Question

I'm using VS2010 and I was able to compile a program with an empty white window but then when I tried to create buffer and texture objects I get these linker errors.

1>main.obj : error LNK2001: unresolved external symbol ___glewBufferData
1>main.obj : error LNK2001: unresolved external symbol ___glewBindBuffer
1>main.obj : error LNK2001: unresolved external symbol ___glewGenBuffers

I've double checked that my include directories have the path to glew and freeglut's include folders. I've also made sure that the it's library folders are set under Additional Library Directories and Additional Dependencies have freeglut.lib, glew32.lib, opengl32.lib.

I also added "GLEW_STATIC" to Processor Definitions

I've placed the glew32.dll and freeglut.dll into the same folder as the exe files.

I've tried adding this line

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

as well as

#define GLEW_STATIC 1

but no combination of any of them has worked. Someone please help! I really don't know what else to do.

This is what my code looks like now.

#include <GL/glew.h>
#include <GL/wglew.h>
#include <GL/freeglut.h>

#include <iostream>

#include "util.h"

static struct {
    GLuint vertex_buffer, element_buffer;
    GLuint textures[2];

    // Shader objects go here
} gl_resources;

static GLuint make_buffer( GLenum target, const void *buffer_data,
        GLsizei buffer_size){
    GLuint buffer;
    glGenBuffers(1, &buffer); // Creates the object name.
    glBindBuffer(target, buffer); // Binds the object name to the target.

    // Allocates the buffer.
    glBufferData(target, buffer_size, buffer_data, GL_STATIC_DRAW);
    return buffer;
}

static const GLfloat gl_vertex_buffer_data[] = {
    -1.0f,  -1.0f,  // bottom left
     1.0f,  -1.0f,  // bottom right
    -1.0f,   1.0f,  // top left
     1.0f,   1.0f   // top right
};

static const GLushort gl_element_buffer_data[] = {0, 1, 2, 3};

static GLuint make_texture(const char *filename){
    GLuint texture;
    int width, height;
    void *pixels = read_tga(filename, &width, &height);

    if (!pixels)
        return 0;
    glGenTextures(1, &texture); // Creates a texture object.
    glBindTexture(GL_TEXTURE_2D, texture); // our texture object to a 2D target.

    // Setting texture parameters.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);

    // Allocating textures
    glTexImage2D(
        GL_TEXTURE_2D, 0,           // target, level of detail
        GL_RGB8,                    // internal format
        width, height, 0,           //  width, height, border
        GL_BGR, GL_UNSIGNED_BYTE,   // external format, type
        pixels                      // pixels
    );

    free(pixels);
    return texture;

}

// -----------------------------------------------------------------------------

static int make_resources(void){
    // Making Buffers
    gl_resources.vertex_buffer = make_buffer(GL_ARRAY_BUFFER, 
        gl_vertex_buffer_data, sizeof(gl_vertex_buffer_data));
    gl_resources.element_buffer = make_buffer(GL_ELEMENT_ARRAY_BUFFER,
        gl_element_buffer_data, sizeof(gl_element_buffer_data));

    // Making textures
    gl_resources.textures[0] = make_texture("hello1.tga");
    gl_resources.textures[1] = make_texture("hello2.tga");

    if(gl_resources.textures[0] == 0 || gl_resources.textures[1] == 0)
        return 0;

    // Making shaders
    return 1;
}

static void update_fade_factor(void){ // Update

}

static void render(void){
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Sets the Clear colour to white.
    glClear(GL_COLOR_BUFFER_BIT); // fills the buffer with the Clear colour.
    glutSwapBuffers(); // Brings the cleared buffer to the screen.
}

// -----------------------------------------------------------------------------


int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Double for smoother render
    glutInitWindowSize(400,300);
    glutCreateWindow("Hello World");
    glutDisplayFunc(&render);
    glutIdleFunc(&update_fade_factor);

    if(!make_resources()){
        fprintf(stderr,"Failed to load resources\n");
        return 1;
    }

    glutMainLoop();
    return 0;
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top