Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / 2D Question – Any way to draw DIRECTLY to an image?

Author
Message
2DWide
15
Years of Service
User Offline
Joined: 30th Nov 2008
Location:
Posted: 1st Dec 2008 01:06
Hi all. Essentially, what I need to know is if there is a way to draw DIRECTLY to an image instead of first drawing to a bitmap surface, then copying the entire bitmap to a new image. I am running into serious performance issues:

I'm creating a simple hi res (1600 x 1000) non-scrolling 2D game. I have two FULL screen images which get drawn to create my background: The first image drawn is a sky-like background image and the second image is of a landscape which gets drawn on top of the first sky-like image. The "empty space" on the landscape image is all black pixels and I use dbSetImageColorKey (0,0,0) so that when the landscape image is drawn on top of the first background image, the "sky" imagery fills in the empty space of the landscape image. The idea here is that when bombs explode on the landscape surface, I want to be able to "obliterate" part of the landscape surface by replacing the landscape colored pixels with black ones (in the area of the explosion) thus revealing more of the sky background image.

What I am doing now, is when a bomb sprite collides with the landscape, I play an explosion sprite at the collision coordinates, then I draw some black pixels on the landscape bitmap surface in a pattern matching the on screen sprite explosion, then I delete the old landscape image and copy the modified landscape bitmap surface to a new landscape image which ultimately gets drawn back to the screen. It works, but at the point that the bitmap surface is being copied to the image, I get about a 2 or 3 second pause in action - obviously because so much pixel data is being copied. If I could somehow either draw my black pixels directly to the landscape IMAGE -OR- if there was a way to copy PART of the bitmap surface onto the already existing full landscape image, I'm sure I would not have the performance issue.

I'm brand new to Dark GDK, but I'm sure there must be a better way than what I am currently doing. Any help would be greatly appreciated.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 1st Dec 2008 05:26
The answer is yes, but not directly using the Dark GDK library that I can see. I've written an Image class (along with a few other 2D classes) that wraps much of the DarkGDK functions but have added a few of my own. I've added functions to give Image objects the same functionality of the bitmap along with being able to copy other images over each other (I'm not sure if I dealt with tranparency.) However, this required digging down into the DirectX functionality. That's why using a class is extremely helpful. It helps to keep the details straight.

All of this starts with using the dbGetImageData function (undocumented) and working backwards.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 1st Dec 2008 10:39 Edited at: 1st Dec 2008 10:40
Check Sephnroth's Image/Primitives extension:

http://forum.thegamecreators.com/?m=forum_view&t=111366&b=22

It allows to write to an image. He also made a batch version, with better performance, but I cannot see it around at this moment. If anyone finds it, please post the link.
2DWide
15
Years of Service
User Offline
Joined: 30th Nov 2008
Location:
Posted: 2nd Dec 2008 03:26
Thank you Morcilla for posting the link!! The code in the image extension is exactly what I was looking for.

Login to post a reply

Server time is: 2024-09-30 11:28:41
Your offset time is: 2024-09-30 11:28:41