ThePentiumGuy
Senior Contributor
A long Simple DirectDraw Question
I saw this tutorial from http://www.directx4.net/tutorial.php?tutid=1
its just that i cant really understand this
i tried to translate it into english - i came up with an explanationbtw the thing im posting is not a tutorial, it is my own "explanation" of that tutorial, im just wondering if my explanation is right)
im gonna try to put the code into "english" , can u tell me if its right? btw - anythign in red is what im shaky on anything in blue is a comment/remark. i wrote this in , "tutorial format" because somehow it helps me understand better when i read it
first u import Microsoft.DirectX.DirectDraw and Microsoft.DirectDraw, becuase when u code - you dont want to dim a variable like this: Microsoft.DirectX.DirectDraw.Surface, you want to dim it as Surface
You Dim 2 Surfaces - primary and secondary surface - which both hold pictures (From another site i heard the objects that are ALWAYS going to be displayed on the screen are stored in the primary surface, and the objects that are SOMETIMES stored on the screen are in the secondary surface, its like the animation, when u put a fish on 1 side of a paper, and a bowl on the other side of the paper with other fishes, tape them to both ends of straws and flip!)
You dim a clipper, a clipper gives the bounds of the drawings, you dont want your drawings to go off the form - or you want them in a specific area in the form.
You dim a device - if you like Biology, you could compare it with the Nucleus of the cell, it controls everything DDraw does
You dim a TargetForm - which will be "your applications form", indirectly, it will hold the "Address" of your form - i dont know how else to put it
you tell the TargetForm to "Be" the application's form
call INitDevice()
under INitDevice() :
You Create an instance of your Device so u can use it
in the Device, you "setcooperativelevel", make the device draw on TargetForm and make TargetForm FullScreenExclusive - which makes the appliation form FUllScreenExclusive - i duno the difference between fullscreen and full scren exclusive.
Call InitSurfaces
Under InitSurfaces
Every surface has to have a description, just as every object has to have adjectives to describe it. so you create a surface description for a surface
Create an instane of the CLipper so u can use it, and make it "used on"DDevice
Make the Clipper ONLY work for TargetForm and nothing else - so u set its "window" to target form
--
ok, in order to save memory we create only 1 surface description (sdesc) and "Re-use" it.
--
so we take sdesc and make it describe Primary Surfaces
Enable flipping to make it go faster(in GDI+ its like DOubleBuffer)
Make it complex because u have more than 1 surface and they all link to the primary surface.
The NUmber of BackBuffers - the more u have the smoother it goes, but it slows down ur applicaton of u have too many - i presume
Take your primary surface - create an instance so u can use it
- set its surface description to sdesc and make it controlled by your Device
take your surface and set its clipper to the one you Dimmed
--
memory management here
--
you clear out the surface descrpition so u can "re-use" it for the secondary surface
you make the surface description thats gonna describe the secondary surface, a back buffer -
remember we only have 1 (sdesc.BackBufferCount = 1)
The one thing i didnt really notice was, setting the surface description to secondary(sdesc.surfacecaps.secondarysurface = true) - unless its already by default(when u cleared it, everything returned to default) secondary.. i also didnt notice, in the tutorial, setting the sdescto describe ssurface(ssurface = New Surface(sdesc, dddevice ). i think im wrong anyway.. but i just wanted to point that out to clear things up for me
you take the secondary surface - and attach it to the primary surface?
-
now remember, all this code above goes in a class called GraphicsClass
-
ok
in the main application - what you do is, Dim GameGraphics as New GraphicsClass(Me)
remember, in the GraphicsClass code in the sub New you said (byval frm As Form)
that FORM is Me - no not me, but the Applications form
ok,
while a variable called GameGoes is True, you "flip" gamegraphics, which is your GraphicsClass class, which is basically your DDraw thing.
APplication.DoEvents[/COLOR] - not too sure what this does - i think it allows your program or event to run on a seperate thread
In a sub calld FlipSurface:
You fill the secondary surface with a redish color
you flip the primary surface? and dont wait?
in a sub calld dispose
--
memory management
--
discard device/surfaces/and clipper
when you push escape - game goes = false, which disposes the stuff and ends the applicatoin
sorry for the long explanation - well, this is finnally starting to get to my head - please tell me what i did wrong here(i know what i did wrong)
i posted this code so i could take DDraw step by step and pust it in 'english' and see if i could understand it, and if i didnt, if anyone could correct me on this, that would be great, i got lost a bit at the end
thanks for your cooperation for reading this, and thanks in advance
[/COLOR]
I saw this tutorial from http://www.directx4.net/tutorial.php?tutid=1
its just that i cant really understand this
i tried to translate it into english - i came up with an explanationbtw the thing im posting is not a tutorial, it is my own "explanation" of that tutorial, im just wondering if my explanation is right)
im gonna try to put the code into "english" , can u tell me if its right? btw - anythign in red is what im shaky on anything in blue is a comment/remark. i wrote this in , "tutorial format" because somehow it helps me understand better when i read it
first u import Microsoft.DirectX.DirectDraw and Microsoft.DirectDraw, becuase when u code - you dont want to dim a variable like this: Microsoft.DirectX.DirectDraw.Surface, you want to dim it as Surface
You Dim 2 Surfaces - primary and secondary surface - which both hold pictures (From another site i heard the objects that are ALWAYS going to be displayed on the screen are stored in the primary surface, and the objects that are SOMETIMES stored on the screen are in the secondary surface, its like the animation, when u put a fish on 1 side of a paper, and a bowl on the other side of the paper with other fishes, tape them to both ends of straws and flip!)
You dim a clipper, a clipper gives the bounds of the drawings, you dont want your drawings to go off the form - or you want them in a specific area in the form.
You dim a device - if you like Biology, you could compare it with the Nucleus of the cell, it controls everything DDraw does
You dim a TargetForm - which will be "your applications form", indirectly, it will hold the "Address" of your form - i dont know how else to put it
you tell the TargetForm to "Be" the application's form
call INitDevice()
under INitDevice() :
You Create an instance of your Device so u can use it
in the Device, you "setcooperativelevel", make the device draw on TargetForm and make TargetForm FullScreenExclusive - which makes the appliation form FUllScreenExclusive - i duno the difference between fullscreen and full scren exclusive.
Call InitSurfaces
Under InitSurfaces
Every surface has to have a description, just as every object has to have adjectives to describe it. so you create a surface description for a surface
Create an instane of the CLipper so u can use it, and make it "used on"DDevice
Make the Clipper ONLY work for TargetForm and nothing else - so u set its "window" to target form
--
ok, in order to save memory we create only 1 surface description (sdesc) and "Re-use" it.
--
so we take sdesc and make it describe Primary Surfaces
Enable flipping to make it go faster(in GDI+ its like DOubleBuffer)
Make it complex because u have more than 1 surface and they all link to the primary surface.
The NUmber of BackBuffers - the more u have the smoother it goes, but it slows down ur applicaton of u have too many - i presume
Take your primary surface - create an instance so u can use it
- set its surface description to sdesc and make it controlled by your Device
take your surface and set its clipper to the one you Dimmed
--
memory management here
--
you clear out the surface descrpition so u can "re-use" it for the secondary surface
you make the surface description thats gonna describe the secondary surface, a back buffer -
remember we only have 1 (sdesc.BackBufferCount = 1)
The one thing i didnt really notice was, setting the surface description to secondary(sdesc.surfacecaps.secondarysurface = true) - unless its already by default(when u cleared it, everything returned to default) secondary.. i also didnt notice, in the tutorial, setting the sdescto describe ssurface(ssurface = New Surface(sdesc, dddevice ). i think im wrong anyway.. but i just wanted to point that out to clear things up for me
you take the secondary surface - and attach it to the primary surface?
-
now remember, all this code above goes in a class called GraphicsClass
-
ok
in the main application - what you do is, Dim GameGraphics as New GraphicsClass(Me)
remember, in the GraphicsClass code in the sub New you said (byval frm As Form)
that FORM is Me - no not me, but the Applications form
ok,
while a variable called GameGoes is True, you "flip" gamegraphics, which is your GraphicsClass class, which is basically your DDraw thing.
APplication.DoEvents[/COLOR] - not too sure what this does - i think it allows your program or event to run on a seperate thread
In a sub calld FlipSurface:
You fill the secondary surface with a redish color
you flip the primary surface? and dont wait?
in a sub calld dispose
--
memory management
--
discard device/surfaces/and clipper
when you push escape - game goes = false, which disposes the stuff and ends the applicatoin
sorry for the long explanation - well, this is finnally starting to get to my head - please tell me what i did wrong here(i know what i did wrong)
i posted this code so i could take DDraw step by step and pust it in 'english' and see if i could understand it, and if i didnt, if anyone could correct me on this, that would be great, i got lost a bit at the end
thanks for your cooperation for reading this, and thanks in advance
[/COLOR]
Last edited: