我只是试图将纹理附加到使用SOIL库的四边形绘制的方格,但没有任何结果,只有黑屏。你知道为什么会这样吗? 我已经绑定了变量,并根据方形本身定义了纹理坐标......
#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <SOIL.h>
#include <gl\gl.h>
#include <gl\glu.h>
GLuint texture[1];
int LoadGLTextures()
{
texture[0] = SOIL_load_OGL_texture
(
"img_test.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y
);
if(texture[0] == 0)
return false;
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
return true;
}
void init()
{
glEnable(GL_TEXTURE_2D);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
//glEnable(GL_TEXTURE_2D);
glLoadIdentity();
glColor3f(0.0, 0.0, 0.0);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.25f, 0.25f); glVertex3f(0.25f, 0.25f, 0.0f);
glTexCoord2f(0.75f, 0.25f); glVertex3f(0.75f, 0.25f, 0.0f);
glTexCoord2f(0.75f, 0.75f); glVertex3f(0.75f, 0.75f, 0.0f);
glTexCoord2f(0.25f, 0.75f); glVertex3f(0.25f, 0.75f, 0.0f);
glEnd();
LoadGLTextures();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION),
glLoadIdentity();
//glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);*/
gluPerspective(30.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(200,200);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}