2012-06-16 13 views
9

Voglio iniziare a lavorare con OpenGL 3+ e 4 ma ho problemi a far funzionare Glew. Ho provato ad includere il glew32.lib nelle dipendenze aggiuntive e ho spostato la libreria e .dll nella cartella principale, quindi non ci dovrebbero essere problemi di percorso. Gli errori che sto ottenendo sono:Glew problemi, esterni non risolti

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 

Ed ecco la maggior parte del mio codice:

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

risposta

3

Questo problema è stato risolto. Il problema era rappresentato solo sulla macchina che stavo usando in università. Il problema era che la macchina aveva una .dll precedente che era in conflitto con il file .dll che avevo nei file della soluzione. È stato installato nei file di sistema della macchina. Come tale stava producendo questi errori.

Probabilmente dovrei controllare una cosa del genere la prossima volta.

2

Non sono sicuro di come vi aiuterà, ma, si potrebbe dare una prova e staticamente collegare il progetto una libreria ".a". o è .lib su windows. Se ci sono dei simboli non risolti significa che ha provato a collegarsi a una libreria e non a una DLL.

Se si stesse utilizzando la DLL, probabilmente non funzionerebbe in fase di esecuzione.

7

Si verifica un problema di collegamento. Non stai fornendo al linker il percorso corretto per il file lib di glew. Per questo motivo il linker non è in grado di trovare il codice compilato delle funzioni che stai chiamando.

Dal registro sembra che si stia lavorando su Windows. Se si utilizza Visual Studio, fare clic con il pulsante destro del mouse sul progetto. Seleziona Linker, quindi Input. Verifica che le dipendenze aggiuntive contengano il percorso di glew lib.

Si noti che la DLL non è richiesta al momento del collegamento. Questo verrà caricato solo in fase di esecuzione (ricordati di inserirlo nella stessa cartella del tuo eseguibile o in un percorso elencato nel tuo percorso di sistema).

Problemi correlati