2012-06-16 15 views
9

Quiero comenzar a trabajar con OpenGL 3+ y 4 pero estoy teniendo problemas para hacer que Glew funcione. He intentado incluir glew32.lib en las dependencias adicionales y he movido la biblioteca y .dll a la carpeta principal, por lo que no debería haber ningún problema en la ruta. Los errores que estoy recibiendo son:Glew problems,

Error 5 error LNK2019: unresolved external symbol __imp__glewInit referenced in function "void __cdecl init(void)" ([email protected]@YAXXZ) C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader 
Error 4 error LNK2019: unresolved external symbol __imp__glewGetErrorString referenced in function "void __cdecl init(void)" ([email protected]@YAXXZ) C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader 
Error 3 error LNK2001: unresolved external symbol __imp____glewGenBuffers C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader 
Error 1 error LNK2001: unresolved external symbol __imp____glewBufferData C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader 
Error 2 error LNK2001: unresolved external symbol __imp____glewBindBuffer C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader 

Y aquí está la mayor parte de mi código:

#define NOMINMAX 

#include <vector> 
#include <memory> 
#include <string> 
#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <Windows.h> 
#include <cstdio> 
#include <time.h> 
#include "GL\glew.h" 
#include "glut.h" 

#pragma comment(lib, "glew32.lib") 
#pragma comment(lib, "opengl32.lib") 

using namespace std; 

GLsizei screen_width, screen_height; 

float camera[3] = {0.0f, 10.0f, -15.0f}; 

float xPos = 0; 
float yPos = 10; 
float zPos = -15; 
float orbitDegrees = 0; 

clock_t sTime; 
float fPS; 
int fCount; 

GLdouble* modelV; 
GLdouble* projM; 
GLint* vPort; 

//Lights settings 
GLfloat light_ambient[]= { 0.1f, 0.1f, 0.1f, 0.1f }; 
GLfloat light_diffuse[]= { 1.0f, 1.0f, 1.0f, 0.0f }; 
GLfloat light_specular[]= { 1.0f, 1.0f, 1.0f, 0.0f }; 
GLfloat light_position[]= { 100.0f, 0.0f, -10.0f, 1.0f }; 

//Materials settings 
GLfloat mat_ambient[]= { 0.5f, 0.5f, 0.0f, 0.0f }; 
GLfloat mat_diffuse[]= { 0.5f, 0.5f, 0.0f, 0.0f }; 
GLfloat mat_specular[]= { 1.0f, 1.0f, 1.0f, 0.0f }; 
GLfloat mat_shininess[]= { 1.0f }; 

typedef struct Vectors { 
    float x; 
    float y; 
    float z; 
}Vector; 

typedef struct Polys { 
    Vector v; 
    Vector vt; 
    Vector vn; 
    int texture; 
} Poly; 

vector<Vector> vecs; 
vector<Vector> normVecs; 
vector<Vector> textVecs; 

vector<Poly> polyList; 


void loadModel(string filepath); 
void createTex(string ref); 
void render(); 

// An array of 3 vectors which represents 3 vertices 
static const GLfloat g_vertex_buffer_data[] = { 
    -1.0f, -1.0f, 0.0f, 
    1.0f, -1.0f, 0.0f, 
    0.0f, 1.0f, 0.0f, 
}; 

void render() 
{ 
} 

void createTex(string ref) 
{ 
} 

void loadModel(string filepath) 
{ 
} 

void resize (int p_width, int p_height) 
{ 
    if(screen_width==0 && screen_height==0) exit(0); 
    screen_width=p_width; // Obtain the new screen width values and store it 
    screen_height=p_height; // Height value 

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear both the color and the depth buffer so to draw the next frame 
    glViewport(0,0,screen_width,screen_height); // Viewport transformation 

    glMatrixMode(GL_PROJECTION); // Projection transformation 
    glLoadIdentity(); // Initialize the projection matrix as identity 
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,10000.0f); 

    glutPostRedisplay(); // This command redraw the scene (it calls the same routine of glutDisplayFunc) 
} 

