Little Help Please

Started by
4 comments, last by Squeejee 22 years, 1 month ago
I am tring to use direct draw to plot pixles with double buffering. It compiles fine and all, but the screen just goes black and I cant even use esc key to get out of it. This is what my main loop is:
    
int gameMain()
{

	if(window_closed = 1)
		return(0);

	if(KEYDOWN(VK_ESCAPE))
	{
		SendMessage(main_window_handle, WM_CLOSE, 0, 0);
		window_closed = 1;
	}

	UCHAR *primary_buffer = NULL;

	memset((void *)double_buffer,0, SCREEN_WIDTH*SCREEN_HEIGHT);

	// Game Logic


	for(int index=0; index < 5000; index++)
	{
		int x = rand()%SCREEN_WIDTH;
		int y = rand()%SCREEN_HEIGHT;
		UCHAR color = rand()%256;
		double_buffer[x+y*SCREEN_WIDTH] = color;
	}

		//copy double buffer to primary

		DDRAW_INIT_STRUCT(ddsd);

		lpddsprimary->Lock(NULL,
						   &ddsd,
						   DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
						   NULL);

		// get video pointer to primary surface

		primary_buffer = (UCHAR *)ddsd.lpSurface;

		memcpy((void *)primary_buffer, (void *)double_buffer, SCREEN_WIDTH*SCREEN_HEIGHT);

		//unlock primary surface

		if(FAILED(lpddsprimary->Unlock(NULL)))
			return(0);

		Sleep(500);

  return(1);
}
    
Edited by - Squeejee on February 19, 2002 5:01:34 PM
-----
Advertisement
what''s the KEYDOWN define ??

... and i think you can code you two first if-statments like this

if(KEYDOWN(VK_ESCAPE))
{
SendMessage(main_window_handle, WM_CLOSE, 0, 0);
return 0;
} else {
// doing stuff
}

ahh ??? what are you doing there ???

you randomize 5000 times and you are setting a randomized pixel to an randomized color ??? o.k. but what are you doing while doublebuffering ?? are you copying the one buffer in the other ?? normaly you change the buffers. one time you point to one buffer the next time to the other. use pointer not memcpy. i think this way slows you down.


Could you show me how to change the back buffer the the primary? I am just learning and don''t really know what I am doing. And this is from TOTWGPG BTW.
-----
Check out the ''for beginners'' section here, and learn C++ and Win32 before worrying about DirectX.

,Jay
Uhh.. I know C++, and I know some Win32 API. I just don''t know much at all about DirectX yet.
-----
DirectDraw has a built-in double buffering system which is much quicker than a system memory blit, look for a basic DirectDraw tutorial. You only need to know how to set it up and your sorted.

you draw to the backbuffer and flip it to the primary. You can use setlockedPixel to address each pixel on the backbuffer and backbuffer.lock/unlock before and after. (or something similar)

,Jay

This topic is closed to new replies.

Advertisement