I thought I should write this, it's nothing special just a full screen application drawing one triangle.
I removed the source code for writing to the log file from here because it have nothing to do with the actual program, but it is still in the source code file below.
Source code
I need these headerfiles.
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
A keyboard array for input.
int KeyDown[256];
This function is called when a key is pressed, setting the value for input.
void keyboard(unsigned char key, int x, int y)
{
KeyDown[key] = 1;
}
This function is called when a key is released, setting the value for input.
void keyboardUp(unsigned char key, int x, int y)
{
KeyDown[key] = 0;
}
This function is called every frame to update the screen.
void display(void)
{
Clear the screen.
glClear(GL_COLOR_BUFFER_BIT);
Start drawing triangles
glBegin(GL_TRIANGLES);
Giving three cordinates, needed to draw an triangle.
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
Done drawing triangles.
glEnd();
Refresh the screen.
glutSwapBuffers();
Check to see if ESC key is pressed.
if ( KeyDown[27] )
{
Exit program.
exit(0);
}
}
The starting point of the application.
int main(int argc, char * argv[])
{
Do some GLUT init.
glutInit( &argc, argv );
Chose some parameters wanted for the application.
GLUT_RGBA = RGBA color.
GLUT_DOUBLE = double buffers with a back buffer to draw on.
GLUT_DEPTH = want to store Z values to determine in 3D if an object is in front or behind an other object.
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
Set the screen values.
glutGameModeString( "1280x800:32@60" );
Now we enter fullscreen.
glutEnterGameMode();
Set the render function that will be called every frame also sett it as Idle function.
glutDisplayFunc( display );
glutIdleFunc( display );
Clear the input array.
for(int i = 0 ; i != 256 ; i++)
KeyDown[i] = 0;
Set the input functions that will be called when a button on the keyboard is pressed/released.
glutKeyboardFunc( keyboard );
glutKeyboardUpFunc( keyboardUp );
Start the main loop.
glutMainLoop();
Return 0 if everything went well!
return 0;
}