使用SOIL映射纹理与OpenGL
尝试使用OpenGL和SOIL完成基本纹理映射到曲面,但我不生成任何东西。使用SOIL映射纹理与OpenGL
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);
}
然而,脸部绘制蓝色,我没有纹理。我有第二个窗口,在这里除了位置的唯一延异的是,我使用截,而不是正交
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
以上是 使用SOIL映射纹理与OpenGL 的全部内容, 来源链接: utcz.com/qa/260874.html