I am trying to render tiles in my 2D "game". But I cannot figure out this problem I am having at the moment and how to get by it so I can continue on with the programming.
I have
no clue how to fix this. Anyone that can help? :) preferably without flaming and cursing. I ain't sure this will work the way I want to but I won't find out if I can't fix this.
Function// draw the sprites.
void DxManager::Render()
{
int spriteWidth = 32, spriteHeight = 32, destx = 0, desty = 0;
if(!pd3dDevice)
return;
pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBuffer);
textures.push_back(this->getSurfaceFromBitmap("./gfx/sprite1.bmp"));
textures.push_back(this->getSurfaceFromBitmap("./gfx/sprite1.bmp"));
for(int x = 10; x >= 0; x--)
{
for(int y = 10; y >= 0; y--)
{
IDirect3DSurface9* pSurface;
pSurface = groundMap[x][y];
hResult = pd3dDevice->StretchRect(groundMap[x][y], NULL, BackBuffer, &destRect, D3DTEXF_NONE);
}
}
if(hResult != D3D_OK)
{
MessageBox(NULL, "D3D is not OK!", "Error", MB_OK);
return;
}
pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
Class#ifndef _DXMANAGER_H_
#define _DXMANAGER_H_
#include "gui.h"
#include "tiles.h"
#include <d3d9.h>
#include <d3dx9tex.h>
#include <string>
class DxManager : public Gui
{
public:
DxManager();
virtual ~DxManager();
bool InitDirect3D();
bool LoadBackground();
bool InitSprites();
void Render();
void StartRender();
void StopRender();
void CleanUp();
void BlitToSurface(IDirect3DSurface9* srcSurface, const RECT *srcRect, const RECT *destRect);
std::vector<IDirect3DSurface9*> textures;
LPDIRECT3D9 pd3d;
LPDIRECT3DDEVICE9 pd3dDevice;
protected:
unsigned int construct();
std::map<unsigned int, unsigned int> twidth;
std::map<unsigned int, unsigned int> theight;
Tile *tiles[10][10];
private:
bool fullscreen;
unsigned int tTile;
D3DXIMAGE_INFO imageInfo;
IDirect3DSurface9* surface;
IDirect3DSurface9* GetBackBuffer();
IDirect3DSurface9* getSurfaceFromBitmap(std::string filename);
IDirect3DSurface9* getSurfaceFromBitmap(std::string filename, int width, int height, int alpha);
IDirect3DSurface9* Background;
IDirect3DSurface9* BackBuffer;
IDirect3DSurface9* sprite;
};
#endif
groundMap[x][y]unsigned int groundMap[10][10] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}
Error(s)
1>------ Build started: Project: sample, Configuration: Debug Win32 ------
1>Compiling...
1>dxmanager.cpp
1>c:\development\dxmanager.cpp(106) : error C2440: '=' : cannot convert from 'int' to 'IDirect3DSurface9 *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\development\dxmanager.cpp(107) : error C2664: 'IDirect3DDevice9::StretchRect' : cannot convert parameter 1 from 'int' to 'IDirect3DSurface9 *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>Generating Code...
1>Compiling...
1>main.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Development\BuildLog.htm"
1>sample - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========