我无法找到原因。这就是我的称呼方式
<p>StudentComponent works!</p>
宽度和高度参数是872 639 内部格式为GL_RGBA
可能是什么问题?我检查https://www.khronos.org/registry/OpenGL-Refpages/es1.1/xhtml/glTexImage2D.xml它看起来很好(除非宽度或高度大于我怀疑的最大纹理大小或不支持内部格式RGBA,这也不太可能)
这是完整的代码
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, data_fmt, GL_UNSIGNED_BYTE, surf->pixels)
out << "loading " << fileName << "\n";
dimensions.setZero();
name = fileName;
this->repeat = repeat;
SDL_Surface* surf = IMG_Load(fileName.c_str());
if (surf == NULL)
{
out << "surface_error: " << fileName << " " << SDL_GetError() << "\n";
hasError = true;
return;
}
GLenum data_fmt;
if (surf->format->BytesPerPixel == 4)
{
data_fmt = GL_RGBA;
}
else if (surf->format->BytesPerPixel == 3)
{
data_fmt = GL_RGB;
}
else if (surf->format->BytesPerPixel == 1)
{
data_fmt = GL_RED;
}
else
{
assert(false);
}
GL_CALL(glGenTextures(1, &gTexture));
GL_CALL(glBindTexture(GL_TEXTURE_2D, gTexture));
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, data_fmt, GL_UNSIGNED_BYTE, surf->pixels));
if (hadGLError)
{
out << data_fmt << " " << surf->w << " " << surf->h << "\n";
}
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
dimensions = IntVec2(surf->w, surf->h);
glGenerateMipmap(GL_TEXTURE_2D);
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
SDL_FreeSurface(surf);
检查GL_CALL
,并在glGetError
之后设置为GL_INVALID_VALUE
,0x0501。试图设置包装参数时游戏崩溃
答案 0 :(得分:0)
我认为问题是由其他原因引起的,opengl没有正确启动。