So, I'm trying to make a wrapper for SDL_RenderCopy()
and for some reason, I keep getting an error that says "use of undefined type 'SDL_Texture'". I have all SDL2's libraries linked and headers included. Here's the code:
void drawImage(Uint32 tex, float x, float y){
SDL_Rect rec;
rec.x = x;
rec.y = y;
if(vcTextures.size() > tex){ //If the argument is in range
if(vcTextures[tex] != 0){ //If the index points to an image
rec.w = vcTextures[tex]->w;
rec.h = vcTextures[tex]->h;
SDL_RenderCopy(gvRender, vcTextures[tex], 0, &rec);
};
};
};
vcTextures
is of type vector<SDL_Texture*>
to store the addresses of all loaded textures for easy cleanup at the end of execution. This is the only place where this happens. When I click on the message that says "see declaration of 'SDL_Texture'", it shows me the declaration, so I know the type exists as far as the file is concerned.
Here's the full error message:
1>f:\c++\xyg\xyg_runtime\graphics.cpp(125) : error C2027: use of undefined type 'SDL_Texture'
1> d:\sdl2\vc\include\sdl_render.h(127) : see declaration of 'SDL_Texture'
1>f:\c++\xyg\xyg_runtime\graphics.cpp(125) : error C2227: left of '->w' must point to class/struct/union/generic type
You are not supposed to access members of SDL_Texture directly. It is an opaque type. I'm pretty sure the documentation doesn't make any mention of members w
or h
, so I don't know where you got the idea to do that. If you want to get information about the texture, you can use SDL_QueryTexture
.
SDL_QueryTexture(vcTextures[tex], nullptr, nullptr, &rec.w, &rec.h);