SDL_LoadBMP 将位图倒置加载并在 OpenGL 中镜像。可能是什么问题?
unsigned int loadTexture (const char * fileName)
{
unsigned int texId;
GLenum format;
GLint colorCount;
SDL_Surface * image = SDL_LoadBMP (fileName);
colorCount = image->format->BytesPerPixel;
if (colorCount == 4)
{
if (image->format->Rmask == 0x000000ff)
format = GL_RGBA;
else
format = GL_BGRA;
}
else if (colorCount == 3)
{
if (image->format->Rmask == 0x000000ff)
format = GL_RGB;
else
format = GL_BGR;
}
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, colorCount, image->w, image->h, 0, format, GL_UNSIGNED_BYTE, image->pixels);
SDL_FreeSurface(image);
return texId;
}
..这就是我绘制测试四边形的方式..
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex3f(-1.0, -1.0, 0.0);
glTexCoord2i(1, 0); glVertex3f( 1.0, -1.0, 0.0);
glTexCoord2i(1, 1); glVertex3f( 1.0, 1.0, 0.0);
glTexCoord2i(0, 1); glVertex3f(-1.0, 1.0, 0.0);
glEnd();