I have the same problem trying to use OpenGL - for learning. My program:
#include <SFML/Window.hpp>
//#include <SFML/OpenGL.hpp>
#include <GL/glew.h>
#include <stdint.h>
GLuint vbo[2]; // I want to generate two VBOs
void drawProc()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.f, 0.5f, 1.f, 1.f); // light blue
}
int main(int argc, char **argv)
{
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 4;
settings.majorVersion = 3;
settings.minorVersion = 0;
sf::Window window(sf::VideoMode(800, 600), "OpenGL Test", sf::Style::Default, settings);
window.setVerticalSyncEnabled(true);
float triangle[9] =
{
-0.4f, 0.1f, 0.0f,
0.4f, 0.1f, 0.0f,
0.0f, 0.7f, 0.0f
};
float quad[12] =
{
-0.2f, -0.1f, 0.0f,
-0.2f, -0.6f, 0.0f,
0.2f, -0.1f, 0.0f,
0.2f, -0.6f, 0.0f
};
glGenBuffers(2, vbo); // gdb says, that this program crashes on this line
/*glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 9, triangle, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 12, quad, GL_STATIC_DRAW);*/
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed) window.close();
}
drawProc();
window.display();
}
return 0;
}
I already got the code working with the drawProc and not generating any VBO, my screen was cleared blue, as wished. But as soon, as I try to generate a buffer (only works, when I include GL/glew.h, it is not available with SFML/OpenGL.hpp...), my program crashes.
I am using linux (64-bit) and compiling the program above with the following command:
g++ main.cpp -o opengl-test -g $(pkg-config --cflags --libs sfml-window gl glew)
EDIT: glewInit() right after the window creation solves the problem in my case!
sf::Window window(sf::VideoMode(800, 600), "OpenGL Test", sf::Style::Default, settings);
glewInit();