Cannot create a simple colored window (OpenGL, GLFW, GLEW)

Viewed 372

I have been trying for days to create a simple window with a blue background, but for some unknown reason, I only get a black window. I am compiling a small program using the following 3 files.

  • main.cpp
#include "wind.hpp"

int main()
{
    wind display;
    display.test();
}
  • wind.hpp
#include <GL/glew.h>
#include <GLFW/glfw3.h>

class wind
{
public:

    void test();

};
  • wind.cpp
#include "wind.hpp"

void wind::test()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);

    glfwMakeContextCurrent(window);

    glewInit();

    std::cout << "Version: " << glGetString(GL_VERSION) << std::endl;

    static unsigned frameCount = 0;

    while (true)
    {
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);


        std::cout << ++frameCount << '\r';

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
}

I compile a program containing these 3 files and the output is:

enter image description here

System: Ubuntu 18.04.5 LTS. Tools used: OpenGL (color), GLFW (for the window), GLEW (for OpenGL calls), CMake (for the building).

Some facts:

  • glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL) != NULL
  • glewInit() == GLEW_OK
  • In the console, the only output I get is Version: . Any subsequent std::cout seems to be not executed (no output).
  • If I delete the line std::cout << "Version: " << glGetString(GL_VERSION) << std::endl; I get the frameCount values in the console (so, main loop is running). But the window is still black.
  • If I create a static library with "wind.hpp" and "wind.cpp" (say "libwind.a"), and then I link it to my program ("main.cpp"), and compile... I get the blue window. But I should need to do all this just for creating this simple blue window. I can't understand why it works this way and not the other...

enter image description here

0 Answers
Related