I'm currently trying to learn OpenGL with the use of GLFW and the Addison Wesley book 'OpenGL Programming guide 7th edition'. Here is one of the first sample programs they present, it is meant to draw a white box. In this example I mixed it with a simple glfw window and message loop:

#include "glfw\include\GL\glfw.h"
#include <stdlib.h>

int main( void )
	int running = GL_TRUE;

	if ( !glfwInit() )
		exit( EXIT_FAILURE );

	if ( !glfwOpenWindow( 640, 480, 8, 8, 8, 8, 24, 0, GLFW_WINDOW ) )
		exit( EXIT_FAILURE );

	while( running )
		glClearColor(0.0, 0.0, 0.0, 0.0);
		glColor3f( 1.0, 1.0, 1.0 );
		glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 );
		glBegin( GL_POLYGON );
			glVertex3f( 0.25, 0.25, 0.0 );
			glVertex3f( 0.75, 0.25, 0.0 );
			glVertex3f( 0.75, 0.75, 0.0 );
			glVertex3f( 0.25, 0.75, 0.0 );

		running = !glfwGetKey( GLFW_KEY_ESC ) &&
			glfwGetWindowParam( GLFW_OPENED );


	exit( EXIT_SUCCESS );

I believe in the book they use GLUT and I think the reason this won't work has something to do with the 'glfwSwapBuffers()' call. If you place it before the glClear() block it very briefly shows the square before going to black. Also if you remove the glClear() call it displays a flickering square.
Maybe it's only rendering on one of the buffers? If that's the case I don't understand why it isn't drawing the box on both of the buffers.
I've been looking at this for a while now, any help would be appreciated (even if it's not direct help). Thank You! :)

5 Years
Discussion Span
Last Post by NoMoreRobots

Nevermind, after researching further I found that glOrtho needs to be called only once at the beginning as an initialization. Do so every rotation of the loop causes it to mess up the values somehow.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.