| |
|
 |
Building 3D worlds with OpenGL
|
The code
I use only two classes, MainWindow, which manages the menus and the timer used for rotation, and GameWidget, which does all the interesting stuff. GameWidget contains the three re-implemented QGLWidget functions, initializeGL(), resizeGL() and paintGL(). You should also take a look at the buildLandscape() function, this one does all the real work in my case.
initializeGL()
To be short: I declare a position array for the light source, and a nice red color. Then lighting is enabled, and a few states regarding lighting are set, and finally I build a display list. This is a list of OpenGL instructions, that are saved so I can call them later without doing all the heavy calculations in the buildLandscape() function once more.
void GameWidget::initializeGL()
{
// lighting settings
static GLfloat pos[4] = { 5.0, 5.0, 5.0, 1.0 };
glLightfv( GL_LIGHT0, GL_POSITION, pos );
glEnable( GL_CULL_FACE );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_DEPTH_TEST );
static GLfloat ared[4] = { 0.8, 0.1, 0.0, 1.0 };
Landscape = glGenLists(1); // start building a display list
glNewList( Landscape, GL_COMPILE );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared );
buildLandscape();
glEndList(); // done with display list
glEnable( GL_NORMALIZE );
}
|
Comment List
| Topic: |
Author: |
Time: |
|
Beginner's tutorials
|
Johann Fuchs
|
13.02.2001 17:04
|
|
if you want to learn opengl programming from the scratch
to high level you should look at
http://nehe.gamedev.net
which is quite an excellent site IMHO.
|
|
 |
|
|