DEV Community

dwarfŧ
dwarfŧ

Posted on • Updated on

making a window in opengl and GLFW, a c++ guide

intro
i have made a post on making a window in just opengl but i found most tutorials used GLFW for window displaying

step 1
first install opengl on your Operating System(OS) i am using ubuntu and i installed it from here

step 2
you need to install GLFW for ubuntu linux i found a tutorial here, however you will need to install it for your OS.

step 3

i found the code to making a window off the installation guide to install GLFW for ubuntu here, this is the code:

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

step 4
to compile your main.cpp file you can do

g++ -pthread -o main main.cpp -lglfw -lGLU -lGL -lXrandr -lX11 -lrt -ldl -lglut
Enter fullscreen mode Exit fullscreen mode

i included some extra library's for when you are doing other things with opengl so you wont run into library errors

step 5
enjoy and good luck coding

Oldest comments (0)