Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectDraw and surfaces

Started by DJ_House Oct 12, 2000 at 8:34 AM 3 replies 250+ views
Original Post
DJ_House
DJ_House
Hey guys. Something still hasn''t clicked for me with DirectDraw and surfaces. I''ve read 2 books and DirectX SDK, but I''m not 100% clear on them (I''ve been using DD for about 2 weeks now). Ok, here''s my ''unclear'' area: I create a primary surface and a backbuffer (dwBackBufferCount). The backbuffer gets attached to the primary surface. Then I create another surface, which all images will get loaded to. Say this surface is 64x64. So load a 64x64 image onto the offscreen surface, then I blt that offscreen surface to the backbuffer. However, where is it located in my backbuffer if the buffer is 640x480 (same as my primary)? And if I have a background image, what happens to it when I flip it from my primary surface to reveal frame X of my animation? And to copy the next frame from the offscreen surface to the backbuffer, do I have to clear the backbuffer of the flipped primary surface contents? I ran a little long, but hopefully some of you guys have a general clue what I''m talking about.
TheLabRat
TheLabRat
You''ve got the right idea.
1) Where does the sprite go?
It goes to the position that you specify in the Blt or BltFast method (ths first two params)

If your sprite is 64 by 64 and you want to blit it to the top-left of your back-buffer you call BackFuffer->BltFast(0,0,....

The idea is to load all you sprites into :
either the same big off-screen surface and blit them onto the back-buffer to compose the scene and then flip to the primary buffer.
or:
Load each sprite into it''s own little surface and build up your scene by bitting them to the appropriate position on the backbuffer.

Hope this helps
Chris
DJ_House
DJ_House
Thanks for the help! One thing though. I created a sample app with a 640x480 background. In my initilization code, I load the background to the offscreen surface, blt it to the backbuffer, the flip that to the primary surface. It works fine, I can see the background no problems. However, how do I keep a constant background? If I load up another image (the donuts from DirectX SDK), and flip them, even with colorkeys, my background disappears; which I understand because I''m flipping the surface that was already there. But now, I''m left with my background in my backbuffer and the image I want on top of it in my primary surface.

I guess my question is: How do I sync my surfaces?
Dodgy Bob
Dodgy Bob
Hi,

The idea is that you have two surfaces representing your screen with only one of them being active at any one time.

You build whatever you want displayed on the non-active surface and then ''flip''. The non-active surface is now active and the other one is now the in-active (this could get confusing!).

Now you clear the non-active surface, rebuild it (from the background up) and ''flip''.

Now you clear the non-active surface, rebuild it (from the background up) and ''flip''.

Now you clear the non-active surface, rebuild it (from the background up) and ''flip''.

etc.............


Hope this helps.
Gaiiden
Gaiiden
well, if you wanna make it simpler, the backbuffer will always be your non-active surface. For every frame of animation, you HAVE to clear the back buffer and rebuild the scene. Just changing the position of one bitmap won''t do it, even if that''s all you have to do. Now, it DOES get confusing when you have a triple-buffer in your game, because then you have TWO backbuffers to worry about, and you have to figure out which one has just been flipped and which one is about to be flipped. Wheee

==============================
"Need more eeenput..."

- #5, "Short Circuit"
==============================
Drew Sikora
Executive Producer
GameDev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.