Hi again. I am trying to show up 10 sprites taken of a "sprites.bmp" file, in the project folder, to the screen, but I get some errors. The code I think the errors come from is:
VOID Render()
{
IDirect3DSurface9* surface ;
IDirect3DSurface9* spriteSurface ;
IDirect3DSurface9* backbuffer ;
if (NULL==g_pd3dDevice)
return;
hResult=g_pd3dDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
if (FAILED(hResult))
return;
spriteSurface=getSurfaceFromBitmap("sprites.bmp");
//Clear the backbuffer to a blue color
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100, 200, 255), 1.0f, 0);
//Get the backbuffer
g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //Here we get a pointer to the backbuffer surface
//Copy the offscreen(surface) to the backbuffer
for (int i = 10; i<10; i++)
{
RECT destRect; //Temporary destination rect
//Fill the temporary rect with data from the current sprite structure
destRect.left = spriteStruct.srcRect.left ;
destRect.top = spriteStruct.srcRect.top ;
destRect.bottom = spriteStruct.srcRect.top + SPRITE_HEIGHT ;
destRect.right = spriteStruct.srcRect.left + SPRITE_WIDTH ;
//Draw the sprite to the backbuffer
g_pd3dDevice->StretchRect(spriteSurface,
&spriteStruct.srcRect,
backbuffer,
&destRect,
D3DTEXF_NONE);
}
// if (SUCCEEDED(g_pd3dDevice->BeginScene()))
// {
//rendering of scene objects can happen here
//End the scene
// g_pd3dDevice->EndScene();
// }
//Present the backbuffer contents to the display
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
IDirect3DSurface9* getSurfaceFromBitmap(std::string filename)
{
HRESULT hResult = NULL;
IDirect3DSurface9* surface = NULL;
D3DXIMAGE_INFO imageInfo ; //holds details concerning this bitmap
//Get the width and height info from this bitmap
hResult=D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);
//Make sure that the call to D3DXGetImageInfoFromFile was succeeded
if (FAILED(hResult))
return NULL;
//Create the offscreen surface that will hold the bitmap
hResult=g_pd3dDevice->CreateOffscreenPlainSurface(800, 600, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
if (FAILED(hResult))
return NULL;
//Load the bitmap into the surface
hResult=D3DXLoadSurfaceFromFile(surface,
NULL,
NULL,
filename.c_str(),
NULL,
D3DX_DEFAULT,
0,
NULL);
if (FAILED(hResult))
return NULL;
return surface;
}
bool initSprites(void)
{
//Loop through 10 sprite structures and initialize them
for (int i = 0; i < 10; i++)
{
spriteStruct.srcRect.top = 0 ;
spriteStruct.srcRect.left = i * SPRITE_WIDTH ;
spriteStruct.srcRect.right = spriteStruct.srcRect.left + SPRITE_WIDTH ;
spriteStruct.srcRect.bottom = SPRITE_HEIGHT ;
spriteStruct.posX = rand() % SCRN_WIDTH - SPRITE_WIDTH ;
spriteStruct.posY = rand() % SCRN_HEIGHT - SPRITE_HEIGHT ;
}
return true;
}
The errors say:
Sprites_Direct3D error LNK2020: simbol (token) without solving (0A00000A) spriteStruct
Sprites_Direct3D fatal error LNK1120: 1 extern without solving
Why do I get this errors? Is there any mistake in code? And yes, I included the link dependencies with lines:
#pragma comment(lib,"d3d9.lib");
#pragma comment(lib,"d3dx9.lib");
Thank you for attention.
Ah! I almost forget it! Do you know any code colorizer, to make reading codes clearer and easier?
Thank you!
EDIT: Gave your thread a title, replaced large code tag with source tag. -jba.
[Edited by - jbadams on December 8, 2008 9:33:26 AM]