问题描述
我试图呈现一个简单的纹理(64×64),以64×64四。四是自身渲染,但是,没有质感。 (它呈现一个空白64×64四。)
I'm trying to render a simple texture(64x64) to a 64x64 quad. The quad itself is rendering, but, not the texture. (It's rendering a blank white 64x64 quad.)
我使用加载图像。
static GLuint LoadPNG(char* filename)
{
GLuint texture = SOIL_load_OGL_texture
(
filename,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
if (texture == 0)
Log("Texture Load Error: " + string(filename));
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return texture;
}
这是我的渲染code,我可能没有正确映射,所以这可能是问题了。
This is my rendering code, I may not be mapping it correctly, so that could be the issue too.
// Draw Textured Quad
static void glDrawTexturedQuad(glRectF rect, GLuint tex)
{
// Bind Texture
glBindTexture (GL_TEXTURE_2D, tex);
// Render Settings
glEnable(GL_TEXTURE_2D);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glColor3ub(255,255,255);
glBegin(GL_QUADS);
// Top Left
glTexCoord2f(0, 1);
glVertex2f(rect.X, rect.Y);
// Top Right
glTexCoord2f(1, 1);
glVertex2f(rect.X + rect.Width, rect.Y);
// Bottom Right
glTexCoord2f(1, 0);
glVertex2f(rect.X + rect.Width, rect.Y + rect.Height);
// Bottom Left
glTexCoord2f(0, 0);
glVertex2f(rect.X, rect.Y + rect.Height);
glEnd();
}
下面是相关code的其余部分。 (这其实只是临时code,粘合到一起进行测试,我会想出一个更好的解决方案后,我得到它的工作。)
Here is the rest of the relevant code. (This is really just temp code, to glue it all together for testing, I'll come up with a better solution after I get it working.)
static GLuint Texture;
static void LoadTextures()
{
Texture = LoadPNG("filename");
}
static void glRenderTest()
{
glRectF rect = {20, 20, 64, 64};
glDrawTexturedQuad(rect, Texture);
}
我也跟着发现所有的建议here它仍然没有显示我的质感。
I've also followed all the suggestions found here It's still not displaying my texture.
我交换出去LodePNG土壤(简单的OpenGL图片库),这是一个有点更容易使用,但仍不能正常工作。
I swapped out LodePNG for SOIL(Simple OpenGL Image Library), it's a bit easier to use, but still isn't working.
我添加glTexEnv如下答案的建议,但我仍然刚开白盒子,我会尝试一些更多的设置,但我不认为这是它。 (编辑:尝试各种标志,什么都没有,还只是一个白色四)
I added glTexEnv as suggested in the answer below, but I'm still just getting a white box, I'll try some more settings, but I don't think that was it. ( Tried various flags, nothing, still just a white quad.)
推荐答案
有你打过电话
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture);
在
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
这篇关于OpenGL的 - 2D纹理映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!