Original Post
Hello, I'm currently reading the book "game programming all in one" and I've stuck on a problem. Although I did everything that was written in the book and although everything compiles right, I still do not get what I should get . With the following code I should get a certain grey pattern on the top left of my window : Code: The function setupDirect3D is (obviously) only runned once. The function frame is runned continueously. Everything compiles with no errors and D3D is initialized right, because I do get the blue background that I ask for in the frame() function. Does any1 see something wrong with this code?
/* Initializes Direct3D */
HRESULT D3DWindow::SetupDirect3D(void)
{
/* Create the Direct3D object */
if (NULL == (m_pD3D = Direct3DCreate8(D3D_SDK_VERSION)))
{
return E_FAIL ;
}
/* Get the current display mode so we can know what bitdepth we are */
D3DDISPLAYMODE d3ddm;
if (FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm)))
{
return E_FAIL ;
}
/* Fill in the present parameters */
D3DPRESENT_PARAMETERS d3dpp ;
ZeroMemory(&d3dpp, sizeof(d3dpp)) ;
/* We want windowed mode */
d3dpp.Windowed = TRUE ;
/* Discard this */
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD ;
/* Same format as the current format
(we got this from g_pD3D->GetAdapterDisplayMode) */
d3dpp.BackBufferFormat = d3ddm.Format ;
/* Create the device */
if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,
m_hWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &m_pD3DDevice)))
{
return E_FAIL ;
}
/* Create the surface */
if (FAILED(m_pD3DDevice->CreateImageSurface(256, 256,
(D3DFORMAT) m_iD3DFormat, &m_pD3DSurface)))
{
return E_FAIL ;
}
/* Lock surface */
D3DLOCKED_RECT kLockedRect ;
m_pD3DSurface->LockRect(&kLockedRect, NULL, 0) ;
/* Cast a pointer to point to the first pixel */
DWORD *piSurfaceBuffer = (DWORD *)kLockedRect.pBits ;
/* Fill surface */
int iX, iY ;
for (iY=0; iY<256; iY++)
{
for (iX=0; iX<256; iX++)
{
/* Form a pattern */
int iPower = (int)(sin (iY * iX) * 128 + cos (iY * -iX) * 128) ;
piSurfaceBuffer[iX + iY* (kLockedRect.Pitch >> 2)] =
D3DCOLOR_XRGB (iPower, iPower, iPower) ;
}
}
/* Unlock */
m_pD3DSurface->UnlockRect();
return D3D_OK ;
}
mrBool32 D3DWindow::Frame(void)
{
/* Clear the window to blue */
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0) ;
/* Get back buffer */
LPDIRECT3DSURFACE8 pBackBuffer ;
m_pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer) ;
/* Start rendering */
m_pD3DDevice->BeginScene() ;
/* Copy the surface to the screen */
m_pD3DDevice->CopyRects(m_pD3DSurface, NULL, 0, pBackBuffer, NULL) ;
m_pD3DDevice->EndScene() ;
/* Present the rendered scene to the screen */
m_pD3DDevice->Present(NULL, NULL, NULL, NULL) ;
return mrTrue ;
}