From the posts, comp.graphics.api.openglit seems that most newbies burn their hands in their first OpenGL program. In most cases, an error occurs because OpenGL functions are called before the correct OpenGL context is created. OpenGL is a state machine. Only after the machine has been started and humming in a ready state can it be started.
Here is simple code to create a valid OpenGL context:
#include <stdlib.h>
#include <GL/glut.h>
static const unsigned int WIN_POS_X = 30;
static const unsigned int WIN_POS_Y = WIN_POS_X;
static const unsigned int WIN_WIDTH = 512;
static const unsigned int WIN_HEIGHT = WIN_WIDTH;
void glInit(int, char **);
int main(int argc, char * argv[])
{
glInit(argc, argv);
glutMainLoop();
return 0;
}
void glInit(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowPosition(WIN_POS_X, WIN_POS_Y);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutCreateWindow("Hello OpenGL!");
return;
}
Note:
- Challenge of interest here
glutCreateWindow(). It not only creates a window, but also creates an OpenGL context. - ,
glutCreateWindow(), , glutMainLoop().