我有以下代码用于渲染纹理:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *tex);
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex2f (sx, sy);
glTexCoord2f (1.0, 0.1);
glVertex2f (sx + sxmax, sy);
glTexCoord2f (1.0, 1.0);
glVertex2f (sx + sxmax, sy + symax);
glTexCoord2f (0.0, 1.0);
glVertex2f (sx, sy + symax);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable( GL_BLEND );
glClearColor(0.5,0.5,0.5,0.0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glPopAttrib();
在运行该代码之前,我执行以下操作: glGenTextures(1,tex); 然而,它只是在屏幕上生成一个白色框。 tex的类型为GLuint,使用以下内容创建:
GLuint GetTexture (string Filename) {
GLuint tex_ID;
tex_ID = SOIL_load_OGL_texture (
Filename.c_str(),
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
| SOIL_FLAG_MULTIPLY_ALPHA
| SOIL_FLAG_COMPRESS_TO_DXT
| SOIL_FLAG_DDS_LOAD_DIRECT
| SOIL_FLAG_INVERT_Y
);
if ( tex_ID > 0 ) {
glEnable ( GL_TEXTURE_2D );
glBindTexture ( GL_TEXTURE_2D, tex_ID );
return tex_ID;
} else {
cout << "Texture failed to load" << SOIL_last_result() << Filename << endl;
return 0;
}
}
我使用土壤来生成纹理,使用GLFW来显示它,这一切都在C ++中。我做错了什么?
运行glgeterror会返回错误代码1281