Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLFW 3 initialized, yet not?

Tags:

c++

opengl

glfw

I'm struggling with creating a window with the GLFW 3 function, glfwCreateWindow. I have set an error callback function, that pretty much just prints out the error number and description, and according to that the GLFW library have not been initialized, even though the glfwInit function just returned success?

Here's an outtake from my code

// Error callback function prints out any errors from GFLW to the console
static void error_callback( int error, const char *description )
{
    cout << error << '\t' << description << endl;
}


bool Base::Init()
{
    // Set error callback
    /*!
     *  According to the documentation this can be use before glfwInit,
     *  and removing won't change anything anyway
     */
    glfwSetErrorCallback( error_callback );



    // Initialize GLFW
    /*!
     *  This return succesfull, but...
     */ 
    if( !glfwInit() )
    {
        cout << "INITIALIZER: Failed to initialize GLFW!" << endl;
        return false;
    }
    else
    {
        cout << "INITIALIZER: GLFW Initialized successfully!" << endl;
    }



    // Create window
    /*!
     *  When this  is called, or any other glfw functions, I get a
     *  "65537    The GLFW library is not initialized" in the console, through
     *  the error_callback function
     */
    window = glfwCreateWindow( 800,
                               600,
                               "GLFW Window",
                               NULL,
                               NULL );


    if( !window )
    {
        cout << "INITIALIZER: Failed to create window!" << endl;
        glfwTerminate();
        return false;
    }


    // Set window to current context
    glfwMakeContextCurrent( window );


    ...


    return true;
}

And here's what's printed out in the console

INITIALIZER: GLFW Initialized succesfully!
65537    The GLFW library is not initialized
INITIALIZER: Failed to create window!

I think I'm getting the error because of the setup isn't entirely correct, but I've done the best I can with what I could find around the place

I downloaded the windows 32 from glfw.org and stuck the 2 includes files from it into minGW/include/GLFW, the 2 .a files (from the lib-mingw folder) into minGW/lib and the dll, also from the lib-mingw folder, into Windows/System32

In code::blocks I have, from build options -> linker settings, linked the 2 .a files from the download. I believe I need to link more things, but I can figure out what, or where I should get those things from.

like image 950
Mikkel Dockweiler Sørensen Avatar asked Jun 29 '13 15:06

Mikkel Dockweiler Sørensen


People also ask

Do I need OpenGL for GLFW?

By default, the OpenGL context GLFW creates may have any version. You can require a minimum OpenGL version by setting the GLFW_CONTEXT_VERSION_MAJOR and GLFW_CONTEXT_VERSION_MINOR hints before creation. If the required minimum version is not supported on the machine, context (and window) creation fails.

Is GLFW C or C++?

GLFW is written in C and supports Windows, macOS, X11 and Wayland.

Can you use GLFW in C++?

3.1 - What compilers are supported by GLFW? Currently, GLFW releases are tested with MinGW, MinGW-w64 and Visual C++ 2010, 2012, 2013 and 2015, but it should work with any compiler that supports C99 (C89 on Windows). Very old development environments may require updated system headers.

What is glfwInit?

glfwInit. int glfwInit(void) Initializes the GLFW library. If any part of initialization fails, any parts that succeeded are terminated as if glfwTerminate had been called. The library only needs to be initialized once and additional calls to an already initialized library will return GLFW_TRUE immediately.


1 Answers

I tried reinstalling codeblocks and mingw, which solved the issue.

Seems like GLFW3 doesn't like having previous versions installed at the same time for some reason, so if anyone else is having a similar problem, you might want to try that.

like image 195
Mikkel Dockweiler Sørensen Avatar answered Sep 29 '22 04:09

Mikkel Dockweiler Sørensen