Monday, November 21, 2011

Draw a 3D Chess Board using OpenGL utility toolkits (GLUT), a graphics project with source code

This program  may help you in graphics project of your college.I simply  tries to draw the 3D Chess Board.  For this our main goal is to draw white and black rectangular box alternately along both x and y-axis.Drawing rectangular box is simple ,it is drawn by providing all side co-ordinates with the help of glVertex3f function and only top face is assign with black or white color and other face with brown color with the help of glColor3f function. I have made two function void draw_BlackArea() and void draw_whiteArea() to draw black and white square box respectively .Inside two for loop I have call these function by creating displaylist and with the help of glTranslatef(GLfloat x,GLfloat y,GLfloat z) function I draw  alternatively by translating their position.

Tuesday, November 15, 2011

Draw Reflection of Object on the floor using OpenGL Utility Toolkit (GLUT)

Drawing reflection capture the extra realism of the Object in 3D programming.For example Bouncing ball having its reflection on the floor can make the bouncing scenario more beautiful and realistic. So,OpenGL has all the features needed to render fast high-quality reflections on planar surfaces.
        Reflection technique is not so hard its pretty simple.If you want to draw reflection on floor then suppose your floor is in x-z plane and your object along positive y-axis above the plane then for reflection of object draw the copy of object along the negative y-axis vertically below the plane or floor.Your floor must look like the reflecting surface to see the object which is below the floor for this we use alpha blending which make the floor transparent by certain percent say 40% then it is specified to be 40% the color of the floor and 60% the color of the reflection or object.But only alpha blending doesn’t make the reflection real because the reflected copy of the object may leak outside or bottom of the floor so to fixed this problem we actually going to use the stencil buffer concept.With OpenGL stenciling, we can "pre-draw" the floor into the stencil buffer without updating the color or depth buffers. Then when we go to draw the reflection,  just only allow the reflection to update pixels marked as belonging to the floor's stencil value. The floor can then be any complex (but coplanar) polygon and the reflection only shows up in the floor.

Drawing a Bitmapped Character or string in OpenGL sample example

A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window. Suppose you're drawing a bitmap and that the current raster color is red. Wherever there's a 1 in the bitmap, the corresponding pixel is replaced by a red pixel and If there's a 0 in the bitmap, the contents of thepixel are unaffected. The most common use of bitmaps is for drawing characters on the screen.
            In the simple example we use two main function glBitmap and glRasterPos2i function.
The glBitmap function draws a bitmap.

Saturday, November 12, 2011

Rotate an Object in OpenGL(GLUT) sample example with source

In GLUT we rotate the object by glRotate3f(angle_rotation,GLfloat x, GLfloat y ,GLfloat z) function angle_rotation parameter is value of angle to rotate and x,y,z co-ordinate are axis of rotation.But it does not rotate object continuously for that we have to change angle of rotation by small amount of increment. We do this by using timer thread with the help of glutTimerFunc function.Here is the sample source code copy and compile it.

Friday, November 11, 2011

How to change the color of object in OpenGL(GLUT) using keyboard function

If you have problem in changing color of object in OpenGL using keyboard while running program then this article may help you.Simply we can’t change the color of object while running for this we have to create a timer thread by using
Void  glutTimerFunc(unsigned int msecs,void (*func(int value),value)  function or other techinque can also be use.
Parameter:
msecs

Number of milliseconds to pass before calling the callback.

func

The timer callback function.

value

Integer value to pass to the timer callback.