0

PS: I've already tried the answers in this link: Supposedly duplicated :(

But I didn't get any results, the same error still shows.

I´m trying to compile some code in c++, im using SDL and GLEW,I was trying to create a simple sprite but doing it I get the next output:

Errors

This is my source:

#include "Sprite.h"

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

Sprite::~Sprite() {
    if(_vboID != 0){
    glDeleteBuffers(1, &_vboID);
    }
}

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

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

    float vertexData[12];

    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);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

void Sprite::draw() {
    glBindBuffer(GL_ARRAY_BUFFER, _vboID);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    glDisableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

I have all my labraries added, but i have this output.

SupineDread89
  • 580
  • 2
  • 7
  • 17
  • Those are linker errors. Usually they mean you neglected to specify a library your code needs to the linker. If you wrote the makefile, you should add it to the question. If it was generated by the IDE, you'll need to find the library configuration panel and add the missing library. – user4581301 Mar 08 '17 at 04:44
  • Are you able to execute any other Glew functions other than the ones in your sprite class? – Falla Coulibaly Mar 08 '17 at 04:44
  • https://gyazo.com/2668dad9906dc4e027f339e27a09ee4d glDrawArrays(); does not make any error – SupineDread89 Mar 08 '17 at 05:15
  • Do you mean the CMakeLists.txt? https://gyazo.com/668cdf08d73de54f0b4b8793795c56d6 – SupineDread89 Mar 08 '17 at 05:17
  • https://github.com/SupineDread/VideoGameTraining this is my source – SupineDread89 Mar 08 '17 at 05:18
  • Your image of text [isn't very helpful](//meta.unix.stackexchange.com/q/4086). It can't be read aloud or copied into an editor, and it doesn't index very well, meaning that other users with the same problem are less likely to find the answer here. Please [edit] your post to incorporate the relevant text directly (preferably using copy+paste to avoid transcription errors). – Toby Speight Mar 09 '17 at 11:30
  • Your code is incomplete; in particular, it seems to be missing a `main()` function and at least one `#include`. Even more importantly, you don't show your compile and link commands, and they are probably crucial to solving the problem. Please [edit] your question to include a [mcve] of the Makefile (or equivalent) that can reproduce this. – Toby Speight Mar 09 '17 at 11:32
  • I hace my main funtion and all my #include in the main.cpp, sorry about images. My question was marked as duplicated, maybe otherbusers with my problem can find the answer y the "original". I dont use compile commands i was using Clion, i changed my project to visual studio and it worked. – SupineDread89 Mar 09 '17 at 15:02

1 Answers1

2

Add this to your CMakeLists.txt

find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})

and in the target_link_libraries( ... ${GLEW_LIBRARIES} ... )

This will most likely fix your problem, but you should dive more deeply into cmake and write a cleaner CMakeLists.txt file.

OutOfBound
  • 1,914
  • 14
  • 31
  • https://gyazo.com/a3c2d848246965e652ad00cf637f149a testing the CMakeLists i have this output. I see _GLEW_INCLUDE_DIR GLEW_LIBRARY_ in my FindGLEW.cmake file, i dont know where is missing _GLEW_INCLUDE_DIR GLEW_LIBRARY_ – SupineDread89 Mar 08 '17 at 16:02
  • It seems, like your cmake is not aware of your glew installation. Can you try adding -DGLEW_DIR= to you cmake call? – OutOfBound Mar 09 '17 at 10:14
  • I changed all my project to visual studio and it worked, with the same library versions and the same #include. But thanks you Wero so helpful – SupineDread89 Mar 09 '17 at 14:56