void display(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue 
    glMatrixMode(GL_MODELVIEW); // Modeling transformation 
    glPushMatrix(); 
    glLoadIdentity(); // Initialize the model matrix as identity 

    gluLookAt(xPos, yPos, zPos, /* look from camera XYZ */ 
       0, yPos, 0, /* look at the origin */ 
       0, 1, 0); /* positive Y up vector */ 

    glRotatef(orbitDegrees, 0.f, 1.0f, 0.0f); 
    //glTranslatef(0.0,0.0,-20); // We move the object forward (the model matrix is multiplied by the translation matrix) 
    //rotation_x = 30; 
    //rotation_x = rotation_x + rotation_x_increment; 
    //rotation_y = rotation_y + rotation_y_increment; 
     //rotation_z = rotation_z + rotation_z_increment; 

    //if (rotation_x > 359) rotation_x = 0; 
    //if (rotation_y > 359) rotation_y = 0; 
    //if (rotation_z > 359) rotation_z = 0; 

    // glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices) 
    //glRotatef(rotation_y,0.0,1.0,0.0); 
    // glRotatef(rotation_z,0.0,0.0,1.0); 

    //if (objarray[0]->id_texture!=-1) 
    //{ 
    // glBindTexture(GL_TEXTURE_2D, objarray[0]->id_texture); // We set the active texture 
    // glEnable(GL_TEXTURE_2D); // Texture mapping ON 
    // printf("Txt map ON"); 
    //} 
    //else 
    // glDisable(GL_TEXTURE_2D); // Texture mapping OFF 

    glGetDoublev(GL_PROJECTION_MATRIX, modelV); 

    glGetDoublev(GL_PROJECTION_MATRIX, projM); 

    glGetIntegerv(GL_VIEWPORT, vPort); 

    if(clock() > sTime) 
    { 
     fPS = fCount; 
     fCount = 0; 
     sTime = clock() + CLOCKS_PER_SEC; 
    } 

    render(); 

    glDisable(GL_LIGHTING); 

    GLdouble pos[3]; 

    gluUnProject(100, yPos, -14, modelV, projM, vPort, &pos[0], &pos[1], &pos[2]); 

    char buffer2[255]; 

    int pAmmount = sprintf(buffer2,"FPS: %.2f", fPS); 

    //glRasterPos3f(pos[0], pos[1], pos[2]); 

    for(int i = 0; i < pAmmount; i++) 
    { 
     glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, buffer2[i]); 
    } 

    glEnable(GL_LIGHTING); 

    /*glPopMatrix(); 
    glPushMatrix(); 
    glTranslatef(5.0,0.0,-20.0); 
    objarray[1]->render();*/ 
    glPopMatrix(); 
    glFlush(); // This force the execution of OpenGL commands 
    glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer 
    fCount++; 
} 

void keyboard(unsigned char k, int x, int y) 
{ 
    switch(k) 
    { 
     case 'w': 
       yPos++; 
     break; 
     case 's': 
      yPos--; 
     break; 
     case 'a': 
      xPos--; 
     break; 
     case 'd': 
      xPos++; 
     break; 
     case 'q': 
     orbitDegrees--; 
     break; 
     case 'e': 
      orbitDegrees++; 
     break; 
     case 'z': 
      zPos--; 
     break; 
     case 'x': 
      zPos++; 
     break; 
    } 
} 

