[英]SDL_Texture not found by compiler
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'". 因此,我试图为
SDL_RenderCopy()
包装,并且由于某种原因,我不断收到一条错误消息,指出“使用未定义的类型'SDL_Texture'”。 I have all SDL2's libraries linked and headers included. 我已链接了所有SDL2的库并包含标头。 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. vcTextures
类型为vector<SDL_Texture*>
用于存储所有已加载纹理的地址,以便在执行结束时轻松清除。 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.
当我单击“查看'SDL_Texture的声明”消息时,它向我显示该声明,因此我知道该类型在文件方面存在。
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. 您不应直接访问SDL_Texture的成员。 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. 我很确定文档中没有提及成员
w
或h
,所以我不知道您有何想法。 If you want to get information about the texture, you can use SDL_QueryTexture
. 如果要获取有关纹理的信息,可以使用
SDL_QueryTexture
。
SDL_QueryTexture(vcTextures[tex], nullptr, nullptr, &rec.w, &rec.h);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.