Basic OpenGL for the Newbie, Part 1

BlitzMax Forums/BlitzMax Tutorials/Basic OpenGL for the Newbie, Part 1

The Display

Lets go back through the previous listing and take a look at the display commands:

bglCreateContext(800,600,32,0,BGL_BACKBUFFER|BGL_DEPTHBUFFER|BGL_FULLSCREEN)

We already know that this is the all important screen setting command.

glClearColor(0.0, 0.0, 0.0, 0.0)

This sets the background colour to black ( RGB 0, 0, 0), values can range from 0.0 to 1.0. '0' being black and '1' being the brightest (white). As you've no doubt guessed, the values go in the format of RGB (red, green & blue) - playing around with the values will change the colour. The fourth 0.0 value is an alpha transparency colour which will not be used just yet.

glColor3f(0.0, 0.0, 1.0);

This sets the foreground colour, in this case the triangle to blue. You can use this command anywhere you want in the program, usually its before a side of an object (which means that each side or object would have a different colour, as we shall see later on).

glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
This line clears the buffers that we previously setup, we use this before we put any fresh data on the screen.
Think of it as flushing the page clean before we use it again !.

bglSwapBuffers

Lastly, this line swaps the display on our screen to that of our off-screen buffer.
(By using double buffers, we can draw on a hidden screen - while the previous screen is still showing. This cuts down on flickering, and can smooth out the overall program framerate.)

As you can see using Blitzmax with OpenGL, the whole process is quite painless.
Incase your wondering... if we where to have programmed the same little proggie in proper C++ with directx, it would be around 50 lines long !