GLUT OpenGL Cube 拉伸错误
Posted
技术标签:
【中文标题】GLUT OpenGL Cube 拉伸错误【英文标题】:GLUT OpenGL Cube exturing error 【发布时间】:2013-11-14 01:13:21 【问题描述】:我正在尝试在 openGL 中对立方体进行纹理处理。我正在使用 GLUT 和 Visual C++ 2010。我正在使用流行的图像加载器 SOIL.h,并且我正在使用来自其他用户的代码。该代码旨在将一个 3-D 立方体绘制到屏幕上,并应用纹理。我在 VC++ 的头文件文件夹中包含了 SOIL.h,但每次编译时都会出现此错误:
error LNK2019: unresolved external symbol _SOIL_load_OGL_texture referenced in function "int __cdecl LoadGLTextures(void)"
如果需要,我会提供任何额外信息。
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <glut.h>
#include "SOIL.h"
GLuint texture[6];//6 textures for 6 faces of the cube
GLfloat xRot,yRot,zRot;//control cube's rotation
int LoadGLTextures()
int Status = 0;
char *bmpFile[6] "BmpFile/1.bmp","BmpFile/2.bmp","BmpFile/3t.bmp","BmpFile/4.bmp","BmpFile/5.bmp","BmpFile/6.bmp";
for (int i = 0;i < 6;++i)
texture[i] = SOIL_load_OGL_texture(
bmpFile[i],
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y);
printf("texture[%d]: %d\n",i,texture[i]);
if(texture[i] == 0)
Status = 0;
glBindTexture(GL_TEXTURE_2D,texture[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
return Status;
int init()
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
return 1;
void display()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(xRot,1.0f,0.0f,0.0f);
glRotatef(yRot,0.0f,1.0f,0.0f);
glRotatef(zRot,0.0f,0.0f,1.0f);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,texture[2]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,texture[3]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,texture[4]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,texture[5]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
xRot += 0.3f;
yRot += 0.4f;
zRot += 0.5f;
glutSwapBuffers();
void reshape(int w,int h)
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f,(GLfloat)w / (GLfloat)h,1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
int main(int argc,char** argv)
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutCreateWindow("Texture Map");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
【问题讨论】:
库链接不正确 【参考方案1】:您好像忘记在链接器设置中添加所需的库。
将 libsoil.lib 文件夹路径添加到 Visual Studio 链接器设置。
如果尚未提供库,您可能必须从 windows 源代码构建库。
【讨论】:
以上是关于GLUT OpenGL Cube 拉伸错误的主要内容,如果未能解决你的问题,请参考以下文章