Jump to content
  • Advertisement

Archived

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

Help.

This topic is 6149 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''m writing a graphics engine for myself in C++/Win32/DirectX 7 I''ve gotten my program to lock on to a front buffer, and draw a dot on it. The problem is, as soon as I run this code, the screen turns completely gray (the same gray that windows are)
LockFront();
	VideoBuffer = (unsigned int *)ddsd.lpSurface;
	for(int y = 0; y < 600; y++)
	{
		for(int x = 0; x < 800; x++)
		{
			PlotPixel32(x, y, 0, 255, 0);
		}
		Sleep(1);
	}

	//PlotPixel32(100, 100, 0, 250, 0);
	UnlockFront();

    while(Game == TRUE)
    {
        // **** screen turns gray somewhere in this loop ****
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			if(msg.message == WM_KEYDOWN)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
    }

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch (message)                
    {
          case WM_DESTROY:
           PostQuitMessage(0);       
           break;
           default:                   
           return DefWindowProc(hwnd, message, wParam, lParam);
		   break;
    }
    return 0;
}

 
I know that I should really use a backbuffer, but I haven''t put one in yet. ANd even though a backbuffer would fix the problem, I don''t know why the screen is turning gray, and I think it might slow my game down. -Forcas
"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."

Share this post


Link to post
Share on other sites
Advertisement
From the looks of your code it looks like you''re trying to paint the entire screen Green. Is this right? Please post the function PlotPixel32(). Are you''re surfaces 32 bit? If they aren''t, you could be trying to plot 32 bit pixels on a different bit depth surface. If they are, you''re pixel plotting function may not be working properly.



"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share this post


Link to post
Share on other sites
LockBack is essentially the same as LockFront..... anyway, I know blitting the screen green would be better, but this was before I made a blitting function.


void PlotPixel32(int x, int y, int red, int green, int blue)
{
VideoBuffer[x + y*lpitch32] = (UINT)_RGB32BIT(0, red, green, blue);
}





void LockBack()
{
if(FAILED(lpddsb->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
return;

lpitch32 = (int)(ddsd.lPitch >> 2);
VideoBuffer = (unsigned int *)ddsd.lpSurface;
}




The code actually works, it turns the screen green, but immediately after the for loop is through, the screen turns gray. I tested it using a Sleep function.


-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You should Repaint every time through the loop. or respond to WM_PAINT.

Share this post


Link to post
Share on other sites
OK, I didn''t even notice that the first time through. Try this:


while(Game == TRUE)
{
// **** screen turns gray somewhere in this loop ****
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT) break;

if(msg.message == WM_KEYDOWN) break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
LockFront();
VideoBuffer = (unsigned int *)ddsd.lpSurface;
for(int y = 0; y < 600; y++)
{
for(int x = 0; x < 800; x++)
{
PlotPixel32(x, y, 0, 255, 0);
}
Sleep(1);
}
UnlockFront();
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd, message, wParam, lParam); break;
}
return 0;
}


That should work.



"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!