Search Projects

Thursday, October 5, 2017

Doll - OpenGL programming using glut

Every Child likes doll, play with it. Every adult used to have as decor item in their collections. In this post we are going to draw a doll with OpenGL Programming using Glut. We will use the c/c++ and opengl glut to draw a beautiful doll.

1. Outline of the Doll

First we will outline how our doll should look like. We are going to draw a simple doll, hence we are not going to have complex attire for it. The doll will have head. without hair - simply bald.  It will have coat and pant as cloths and the black shoes. The coat will be simple with few button fully closed.

The doll should look straight forward. The eye would be more opened liked an egg and eyebrow to be cross not parallel nor it is curve. Colors are choice of programmers, hence if you want you can adjust with it as you want it to be.

OpenGL Programming using Glut

2. Draw Doll in OpenGL

As we finished outlining the doll, so we will go to coding part of it. In this OpenGL Programming using Glut, the shape of doll is code as head first, middle part and then legs.

Face/head is coded using the sphere (gluSphere(gluNewQuadric(),1,100,100);) and put egg like shape with dot on it for eyes. A big line will drawn with high thickness to have the eyebrow. Again same gluSphere(gluNewQuadric() is used for drawing the mouse but radius would be very small. Both left and right, eyes as well as eyebrow is coded separately. All object is drawn using transformation matrix.

The Middle part have neckring which is drawn by the use of glutSolidTorus.  Next is the coat and buttons. The belly coat is drawn by using gluCylinder(gluNewQuadric() and the transformation matrix. There is three button each a small sphere.

Bellycoatbottom is drawn using the gluDisk(gluNewQuadric(),0,.8,30,30);, yeah with matrix. Last is shoes which covered by gluSphere in footright and footleft functions.

3. Rendering

Before we go to the one of the main features let first define the global variable that will define initial camera position and viewing window values. Also it is important to define Initialization values for lighting.

We have defined a function which will render the object to make it look more realistic. It helps in enable depth testing, lightning - Ambient, Diffuse and Specular.

4. User Interaction

One of the important part of this OpenGL Programming using Glut is the user interaction. Here we have both keyboard as well as Mouse interactions. With the help of mouse doll can be move in either of directions. Keyboard interactions is listed below-

GLUT_KEY_UP - move one up scaling
GLUT_KEY_DOWN - move one down scaling
GLUT_KEY_RIGHT- move one step right
GLUT_KEY_LEFT- move one step left
GLUT_KEY_F10 - toggle whole screen
GLUT_KEY_F9 - toggle doll with interaction

5. Final Thought

We are able to draw a computer graphics doll with the help of OpenGL Programming using Glut in C/C++. This program have used the lighting and depth of material which is one of the feature of opengl to give a 3D touch to the objects.

Do download the source code and share your experience thoughts suggestions etc to us via comments. You can also contact us for any help or any other query use our contact form. Happy learning! Happy Coding!.

No comments:

Post a Comment