OpenGL - 2D Texture Mapping

时光总嘲笑我的痴心妄想 提交于 2019-12-03 15:25:56

have you tried calling

glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture);

before

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Are all these in the same file?

static GLuint Texture;

static void LoadTextures()
{
    Texture = LoadPNG("filename");
}

static void glRenderTest()
{   
    glRectF rect = {20, 20, 64, 64};
    glDrawTexturedQuad(rect, Texture);
}

If they aren't in the same file, well static variables will have independent copies in each compilation unit, individually initialized to zero when the program starts. Which would explain why you're binding texture #0 after the loader returned 1.

Try using gDEBugger gDEBugger. It will let you see all the textures that have been loaded into OpenGL and provides other debugging tools as well.

I don't see your setting a texture function. Try adding this after glBindTexture in the geometry drawing function:

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); // texture function: GL_DECAL, GL_MODULATE, etc.

Try the different texture function to fit your need: GL_DECAL, GL_BLEND, GL_MODULATE, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!