Assignment 2: Night Life in NTU

 

Introduction

This assignment involves rendering a NTU night scene and providing simple navigation. The rendering is done in OpenGL using Visual C++ as the compiler for the program. The scene chosen for rendering in this case is the portion of the side view of a walkway shelter in NTU.

Theory

The actual scene has many different shaped objects. In order to render the image in OpenGL, polygons are used to create the objects. Texture and lighmapping is used to make the rendered image look realistic. Cylinders is used to render the pillars of the shelter while rectangles are used to render the road and shelter. Rectangle and loops are used to render the black and white road edge, which repeats along the road. The monitor is a flat screen, thus perspective is used to make images look 3D.

The window of program is created as a 500*600 window with the top left hand corner at (100, 100). The initialization functions are placed in init() function while the display() function contains all the calls to individual functions that drew parts of the scenes. Light sources and  viewport are initialized so that objects may be seen. The gluLookAt() function serve as a camera to present views of the scene from different angels. glEnable() is used to enable the lighting and 2D texture.

In the program, the polygons are created using glVertex3f(GLfloat x, GLfloat y, GLfoat z). glBegin() and glEnd() are used to ensure that the vertices are linked together. gluCylinder is used to create cylinder shapes and translation (glTranslatef()) and rotation (glRotationf()) are used to get the cylinders into the right position. glPushMatrix and glPopMatrix are used to save and restore the viewing transformation so that there is no need to do a reverse transformation after drawing objects at their desired positions. 

The color of the objects and background are set by glColor3f(GLf;oat, GLfloat, GLfloat). The background of the program is set to black (0, 0, 0, 0). Textures and lightmaps are loaded from bitmap files and mapped to the objects.  Lightmaps and textures are mapped to some objects to make them look realistic. Loops are used to create lights sources under the shelter at regular intervals. glEnable(GL_TEXTURE_2D), glTexCoord2f(0.0f, 0.0f) and glBindTexture(GL_TEXTURE_2D, texture[0]) are used to map the lightmap and texture to the polygons.

Navigation of the scene may be done by moving the camera (gluLookAt() function). The scene is rendered based on 1 view. Then using the gluLookAt() function, other views are createdThough its not the actual camera, but it makes the scene look as though its moving. This is actually created by the re-rendering of the scene.

Program

The program may be downloaded here. (Please right click and click select save target as). The texture, source files and ReadMe.txt are included in the zip file. Due to the time contraints, the numerous errors that i faced and most importantly, my own inability, the navigation part of the program is incomplete and thus not included to the zip file.

Conclusion

The 3D scenes may be created in 2D planes. Lightmapping and texture mapping add to realism of the images. A simple 3D scenes need much work and time  to make the scenes look realistic and navigate properly. Texture and lightmapping are applied in similar ways. Lastly but not least, due to my inability to get the navigation to work, I conclude that an A effort on rendering scenes results in a F program.

Download

The zipped file is available here. (Please right click and click select save target as).

References

OpenGL Sper Bible

http://www.gamenet.dev

http://www.dev-gallery.com/programming/opengl/book/b_index.htm

 

Last Updated on 17th August 2003

Done By: Ong Kian Wee Christina

********Increase your success by lowering your expectations*********

1