我似乎无法加载图像并将其用作我的程序的纹理:图像大小为 512*512,我不知道我做错了什么,有人可以帮助我吗?
主功能:
int main(int argc, char** argv)
{
glutInit (&argc, argv);
glutInitWindowSize (800,600);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutCreateWindow ("CS248 GLUT example");
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMainLoop ();
return 0;
}
显示功能:
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f,1.0f,1.0f);
texture = LoadTexture("space.bmp");
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-20.0,-20.0,0);
glTexCoord2f(0.0, 1.0); glVertex3f(-20.0, 20.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(20.0, 20.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(20.0, -20.0, 0.0);
glEnd();
glFlush();
}
所以,我在这里将 loadtexture 函数调用为 GLuint 纹理,这样:
GLuint LoadTexture( const char* texture )
{
GLuint textureID = SOIL_load_OGL_texture( texture, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS );
glGenTextures(1,&textureID);
glBindTexture( GL_TEXTURE_2D, textureID );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
return textureID;
}
重塑功能:
void reshape(GLsizei w, GLsizei h) {
glViewport(0, 0, 800, 600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-20.0f, 20.0f, -20.0f, 20.0f, -20.0f, 20.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
包括等:
#include <glut.h>
#include <SOIL.h>
GLuint texture;