Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Failed to create GLFW window

CODE:

#include "include/glad/glad.h"
#include "include/GLFW/glfw3.h"
#include <iostream>

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    GLFWwindow* window = glfwCreateWindow(800, 800, "YoutubeOpenGL", NULL, NULL);
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    glViewport(0, 0, 800, 800);
    glClearColor(0.07f, 0.13f, 0.17f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glfwSwapBuffers(window);
    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

Whenever I run it it shows failed to create GLFW window
can someone fix my code? or something

I was expecting for a window

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is impossible to debug from this distance.

You will have to check the errors GLFW encounters.

You do that by registering an error handler call back function:

https://www.glfw.org/docs/3.0/group__error.html

In that function, you can log the error message to stdout or a file, for example.

Generally, reading your string "YoutubeOpenGL", I’d argue that directly working with GLFW might be a bit more low-level than you want. There’s enough other frameworks that handle the system specifics for you, so that you don’t have to do windows, linux, OS X… specific modifications yourself. The "big gun" in that is certainly Qt, which supports OpenGL accelerated graphics just as well, but also slimmer, and still quite low-level UI tool kits like DearImgui (with the glfw backend) would serve you better than trying to start with GLFW.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading