gpt4 book ai didi

c++ - 使用 SOIL 使用 OpenGL 映射纹理

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:18 24 4
gpt4 key购买 nike

尝试使用 OpenGL 和 SOIL 完成到表面的基本纹理贴图,但我没有生成任何东西。

GLuint textureID[5];

glutInitWindowPosition(0, 50);
windowID[0] = glutCreateWindow("orthogonal projection, cubes");

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-400, 400, -400, 400, -500, 500);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutKeyboardFunc(Keyboard);
glutDisplayFunc(DrawWindowOne);

textureID[0] = SOIL_load_OGL_texture("assets/faceA.png",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);

void DrawWindowOne()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);

glViewport(0, 0, 250, 250);

glMatrixMode(GL_MODELVIEW);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, textureID[0]);

glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0); // front face
glTexCoord2f(0.0, 0.0); glVertex3f(-a,-a, a);
glTexCoord2f(0.0, 1.0); glVertex3f(-a, a, a);
glTexCoord2f(1.0, 1.0); glVertex3f( a, a, a);
glTexCoord2f(1.0, 0.0); glVertex3f( a,-a, a);
glEnd();

glDisable(GL_TEXTURE_2D);
}

然而,脸部是蓝色的,我看不到任何纹理。我有第二个窗口,除了位置之外,唯一的区别是我使用的是 Frustrum 而不是 Orthogonal

windowID[1] = glutCreateWindow("Perspective projection using glFrustum");

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-60, 60, -60, 60, 60, 200);
gluLookAt(0, 0, 120, 0, 0, 0, 0, 1, 0);

并且纹理绘制得很好。

最佳答案

问题是我一次加载所有纹理,看起来它们需要在每个窗口初始化后加载以供该窗口绘制代码使用。

#pragma region Initialise Window One
glutInitWindowPosition(0, 50);
windowID[1] = glutCreateWindow("orthogonal projection, cubes");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-400, 400, -400, 400, -500, 500);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutKeyboardFunc(Keyboard);
glutDisplayFunc(DrawWindowOne);
LoadTextures();
#pragma endregion

#pragma region Initialise Window Two
glutInitWindowPosition(0, 450);
windowID[1] = glutCreateWindow("Perspective projection using glFrustum, ellipsoids");

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-60, 60, -60, 60, 60, 200);
gluLookAt(0, 0, 120, 0, 0, 0, 0, 1, 0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutKeyboardFunc(Keyboard);
glutDisplayFunc(DrawWindowTwo);
LoadTextures();
#pragma endregion

关于c++ - 使用 SOIL 使用 OpenGL 映射纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30227615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com