ThePentiumGuy Posted September 15, 2003 Posted September 15, 2003 (edited) 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:eek: i tried to translate it into english - i came up with an explanation:(btw 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] Edited September 15, 2003 by ThePentiumGuy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
ThePentiumGuy Posted September 16, 2003 Author Posted September 16, 2003 Whoops guys - i posted the wrong link the link that was really supposed to be there is this: http://www.directx4.net/tutorial.php?tutid=2 sorry about that Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Administrators PlausiblyDamp Posted September 16, 2003 Administrators Posted September 16, 2003 In no certain order: Application.DoEvents() - gives the application chance to process it's message loop. FullScreenExclusive means the application will go fullscreen ;) and no other application is allowed access to the hardware device i.e. only we can draw to the screen at this time. Other modes may allow multiple applications to draw to the hardware at the same time. The idea behind 2 surfaces is you draw to the secondary surface which isn't visible so nobody can see the scene being built up in code and then when the drawing is complete you switch it to the primary surface (similar to blitting an image to a form). The psurface.Flip(ssurface, FlipFlags.DoNotWait) is a performance thing, we are just going to update the display now even if it isn't the best time as far as the hardware is concerned - this is faster but may cause 'artifacts' or image distortions. If we choose to wait the image may be better (fewer drawing errors) but the overall speed may be slower. The Dispose Method of the class simply frees up memory when escape is pressed and the Game loop exits (do while gamegoes) Sure if I'm wrong anywhere Mutant will put me straight :) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ThePentiumGuy Posted September 17, 2003 Author Posted September 17, 2003 Woah! Thansk a lot - im starting to undesttand this better :) 1 question though - , what about the stuff written in blue and the line in red, those are the only 2 doubts i have after that - im set! i can finally understand the basics of DirectDraw:) Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.