void initWindow(GLsizei screen_width, GLsizei screen_height) 
{ 
    glClearColor(0.0, 0.0, 0.0, 0.0); // Clear background color to black 

    // Viewport transformation 
    glViewport(0,0,screen_width,screen_height); 

    // Projection transformation 
    glMatrixMode(GL_PROJECTION); // Specifies which matrix stack is the target for matrix operations 
    glLoadIdentity(); // We initialize the projection matrix as identity 
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,10000.0f); // We define the "viewing volume" 

    gluLookAt(camera[0], camera[1], camera[2], /* look from camera XYZ */ 
       0, 0, 0, /* look at the origin */ 
       0, 1, 0); /* positive Y up vector */ 

    try 
    { 
     //loadModel("Goku habit dechiré.obj"); 
     loadModel("Flooring.obj");; 
    } 
    catch(string& filepath) 
    { 
     cerr << "Model could not be loaded: " << filepath << endl; 

     filepath = "Model could not be loaded: " + filepath; 

     wostringstream sString; 

     sString << filepath.c_str(); 

     MessageBox(HWND_DESKTOP, sString.str().c_str(), L"Error: loadModel(string filepath)", MB_OK); 
    } 

    //Lights initialization and activation 
    glLightfv (GL_LIGHT1, GL_AMBIENT, light_ambient); 
    glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse); 
    glLightfv (GL_LIGHT1, GL_DIFFUSE, light_specular); 
    glLightfv (GL_LIGHT1, GL_POSITION, light_position);  
    glEnable (GL_LIGHT1); 
    glEnable (GL_LIGHTING); 

    //Materials initialization and activation 
    glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient); 
    glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); 
    glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_specular); 
    glMaterialfv (GL_FRONT, GL_POSITION, mat_shininess); 

    //Other initializations 
    glShadeModel(GL_SMOOTH); // Type of shading for the polygons 
    //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Texture mapping perspective correction 
    //glEnable(GL_TEXTURE_2D); // Texture mapping ON 
    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled) 
    glEnable(GL_CULL_FACE); // Enable the back face culling 
    glEnable(GL_DEPTH_TEST); // Enable the depth test 
    glEnable(GL_NORMALIZE); 

    /*float* matrix = new float[16]; 

    glGetFloatv(GL_PROJECTION_MATRIX, matrix); 

    for(int i = 0; i < 4; i++) 
    { 
     cout << matrix[0] << " " << matrix[1] << " " << matrix[2] << " " << matrix[3] << endl; 
     matrix += 3; 
    }*/ 

    modelV = new GLdouble[16]; 

    projM = new GLdouble[16]; 

    vPort = new GLint[4]; 

    sTime = clock() + CLOCKS_PER_SEC; 
} 

void init() 
{ 
    GLenum GlewInitResult; 

    GlewInitResult = glewInit(); 

    if (GLEW_OK != GlewInitResult) { 
     fprintf(
      stderr, 
      "ERROR: %s\n", 
      glewGetErrorString(GlewInitResult) 
     ); 
     exit(EXIT_FAILURE); 
    } 

    // This will identify our vertex buffer 
    GLuint vertexbuffer; 

    // Generate 1 buffer, put the resulting identifier in vertexbuffer 
    glGenBuffers(1, &vertexbuffer); 

    // The following commands will talk about our 'vertexbuffer' buffer 
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); 

    // Give our vertices to OpenGL. 
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); 
} 

int main(int argc, char **argv) 
{ 
    screen_width = 800; 
    screen_height = 800; 

    glutInit(&argc, argv);  
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 
    glutInitWindowSize(screen_width,screen_height); 
    glutInitWindowPosition(0,0); 
    glutCreateWindow("ModelLoader");  
    glutDisplayFunc(display); 
    glutIdleFunc(display); 
    glutReshapeFunc (resize); 
    glutKeyboardFunc(keyboard); 

    //glutKeyboardFunc(keyboard); 
    //glutSpecialFunc(keyboard_s); 
    initWindow(screen_width, screen_height); 
    init(); 
    glutMainLoop(); 

    return 0; 
} 

Respuesta

3

Esto ha sido reparado. El problema solo estaba representado en la máquina que estaba usando en la Universidad. El problema era que la máquina tenía un .dll anterior que estaba en conflicto con el .dll que tenía en los archivos de la solución. Fue instalado en los archivos del sistema de la máquina. Como tal, estaba produciendo estos errores.

Probablemente debería comprobarlo la próxima vez.

2

No estoy seguro de cómo va a ayudar, pero, es posible darle una oportunidad y estáticamente enlazar tu proyecto con una biblioteca ".a". o es .lib en windows. Si hay un símbolo no resuelto, significa que intentó vincularlo a una biblioteca y no a un dll.

Si estaba usando el dll, probablemente fallaría en el tiempo de ejecución.

7

Tiene un problema de vinculación. No le está proporcionando al enlazador la ruta correcta al archivo glew lib. Por este motivo, el vinculador no puede encontrar el código compilado de las funciones a las que llama.

De su registro parece que está trabajando en Windows. Si está usando Visual Studio, haga clic derecho en su proyecto. Seleccione Enlazador, y luego Entrada. Verifique que las dependencias adicionales contengan la ruta de acceso a glew lib.

Observe que el dll no es necesario en el momento de la vinculación. Esto se cargará solo en el tiempo de ejecución (recuerde ponerlo en la misma carpeta que su ejecutable o en una ruta incluida en la ruta de su sistema).