Advertisement

How they do that...?

Started by April 29, 2001 03:57 AM
3 comments, last by zhang_zhou 23 years, 9 months ago
Hey,guys... Currently,I''m learning game programming with C++ and DirectX on Windows... Now,I have a question to Surface in DirectDraw,here it is... As you known,when you want to display a picture on the screen,you must firstly create a Primary Surface,and then place the picture data(pixels) into the Surface,and the picture will be displayed at once.this is just a theory,for an actual video game,in order to improve the speed,you must create lots of surfaces(called back surface) firstly,and place the related picture data into each one,when it''s time to udate the screen and need to display a pic,just blit the right back surface into the primary... Well,up to here,what I dont understand is appearing - For an actual video game,such as StartCraft and Quake,there are a lots of pics(framea) in it,so how they origane such more surfaces? Any help woll be much thankful!!
============================= Hey,I just wanna know WHY! =============================
Hmm I kind of didn''t understand your question, so I''ll just try to explain it the best I can:

Firstly, you don''t have a "back surface" frame for each possible game sequence!!! You simply have the _Ground Graphics_ which you draw first, then over the top you draw your _Buildings_ then you draw your _Units_. You know where to draw these because you keep track of their x and y positions on the screen.

Okay, enough theory, more down to earth explanation:

You have your Primary and Secondary (backbuffer) surfaces. These are the size of your screen resolution (whatever res the player has chosen).

Now, from here it gets a little more complicated. Once you have loaded the imagery, there are two choices to do:

1) load each frame of animation into a different surface (size maybe 32x32) and call Blt to this surface

2) Load the whole animation into 1 surface, and blt a rectangle from that surface depending on what frame you want.

..................................

Okay, I hope I cleared things up a little for you =)


Advertisement
Using offscreen surfaces isn''t done for performance reasons. They simply contain the graphics your app will use. The back buffer is a surface used to compose the entire scene you''re going to display. Then, calling Blit or Flip will actually display that on the primary surface. Drawing on the primary surface is bad for lots of reasons, not the least of which is because you''ll get tearing and flickering.
Here''s another (LONG) explanation/view:

primary surface will always be in video memory and is containing the graphics your screen showing. So any changes to this surface you can see direct changes on the screen.

Let''s say if you draw every frame/sprite one by one on to this primary surface, you can see your whole screen flicker... or ''slowly'' generating, i.e. this is what you see: 1st Your Game''s Background (grass)... then Some Fixed Sprite (buildings)... and then Some moving sprite (people, bullets, explosion)... and then... go back to 1st -- all appearing one by one and then disappear again, and then appear again, and.....

SO instead of letting the player see HOW you draw, why not just finish the complete scene and then let the user see?! Here we go: Double-Buffering. What it means is you now have another surface, call back surface. But now you draw everything on this back surface... after you finish the whole scene, just flip/interchange the primary and back surfaces (if the graphics card support it, but don''t wor, 99% will do )... you got the picture?

NOW for your little sprites/frame... those tanks, marines, armies, soldiers...blah blah blah... these are also surfaces. The differences are that they are independent to the primary/back surfaces. And if your video card has room, these little surfaces will be in the video memory; and if not, it will be in system memory - called off-screen surface. Remember, most of the time you blit your little sprites to the back surface. After finishing, you flip!

Some simple summary:
primary surface = What is on the screen - front stage.

back surface = Your working area - back stage.

little surface
or off-screen surface
= Your tanks, your people, your bullets... blah blah...


HOPE THIS CLEAR THINGS UP.
"after many years of singularity, i'm still searching on the event horizon"
Thanks to the above guys!

Now,I'm a bit understand to the Surface in DX.

And,does anyone can show me an actual example about it(written in C++ with DX)?

Thanks again!!!

Edited by - zhang_zhou on May 5, 2001 7:37:46 AM
============================= Hey,I just wanna know WHY! =============================

This topic is closed to new replies.

Advertisement