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

opengl window initialization issue

I’m new to glfw and I’m trying to encapsulate it in a class to make my code cleaner.
So in my class, I’ve made the basic window creation but when I execute the program, it always enter in the if statement where I check if the initialization went right or not and I don’t know why. This is what I have

#include "include/Window.h"
#include <iostream>

Window::Window(int x, int y) {
    _window = glfwCreateWindow(x, y, "Heightmap Visualizer", NULL, NULL);
}

Window::~Window() {
    glfwTerminate();
}

int Window::createWindow() {
    if (!_window) {
        std::cerr << "went here" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(_window);
    run();
    glfwTerminate();
    return 0;
}

void Window::run() {
    while (!glfwWindowShouldClose(_window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(_window);
        glfwPollEvents();
    }
}

This is the header file

#include <GLFW/glfw3.h>

class Window {
public:
    Window(int x, int y);
    ~Window();
    int createWindow();
    void run();

private:
    GLFWwindow* _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 :

Make sure to glfwInit().

Also good luck in your jorney learning GL and C++!

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