I have code that works to draw sprites to the screen.
////start rendering
//if (d3ddev->BeginScene())
//{
// //erase the entire background
// HRESULT result;
// const RECT dest = {0, 0, 960, 600};
// result = d3ddev->StretchRect(back, NULL, backbuffer, &dest, D3DTEXF_NONE); // param 4 replaced from NULL
// if (result != D3D_OK)
// {
// MessageBox(hwnd, "Error with setting backbuffer", "Error", MB_OK);
// }
// //start sprite handler
// sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
// // draw the textbox
// position.x = (float)textbox.x;
// position.y = (float)textbox.y;
// sprite_handler->Draw(back2, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255));
// // draw the game area
// position.x = (float)sGameArea.x;
// position.y = (float)sGameArea.y;
// sprite_handler->Draw(game_area, NULL, NULL, &position, 0xFFFFFFFF); // color passed will mantain bmp color
//
// //draw the ball
// position.x = (float)ball.x;
// position.y = (float)ball.y;
// sprite_handler->Draw(
// ball_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
//
// //draw the paddle
// position.x = (float)paddle.x;
// position.y = (float)paddle.y;
// //sprite_handler->Draw(paddle_image, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255));
// //sprite_handler->End();
// renderManager.Display();
// //sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
// //draw 10 blocks
// for (int n=0; n<NUMBLOCKS; n++)
// {
// if (block[n].visible == 1)
// {
// //draw the blocks
// position.x = n * (float)block[n].width;
// position.y = (float)block[n].y;
// sprite_handler->Draw(
// block_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
// }
// }
//
// // second set of blocks
// for (int e=0; e<NUMBLOCKS2; e++)
// {
// if (blue_block[e].visible == 1)
// {
// //draw the blocks
// position.x = e * (float)blue_block[e].width;
// position.y = (float)blue_block[e].y;
// sprite_handler->Draw(
// blue_block_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
// }
// }
// // third set of blocks
// for (int e=0; e<NUMBLOCKS3; e++)
// {
// if (white_block[e].visible == 1)
// {
// //draw the blocks
// position.x = e * (float)white_block[e].width;
// position.y = (float)white_block[e].y;
// sprite_handler->Draw(
// white_block_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
// }
// }
// DisplayStatus();
// //stop drawing
// sprite_handler->End();
// //stop rendering
// d3ddev->EndScene();
//}
//display the back buffer on the screen
result = d3ddev->Present(NULL, NULL, NULL, NULL);
It is commented because I am not currently using it.
And I created a class to hanlde all rendering which has a Display function:
int CRenderManager::Display(HWND hwnd, LPDIRECT3DSURFACE9 back, LPD3DXSPRITE sprite_handler)
{
D3DXVECTOR3 position;
HRESULT result;
if(SUCCEEDED(d3ddev->BeginScene()))
{
const RECT dest = {0, 0, 960, 600};
result = d3ddev->StretchRect(back, NULL, backbuffer, &dest, D3DTEXF_NONE); // param 4 replaced from NULL
if (result != D3D_OK)
{
MessageBox(hwnd, "Error with setting backbuffer", "Error", MB_OK);
}
sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
for (int i = 0; i < RenderList.size(); i++)
{
position.x = RenderList.x;
position.y = RenderList[i].y;
result = sprite_handler->Draw(RenderList[i].texture, NULL, NULL, &position, 0xFFFFFFFF);
}
//DisplayStatus();
//stop drawing
result = sprite_handler->End();
//stop rendering
d3ddev->EndScene();
}
return 1;
}
This function does not fail although it does not draw any sprites. It only draws the background. With moving this functionality to a class, what am I missing that would cause this to not Draw. The code is not failing although the following is occuring:
sprite_handler variable is poulated with valid memory address
but
this.sprite_handler is invalid.
Why could this be? and why is my drawing not working?
////start rendering
//if (d3ddev->BeginScene())
//{
// //erase the entire background
// HRESULT result;
// const RECT dest = {0, 0, 960, 600};
// result = d3ddev->StretchRect(back, NULL, backbuffer, &dest, D3DTEXF_NONE); // param 4 replaced from NULL
// if (result != D3D_OK)
// {
// MessageBox(hwnd, "Error with setting backbuffer", "Error", MB_OK);
// }
// //start sprite handler
// sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
// // draw the textbox
// position.x = (float)textbox.x;
// position.y = (float)textbox.y;
// sprite_handler->Draw(back2, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255));
// // draw the game area
// position.x = (float)sGameArea.x;
// position.y = (float)sGameArea.y;
// sprite_handler->Draw(game_area, NULL, NULL, &position, 0xFFFFFFFF); // color passed will mantain bmp color
//
// //draw the ball
// position.x = (float)ball.x;
// position.y = (float)ball.y;
// sprite_handler->Draw(
// ball_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
//
// //draw the paddle
// position.x = (float)paddle.x;
// position.y = (float)paddle.y;
// //sprite_handler->Draw(paddle_image, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255));
// //sprite_handler->End();
// renderManager.Display();
// //sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
// //draw 10 blocks
// for (int n=0; n<NUMBLOCKS; n++)
// {
// if (block[n].visible == 1)
// {
// //draw the blocks
// position.x = n * (float)block[n].width;
// position.y = (float)block[n].y;
// sprite_handler->Draw(
// block_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
// }
// }
//
// // second set of blocks
// for (int e=0; e<NUMBLOCKS2; e++)
// {
// if (blue_block[e].visible == 1)
// {
// //draw the blocks
// position.x = e * (float)blue_block[e].width;
// position.y = (float)blue_block[e].y;
// sprite_handler->Draw(
// blue_block_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
// }
// }
// // third set of blocks
// for (int e=0; e<NUMBLOCKS3; e++)
// {
// if (white_block[e].visible == 1)
// {
// //draw the blocks
// position.x = e * (float)white_block[e].width;
// position.y = (float)white_block[e].y;
// sprite_handler->Draw(
// white_block_image,
// NULL,
// NULL,
// &position,
// D3DCOLOR_XRGB(255,255,255));
// }
// }
// DisplayStatus();
// //stop drawing
// sprite_handler->End();
// //stop rendering
// d3ddev->EndScene();
//}
//display the back buffer on the screen
result = d3ddev->Present(NULL, NULL, NULL, NULL);
It is commented because I am not currently using it.
And I created a class to hanlde all rendering which has a Display function:
int CRenderManager::Display(HWND hwnd, LPDIRECT3DSURFACE9 back, LPD3DXSPRITE sprite_handler)
{
D3DXVECTOR3 position;
HRESULT result;
if(SUCCEEDED(d3ddev->BeginScene()))
{
const RECT dest = {0, 0, 960, 600};
result = d3ddev->StretchRect(back, NULL, backbuffer, &dest, D3DTEXF_NONE); // param 4 replaced from NULL
if (result != D3D_OK)
{
MessageBox(hwnd, "Error with setting backbuffer", "Error", MB_OK);
}
sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
for (int i = 0; i < RenderList.size(); i++)
{
position.x = RenderList.x;
position.y = RenderList[i].y;
result = sprite_handler->Draw(RenderList[i].texture, NULL, NULL, &position, 0xFFFFFFFF);
}
//DisplayStatus();
//stop drawing
result = sprite_handler->End();
//stop rendering
d3ddev->EndScene();
}
return 1;
}
This function does not fail although it does not draw any sprites. It only draws the background. With moving this functionality to a class, what am I missing that would cause this to not Draw. The code is not failing although the following is occuring:
sprite_handler variable is poulated with valid memory address
but
this.sprite_handler is invalid.
Why could this be? and why is my drawing not working?