functions.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include "Headers.h"
#include "CharProp.h"
CharProp gracz;
const int SCREEN_WIDTH = 1024;
const int SCREEN_HEIGHT = 1024;
SDL_Window* gWindow = NULL;
SDL_Texture* gTextureWoodfloor = NULL;
SDL_Renderer* gRenderer = NULL;
SDL_Surface* gScreenSurface = NULL;
SDL_Surface* Icon = NULL;
/*there are a lot lines of code but they are not needed to solve problem*/
|
LTexture.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include "Headers.h"
class LTexture
{
public:
LTexture();
~LTexture();
bool loadFromFile(std::string path);
void free();
void render(int x, int y);
int getWidth();
int getHeight();
private:
SDL_Texture* mTexture;
int mWidth;
int mHeight;
};
|
LTexture.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include "LTexture.h"
LTexture::LTexture()
{
}
LTexture::~LTexture()
{
}
bool LTexture::loadFromFile(std::string path)
{
bool success = true;
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if (loadedSurface == NULL)
{
std::cout << " Could not load: " << path.c_str() << " Error: " << SDL_GetError() << std::endl;
success = false;
}
else
{
mTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface); // Here is the error that "gRenderer: undeclared identifier
if (mTexture == NULL)
{
std::cout << "Could not load Texture image: " << path.c_str() << " Error: " << SDL_GetError() << std::endl;
success = false;
}
SDL_FreeSurface(loadedSurface);
}
return success;
}
void LTexture::free()
{
}
void LTexture::render(int x, int y)
{
}
int LTexture::getWidth()
{
return 0;
}
int LTexture::getHeight()
{
return 0;
}
|
When i try to include functions.h in LTexture.h or LTexture.cpp i get this:
1>Main.obj : error LNK2005: "void __cdecl close(void)" (?close@@YAXXZ) already defined in LTexture.obj
1>Main.obj : error LNK2005: "bool __cdecl init(void)" (?init@@YA_NXZ) already defined in LTexture.obj
1>Main.obj : error LNK2005: "bool __cdecl loadMedia(void)" (?loadMedia@@YA_NXZ) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Surface * __cdecl loadSurface(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadSurface@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Texture * __cdecl loadTexture(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadTexture@@YAPAUSDL_Texture@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in LTexture.obj
1>Main.obj : error LNK2005: "void __cdecl render(struct SDL_Texture *,int,int,int,int,struct SDL_Renderer *)" (?render@@YAXPAUSDL_Texture@@HHHHPAUSDL_Renderer@@@Z) already defined in LTexture.obj
1>Main.obj : error LNK2005: "void __cdecl renderAll(void)" (?renderAll@@YAXXZ) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Window * gWindow" (?gWindow@@3PAUSDL_Window@@A) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Texture * gTextureWoodfloor" (?gTextureWoodfloor@@3PAUSDL_Texture@@A) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Renderer * gRenderer" (?gRenderer@@3PAUSDL_Renderer@@A) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Surface * gScreenSurface" (?gScreenSurface@@3PAUSDL_Surface@@A) already defined in LTexture.obj
1>Main.obj : error LNK2005: "struct SDL_Surface * Icon" (?Icon@@3PAUSDL_Surface@@A) already defined in LTexture.obj
1>Main.obj : error LNK2005: "class CharProp gracz" (?gracz@@3VCharProp@@A) already defined in LTexture.obj