Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Squeejee

Little Help Please

This topic is 5995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!