加载OpenGL项目的.obj文件时出现LNK2019错误

时间:2014-12-11 15:52:13

标签: c++ opengl lnk2019

我想在OpenGL中建模我的房间,当我创建我的第一个对象并按照一些教程说明了什么以及如何做,在Visual Studio 2013 Professional应用程序中加载对象后,我得到以下错误:

Warning 1   warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification    d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   2   error LNK2019: unresolved external symbol "float __cdecl glmUnitize(struct _GLMmodel *)" (?glmUnitize@@YAMPAU_GLMmodel@@@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)   d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   3   error LNK2019: unresolved external symbol "void __cdecl glmFacetNormals(struct _GLMmodel *)" (?glmFacetNormals@@YAXPAU_GLMmodel@@@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)  d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   4   error LNK2019: unresolved external symbol "void __cdecl glmVertexNormals(struct _GLMmodel *,float)" (?glmVertexNormals@@YAXPAU_GLMmodel@@M@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z) d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   5   error LNK2019: unresolved external symbol "struct _GLMmodel * __cdecl glmReadOBJ(char *)" (?glmReadOBJ@@YAPAU_GLMmodel@@PAD@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)    d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   6   error LNK2019: unresolved external symbol "void __cdecl glmDraw(struct _GLMmodel *,unsigned int)" (?glmDraw@@YAXPAU_GLMmodel@@I@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)    d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   7   error LNK1120: 5 unresolved externals   d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\Debug\OpenGLApplication.exe  OpenGLApplication

这是我的代码,非常简单,只需加载和可视化对象:

// OpenGLApplication.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "glut.h"
#include "glm.h"
#include <gl/gl.h>
#include <math.h>

int screen_width=1366;
int screen_height=768;
GLMmodel *bed;

void initOpenGL()
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glShadeModel(GL_SMOOTH);
    glViewport(0, 0, screen_width, screen_height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, (GLfloat)screen_width/(GLfloat)screen_height, 1.0f, 1000.0f);
    glEnable(GL_DEPTH_TEST);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glMatrixMode(GL_MODELVIEW);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
}

void drawModel(GLMmodel **pmodel, char*filename, GLuint mode)
{
    if (!*pmodel){
        *pmodel = glmReadOBJ(filename);
        if (!*pmodel){
            exit(0);
        }
        glmUnitize(*pmodel);
        //generate facet normal vectors for model
        glmFacetNormals(*pmodel);
        //generate vertex normal vectors (called after generating facet normals)
        glmVertexNormals(*pmodel, 90.0);
    }
    glmDraw(*pmodel, mode);
}


void renderScene(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, -10.0, 0.0, 1.0, 0.0);

    glPushMatrix();
        drawModel(&bed, "castle.obj", GLM_NONE | GLM_FLAT);
    glPopMatrix();

    glutSwapBuffers();
}

void changeSize(int w, int h)
{
    screen_width=w;
    screen_height=h;

    if(h == 0)
        h = 1;

    float ratio = 1.0*w/h;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, w, h);
    gluPerspective(45.0f, ratio, 1.0f, 1000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0f, 0.0f, 50.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
}

void processNormalKeys(unsigned char key, int x, int y)
{

    switch(key)
    {
        case 't':
            //process
            glutPostRedisplay();
            break;
    }


}

int main(int argc, char* argv[])
{
    //Initialize the GLUT library
    glutInit(&argc, argv);
    //Set the display mode
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    //Set the initial position and dimensions of the window
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(screen_width, screen_height);
    //creates the window
    glutCreateWindow("First OpenGL Application");
    //Specifies the function to call when the window needs to be redisplayed
    glutFullScreen();
    glutDisplayFunc(renderScene);
    //Sets the idle callback function
    glutIdleFunc(renderScene);
    //Sets the reshape callback function
    glutReshapeFunc(changeSize);
    //Keyboard callback function
    glutKeyboardFunc(processNormalKeys);
    //Initialize some OpenGL parameters
    initOpenGL();
    //Starts the GLUT infinite loop
    glutMainLoop();
    return 0;
}

我正在考虑的错误(或在谷歌或此处发现的错误)并没有改变任何错误:

  • 试图设置项目 - &gt;链接器 - &gt;一般 - &gt;启用增量链接=否

  • glm.cpp,glm.h,glut.h,glut32.dll,glut32.lib,StdAfx.h,StdAfx.cpp都在项目目录中

  • 对象及其.mtl文件位于项目目录

任何人都可以帮我找出为什么我无法加载这个对象吗?

0 个答案:

没有答案