0

I am getting an error when trying to build this program:

these are the files of the class where the error is happening:

Sprite.h

#ifndef SPRITE_H
#define SPRITE_H

#include <GL/glew.h>


class Sprite
{
    public:
        Sprite();
        virtual ~Sprite();

        void draw();
        void init(int x, int y, int width, int height);

    protected:
    private:
        int _x;
        int _y;
        int _width;
        int _height;
        GLuint _vboID;
};

#endif // SPRITE_H

Sprite.cpp

#include "Sprite.h"

Sprite::Sprite(){
    _vboID = 0;
}

Sprite::~Sprite()
{
    //dtor
}

void Sprite::init(int x, int y, int width, int height){
    _x = x;
    _y = y;
    _width = width;
    _height = height;

    if(_vboID == 0){
       glGenBuffers(1, &_vboID);
    }

    float vertexData[12];

    //first triangle
    vertexData[0] = x + width;
    vertexData[1] = y + height;

    vertexData[2] = x;
    vertexData[3] = y + height;

    vertexData[4] = x;
    vertexData[5] = y;

    //second triangle

    vertexData[6] = x;
    vertexData[7] = y;

    vertexData[8] = x + width;
    vertexData[9] = y;

    vertexData[10] = x + width;
    vertexData[11] = y + height;

    glBindBuffer(GL_ARRAY_BUFFER, _vboID);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);

}

void Sprite::draw(){

}

Also I have my linkers set up as following in this order under link libraries:

mingw32
libSDL2main
libSDL2
glew32
glew32s
openGL32

I found some solutions that say you have to use #define GLEW_STATIC. This solution however did not work for me. also changing the order of the linkers didn't change anything.

  • Possible duplicate of [undefined reference to '\_imp\_\_\_glewGenBuffers'](http://stackoverflow.com/questions/16369310/undefined-reference-to-imp-glewgenbuffers) – dewaffled Dec 25 '15 at 21:03

1 Answers1

0

Make sure you link the library where glGenBuffers is implemented (I guess it's openGL). You wrote that you link that library, make sure that the linkage settings is set for all configurations (debug, release) and architectures(x64, win32)

Benny Isaacs
  • 105
  • 1
  • 8
  • I have set the linkers for debug and release and for the right architecture, other parts of Glew do work but only when I try to use glGenBuffers it returns an error – Miquel Smits Dec 26 '15 at 00:57
  • Try to order the linker libraries so glew32s will be at the top. – Benny Isaacs Dec 26 '15 at 01:07
  • tried that before and didn't work and if I #define GLEW_STATIC it won't work either. then it says that I have multiple references to glewinit. This is probably because I have glew32 and glew32s. But deleting either one of them calls up another undefined error. – Miquel Smits Dec 26 '15 at 02:54