SFML community forums

Help => Window => Topic started by: Vekta on June 07, 2011, 01:42:27 am

Title: Using glew with sfml 2.0 problem
Post by: Vekta on June 07, 2011, 01:42:27 am
Hello, i've been having some trouble setting up an OpenGl 3.2 context with sfml 2.0 and glew.

When i call glewInit() it retuns the error "Missing GL version". I've tried the same code using freeGLUT for the context and it worked perfectly. I can only deduce that im using SFML wrong somehow.

Here is the code

Code: [Select]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#define WINDOW_TITLE_PREFIX "Chapter 2"


void Initialize(int, char*[]);
void InitWindow(void);


int main(int argc, char* argv[])
{
InitWindow();
Initialize(argc, argv);
exit(EXIT_SUCCESS);
}

void InitWindow()
{
sf::Window App(sf::VideoMode(800, 600, 32), "OpenGL");

}

void Initialize(int argc, char* argv[])
{

GLenum GlewInitResult;

glewExperimental = GL_TRUE;
GlewInitResult = glewInit();

if (GLEW_OK != GlewInitResult) {
fprintf(
stderr,
"ERROR: %s\n ",
glewGetErrorString(GlewInitResult)
);
exit(EXIT_FAILURE);
}

fprintf(
stdout,
"INFO: OpenGL Version: %s\n",
glGetString(GL_VERSION)
);
}


I'm probably being stupid and I apologize but any help is greatly appreciated!
Title: Using glew with sfml 2.0 problem
Post by: Laurent on June 07, 2011, 07:56:56 am
Quote
Code: [Select]
void InitWindow()
{
   sf::Window App(sf::VideoMode(800, 600, 32), "OpenGL");

}

Here you create a window, with an OpenGL context, and... it is destroyed immediately, before the function returns. Therefore when you call glewInit() you have no OpenGL context.
Title: Using glew with sfml 2.0 problem
Post by: Vekta on June 07, 2011, 10:22:03 am
Ah of course, thank you