Failed to Initialize GLEW. Missing GL version [closed]
Asked Answered
N

6

30

I've tried to set up SFML 2.0 with the latest version of the qt creator, I've set up SFML right and I imported a small game I wrote in visual studio. Upon compilation, I get this:

enter image description here

What I tried

  • Reinstalling the entire qt SDK and qt creator IDE from scratch
  • Reinstalling SFML
  • reinstalling mingw
  • I tried to write a simple program to make sure it's not my code, the program compiles correctly but when I close the application, I get OpenGL errors which is not normal
  • I tried posting a thread on the SFML forums but to no avail.
  • Googling the errors shows a few results, which are specific to OpenGL, and which are too localized, they don't apply to me, no answer for this happening in SFML 2.0

Additional details

  • I'm running windows XP SP3, latest version of mingw and qt SDK and SFML

  • The code I'm trying to work with works without any errors or even warnings on Visual Studio 2010 and Code::Blocks

  • Yes, I am sure that SFML is set up on my IDE, basic code works but shows those errors and more advanced code shows all sprites and text as boxes.

  • I did not compile SFML myself

  • My gcc version is 4.6.2

  • My gcc is a DW2 one

I'm getting no results, I don't even know how to remotely get close to fixing this, not even where to start.

EDIT I can't show you all of my code, it's over 20 files and I'm almost 90% sure it's not my code, I've said it above: I can run this code without any warnings or even errors on any IDE except qt creator.

Neurath answered 11/1, 2013 at 10:45 Comment(5)
There is something wrong with your code's initialization. GLEW throws this error when the GLContext is invalid. Check the lifecycle of your objects in your initialization to make sure SFML's not being released before your initialize GLEW.Centrosome
@Centrosome it can't be my code, this works 100% on almost every IDE I've tried, and SFML has never done this to me, it usually does it's openGL stuff without me having to worry about itNeurath
Well the error is GLEW_ERROR_NO_GL_VERSION -- which means that the GLContext is either A) not loaded, B) no longer valid -- the GL context needs to be created and validated before calling glewInit(); not sure what has changed since your move, but I'm sure it's something silly considering how frustrating it is :DCentrosome
Writing a hello world program in SFML shows the same errors. It's not the code for certain, I'm sure it's something silly too but I can't even remotely get an idea of what's wrongNeurath
@Bugster: Then post the hello world program.Cigarette
A
30

It's because you are not initializing OpenGL. Example with the lib glut.

Wrong:

 glewInit();  // ERROR MISSING GL VERSION
 glutInitDisplayMode(GLUT_RGB); 

Good:

 glutInitDisplayMode(GLUT_RGB);
 glewInit();

EDIT I think for SFML:

 sf::Window   App(sf::VideoMode(400, 400, 32), "Window");
 glewInit();

EDIT 2 Test this code.

#include <SFML/Window.hpp>
#include <iostream>
#include <GL/glew.h>

int
main(int, const char**)
{
    GLenum      err;

    std::cout << "Start" << std::endl;
    std::cout << "Test 1" << std::endl;
    if ((err = glewInit()) != GLEW_OK)
        std::cout << glewGetErrorString(err) << std::endl;

    std::cout << "Init window" << std::endl;
    sf::Window  app(sf::VideoMode(400, 400, 32), "Windows");

    std::cout << "Test 2" << std::endl;
    if ((err = glewInit()) != GLEW_OK)
        std::cout << glewGetErrorString(err) << std::endl;
    std::cout << "End" << std::endl;
    return 0;
}

My output:

Start
Test 1
Missing GL version
Init window
Test 2
End

Compile with: g++ -W -Wall -Werror main.cpp -lsfml-window -lGLEW

Good Luck ;)

Alveolate answered 24/2, 2013 at 17:40 Comment(5)
I'm not supposed to be initializing that, SFML should be doing it for me, I'm using a library that is supposed to be initializing openGL, I don't know how to work in OpenGL, but I know how to work in SFML and it's not working because of this error.Neurath
I got GLEW_OK by modifying glutInitDisplayMode(GLUT_RGB); in the above solution to glutInit(&argc, argv); and glutCreateWindow("GLEW Test");. Hope this helps~Farber
For those using GLFW instead of SFML, you need to call glewInit() after glfwMakeContextCurrentDisprize
@syler should make your comment a separate Q&A; ate my hours!!Lodie
@Disprize You sir are the WinRar.Soubriquet
D
8

At the request of user3648895, I am posting my answer outside of the comments separately.

For those using GLFW instead of SFML, you need to call glewInit() after glfwMakeContextCurrent

Disprize answered 8/2, 2015 at 0:45 Comment(0)
M
7

If you're using glew with glfw, use glfwMakeContextCurrent (https://github.com/Cloudef/glhck/issues/15)

Meader answered 11/5, 2017 at 0:51 Comment(1)
You can improve the quality of your Answer by including a description of what you believe was the cause of the Questioner's problem and how your Answer fixes this.Hernardo
I
1

For those using SDL2's Renderer functions, it needs to be right after SDL_CreateRenderer.

Ifni answered 2/5, 2015 at 19:54 Comment(2)
SDL_CreateRenderer is not for openGL, right? Because for GL you need to make a context.Alvinia
I don't have SDL_CreateRenderer call in my code, however this was a helpful hint. glew initialization must be called after some SDL creation.Teeming
K
1

putting the glewInit(); after the sf::window creation that solves my problem for using glew with sfml

Keffiyeh answered 2/5, 2020 at 16:7 Comment(0)
T
1

its clearly mentioned in the docs of GLEW

"First you need to create a valid OpenGL rendering context and call glewInit() to initialize the extension entry points. If glewInit() returns GLEW_OK, the initialization succeeded and you can use the available extensions as well as core OpenGL functionality"

if you are using GLFW then you have to call after "glfwMakeContextCurrent(window)" this function.

Theatheaceous answered 16/8, 2021 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.