使用 SOIL 使用 OpenGL 映射纹理

Mapping a texture with OpenGL using SOIL

尝试使用 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);
}

然而,脸部是蓝色的,我看不到任何纹理。我有第二个 window,除了位置,唯一的区别是我使用 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);

并且纹理绘制良好。

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

#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