Help.

Started by
3 comments, last by Forcas 22 years, 9 months ago
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."
-Forcaswriteln("Does this actually work?");
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
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."



-Forcaswriteln("Does this actually work?");
You should Repaint every time through the loop. or respond to WM_PAINT.
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

This topic is closed to new replies.

Advertisement