gpt4 book ai didi

c++ - GLUT OpenGL Cube 拉伸(stretch)错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:45:34 25 4
gpt4 key购买 nike

我正在尝试在 openGL 中为立方体制作纹理。我使用的是 GLUT 和 Visual C++ 2010。我使用的是流行的图像加载器 SOIL.h,我使用的是来自其他用户的代码。该代码用于在屏幕上绘制一个应用了纹理的 3-D 立方体。我已将 SOIL.h 包含在 VC++ 的头文件文件夹中,但每次编译时都会出现此错误:

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;
}

最佳答案

看起来您忘记在链接器设置中添加所需的库。

将 libsoil.lib 文件夹路径添加到 visual studio 链接器设置中。

如果尚未提供,您可能必须从源代码为 Windows 构建库。

关于c++ - GLUT OpenGL Cube 拉伸(stretch)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19967676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com