Anyone knows why this happens when trying to generate a simple square in OpenGL?
I am using the following source code from the book Computer Graphics Through
Try adding a call to glutSwapBuffers(); at the end of drawScene and removing GLUT_SINGLE from glutInitDisplayMode. Single-buffer mode has all sorts of compatibility issues. On Windows it uses the software rasterizer which is VERY slow and has even more issues.
If that doesn't work, try clearing the depth buffer by changing glClear to glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); and glClearcolor to glClearColor(1.0, 1.0, 1.0, 1.0);.
Also, this example uses legacy OpenGL, which is significantly slower than modern OpenGL and has many other problems. Unless you are using a GPU that's more than a decade old, you have zero reason to use it. Technically, modern GPUs aren't even required to support it. If you need a good modern OpenGL tutorial, http://open.gl is a good one. Just look for an OpenGL 2.1 (or later) tutorial.