Unlocking the Primary Surface

Started by
7 comments, last by Flintlock 24 years ago
I am learning DirectX, and I have run into yet another problem. In my Game_Main function, I have the improper data type for my primary_buffer. The thing is, this code is identical to code from Windows Game Programming For Dummies. Andre'' LaMothe''s code worked perfectly when I copied/pasted it. But, when I rewrote it to use DirectX 7, it didn''t like it anymore... here is the function... // game_main ////////////////////////////////////////////////////////////////// int Game_Main(void *parms = NULL, int num_parms = 0) { // this is the main game logic, do all processing here // test if user is pressing escape and send WM_CLOSE if (KEYDOWN(VK_ESCAPE) // KEYDOWN(VK_SPACE)) SendMessage(main_window_handle, WM_CLOSE, 0, 0); // set up the surface description to lock the surface memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // lock the primary surface lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR / DDLOCK_WAIT, NULL); // get video pointer primary_buffer = (UCHAR *)ddsd.lpSurface; // copy each bitmap line into primary buffer, taking consideration of non-linear // video cards and the memory pitch lPitch for (int y=0; y < SCREEN_HEIGHT; y++) { // copy the line memcpy(&primary_buffer[y*ddsd.lPitch], // destination address &bitmap8bit.buffer[y*SCREEN_WIDTH], // source address SCREEN_WIDTH); } // unlock the surface lpddsprimary->Unlock(primary_buffer); // return success or failure return(1); } /////////////////////////////////////////////////////////////////////////////// Sorry if it is out of line... The compiler says Unlock() can''t change UCHAR * to tagRect *, or something of the sort. Can any of you Guru''s help me out?
Advertisement
lpddsprimary->Unlock(ddsd.lpSurface);

I think you have to cast it to do it from your pointer...?


Edited by - vallis on 3/30/00 6:44:37 PM

Edited by - vallis on 3/30/00 6:47:05 PM
Isn''t it:

DDSPrimary->Unlock(NULL);

I don''t have my code with me right now, but I''m pretty sure you unlock with NULL.

The object knows where it''s lpsurface is...inside itself, so you shouldn''t have to pass a parameter to a member function that belongs to the same class/struct.

Does that make sense? I hope I''m not off on that...I''m pretty sure that''s how my code is(and it works);
asmLOCK - you are right, I always do it the way I said because I think it just makes the code more readable?

Oh well...it works my way at least.

If you unlock by passing the pointer to the surface, you have to cast it I think...not too sure...trying to remember from a book I read about 6 months ago
Yes, that is understandable. And Thanks a lot! I can understand DirectX to a certain extent, but there are a few things I have to iron out. Don''t really know what casting is yet, and basically I am trying to remember all the function calls and what not. I''ll get better with time. Thanks a lot guys! Your help will only allow me to learn more...
Oops... I made the call the way you guys said, but I still got errors. So, I did a little more searching my source... and I found that the parameters in my function definitions were wrong. It''s fixed, and all works right, but it gives me a "This program has performed an illegal operation" whenever I close it out... That''s strange. Do you recommend any books for advanced win32 api topics? like how to make a toolbar, dialog boxes and all that?
I can''t really recommend any books on api stuff, cause I use Borland C++ Builder...which sort of allows me to cheat and get by without knowing all that stuff.
However, I would like to try to help in any way I can.

I''d like to see the code that''s causing the trouble maybe.
You can email me or whatever or post it here if it''ll fit.

asmlock@aol.com


When life hands you lemons, throw them at God's head.
Visual C++ Windows Shell Programming taught me much of what I know about Win32. Some very interesting topics in it to. From Dialog creation to Hooks and even changing the picture on the side of the Start Menu.

ISBN : 1-861001-84-3
The thing is that you need a pointer a a RECT structure and not a pointer to the surface... if you''ve locked the surface with a NULL (which basically means that you allow the whole surface to be drawn on), then you should unlock it with a NULL... If you have any other questions let me know...

Hope this helps!

..-=ViKtOr=-..

This topic is closed to new replies.

Advertisement