Skip to content
Advertisement

Opengl using freeglut on linux shows only a transparent window

I am trying to use freeglut3 on linux mint 20 to do some basic openGL ( my teacher forced me to use glut/freeglut with c++ ). I am just trying to make a black window to show on screen but only a transparent window shows up and it doesn’t close until it shows Segmentation fault (core dumped)

here is my code

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void init()
{
    glClearColor(1, 0, 0, 1);
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glFlush();
    glutSwapBuffers();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowPosition(300, 100);
    glutInitWindowSize(400, 400);
    glutCreateWindow("Linux TEST");
    glutDisplayFunc(display);
    init();
    glutMainLoop();
}

I am using g++ main.cpp -lGL -lGLU -lglut to compile the code

Here is the output screenshot

Advertisement

Answer

You’re creating a double buffered context using…

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

But you never call glutSwapBuffers. Change your display function to…

void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glFlush();
    glutSwapBuffers();
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement