Search Projects

Tuesday, October 2, 2012

Another Font sheet program in OpenGL


The whole bunch of program here given below which deals with displaying the Font in OpenGL. Try this out and have problem post that in comment. Add something to it, that too post this here. Discuss, how to improve this program.


#include <stdio.h>
#include <string.h>
#include <math.h>

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glut.h>

typedef enum {
   MODE_BITMAP,
   MODE_STROKE
} mode_type;

static mode_type mode;
static int font_index;

void
print_bitmap_string(void* font, char* s)
{
   if (s && strlen(s)) {
      while (*s) {
         glutBitmapCharacter(font, *s);
         s++;
      }
   }
}

void
print_stroke_string(void* font, char* s)
{
   if (s && strlen(s)) {
      while (*s) {
         glutStrokeCharacter(font, *s);
         s++;
      }
   }
}
void
my_init()
{
   mode = MODE_BITMAP;
   font_index = 0;
}

void
my_reshape(int w, int h)
{
   GLdouble size;
   GLdouble aspect;

   /* Use the whole window. */
   glViewport(0, 0, w, h);

   /* We are going to do some 2-D orthographic drawing. */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   size = (GLdouble)((w >= h) ? w : h) / 2.0;
   if (w <= h) {
      aspect = (GLdouble)h/(GLdouble)w;
      glOrtho(-size, size, -size*aspect, size*aspect, -100000.0, 100000.0);
   }
   else {
      aspect = (GLdouble)w/(GLdouble)h;
      glOrtho(-size*aspect, size*aspect, -size, size, -100000.0, 100000.0);
   }

   /* Make the world and window coordinates coincide so that 1.0 in */
   /* model space equals one pixel in window space.                 */
   glScaled(aspect, aspect, 1.0);

   /* Now determine where to draw things. */
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

}

void
my_handle_key(GLubyte key, GLint x, GLint y)
{
   switch (key) {

   case 27:    /* Esc - Quits the program. */
      printf("done.\n");
      exit(1);
      break;

   case ' ':    /* Space - toggles mode.     */
      mode = (mode == MODE_BITMAP) ? MODE_STROKE : MODE_BITMAP;
      font_index = 0;
      glutPostRedisplay();
      break;

   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
      if (mode == MODE_BITMAP || key == '1' || key == '2') {
        font_index = key - '1';
      }
      glutPostRedisplay();
      break;

   default:
      break;
   }
}

void
draw_stuff()
{
   char string[8][256];
   unsigned int i, j;
   unsigned int count;
   void* bitmap_fonts[7] = {
      GLUT_BITMAP_9_BY_15,
      GLUT_BITMAP_8_BY_13,
      GLUT_BITMAP_TIMES_ROMAN_10,
      GLUT_BITMAP_TIMES_ROMAN_24,
      GLUT_BITMAP_HELVETICA_10,
      GLUT_BITMAP_HELVETICA_12,
      GLUT_BITMAP_HELVETICA_18  
   };

   char* bitmap_font_names[7] = {
      "GLUT_BITMAP_9_BY_15",
      "GLUT_BITMAP_8_BY_13",
      "GLUT_BITMAP_TIMES_ROMAN_10",
      "GLUT_BITMAP_TIMES_ROMAN_24",
      "GLUT_BITMAP_HELVETICA_10",
      "GLUT_BITMAP_HELVETICA_12",
      "GLUT_BITMAP_HELVETICA_18"  
   };

   void* stroke_fonts[2] = {
      GLUT_STROKE_ROMAN,
      GLUT_STROKE_MONO_ROMAN
   };

   void* stroke_font_names[2] = {
      "GLUT_STROKE_ROMAN",
      "GLUT_STROKE_MONO_ROMAN"
   };

   GLfloat x, y, ystep, yild, stroke_scale;

   /* Set up some strings with the characters to draw. */
   count = 0;
   for (i=1; i < 32; i++) { /* Skip zero - it's the null terminator! */
      string[0][count] = i;
      count++;
   }
   string[0][count] = '\0';

   count = 0;
   for (i=32; i < 64; i++) {
      string[1][count] = i;
      count++;
   }
   string[1][count] = '\0';

   count = 0;
   for (i=64; i < 96; i++) {
      string[2][count] = i;
      count++;
   }
   string[2][count] = '\0';

   count = 0;
   for (i=96; i < 128; i++) {
      string[3][count] = i;
      count++;
   }
   string[3][count] = '\0';

   count = 0;
   for (i=128; i < 160; i++) {
      string[4][count] = i;
      count++;
   }
   string[4][count] = '\0';

   count = 0;
   for (i=160; i < 192; i++) {
      string[5][count] = i;
      count++;
   }
   string[5][count] = '\0';

   count = 0;
   for (i=192; i < 224; i++) {
      string[6][count] = i;
      count++;
   }
   string[6][count] = '\0';

   count = 0;
   for (i=224; i < 256; i++) {
      string[7][count] = i;
      count++;
   }
   string[7][count] = '\0';


   /* Draw the strings, according to the current mode and font. */
   glColor4f(0.0, 1.0, 0.0, 0.0);
   x = -225.0;
   y = 70.0;
   ystep  = 100.0;
   yild   = 20.0;
   if (mode == MODE_BITMAP) {
      glRasterPos2f(-150, y+1.25*yild);
      print_bitmap_string(
         bitmap_fonts[font_index], bitmap_font_names[font_index]);
      for (j=0; j<7; j++) {
         glRasterPos2f(x, y);
         print_bitmap_string(bitmap_fonts[font_index], string[j]);
         y -= yild;
      }
   }
   else {
      stroke_scale = 0.1f;
      glMatrixMode(GL_MODELVIEW);
      glPushMatrix(); {
         glTranslatef(x, y+1.25*yild, 0.0);
         glScalef(stroke_scale, stroke_scale, stroke_scale);
         print_stroke_string(
            stroke_fonts[font_index], stroke_font_names[font_index]);
      } glPopMatrix();
      glPushMatrix(); {
         glTranslatef(x, y, 0.0);
         for (j=0; j<4; j++) {
            glPushMatrix(); {
               glScalef(stroke_scale, stroke_scale, stroke_scale);
               print_stroke_string(stroke_fonts[font_index], string[j]);
            } glPopMatrix();
            glTranslatef(0.0, -yild, 0.0);
         }
         glTranslatef(0.0, -ystep, 0.0);
      } glPopMatrix();
   }
}

void
my_display(void)
{

   /* Clear the window. */
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glClear(GL_COLOR_BUFFER_BIT);

   draw_stuff();

   glutSwapBuffers();
}

int
main(int argc, char **argv)
{

   glutInitWindowSize(500, 250);
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);

   glutCreateWindow("GLUT fonts");

   my_init();

   glutDisplayFunc(my_display);
   glutReshapeFunc(my_reshape);
   glutKeyboardFunc(my_handle_key);

   glutMainLoop();

   return 0;
}

Friday, August 31, 2012

Tic Tac Toe : Cross Zero Game


Abstract : Tic Tac Toe is one of the simple game, which is also called as noughts and crosses but in our local terms we called it as cross-zero game. Other may say differently this game but things are same. It is a pencil-and-paper game for two players, where player select X and O, as their playing item. It is played on the grid of 3×3. The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal row wins the game.

Description : The grid is structured mapping the objects in the array while each have some value to them. Next is the X and O which are simply made by using cylinders and tours. Then mouse variables, Win = windows size, mouse = mouse position  are defined to keep record of click on the grid. Now time is to declare the players to keep track them, player and com is given a value which determine them. The win and start game is given a value so to keep who wins the game and where to start from with considering tie as another option. 
Logic was made as Computer seek the spaces and determine where to keep the next move. Computer move is what made the logic how it play the move on the board by check at the corner and in the middle space.

User interactions :
 First time Computer is given a move show use can either follow it or right click to choose whether to play as X or with O.
Press V to toggle between the ortho to perspective views.

Saturday, August 4, 2012

How to display Timer in OpenGL Projects

This tutorial will demonstrate how to have timer in the project of computer graphics using OpenGL. Follow the simple steps and get you timer in the projects.

To have timer in the program, OpenGL had provide a library function. This library function is "glutTimerFunc" which need to be called to have the timer displayed. So to have this function work we will define and declare a function called myTimer, whose code is like-

void myTimer(int value) {

if(j==0)
{
g_counter = value + 1;
}
else if(j==1)
{
g_counter = value + 0;
}
else
{
g_counter = 0;
}
glutPostRedisplay();
glutTimerFunc(GAP, myTimer, g_counter);
}

You must have g_counter variable declared before you define this function like this. The g_counter, must be declared as a static variable. So you use it like static int g_counter = 0; where it has been initialized to 0 at first to start from 0, if you wish you can set the other time. Also have another variable J, this too must be static go as static int j=0; also initialized to 0.
There are three if else statements, first it check whether the timer is at initial position if it is, then value of   g_counter would be incremented by 1. Further second if, check that timer has been paused as value of j changes to 1, then no increment in g_counter  and last one rest the g_counter value to 0.



glutTimerFunc take three parameter of which first is the value in millisecond here it determines to have per second value. Second his the function called to process the timer, third and the last the value that determine the timer's value.

Now we will desgin a keyboard function that will cause the timer to start, stop and reset. The code for that is below -


void myKey(unsigned char k, int x, int y)
{
switch (k) {
case 's': if(j==0)j=1; else j=0; break;
case 'r': j=2; break;
case 'q':
exit(0);
break;
}
}

From the code most of the things is clear. As User press the 's' key the timer will stop first and if 's' was pressed again, the timer start from where it stopped. The logic is simple, first time when key 's' is pressed the value of j changes to 1 and it changes to 0 when press again, the  value of j is checked in myTimer function and g_counter is incremented accordingly. The  'r' is used to reset the value of the timer to 0, while 'q' will quit the program.

Download the simple timer program from here.

Thursday, July 12, 2012

3D Line Shaped Objects

This project illustrates the simple line drawing of different 3D objects including - Sphere, Cube, Cone, Torus, Icosahedron and Teapot. They drawn in the wired framed with black lines. They looks like a movie of black and white pictures. That cool!. The object are automatically set in motion as they appear on the screen.

While to add user interaction an mouse function is being added, this mouse function allow users to choose which of the object they want to select and display it on screen. There is transparency between one surface of the object to other, which means that one can see both the surface at a time while the object rotate in motion. This is simple project, most of the things here are given to learn how to draw those shapes. To How to draw the line shapes of 3D object,check out this project who codes is given below.
If you like you can add more things to it like adding lighting, textures etc. to the objects. Also you can add the motion controller function that is - function that allow user to move the object with mouse or using the any of the key in keyboard.

Saturday, June 30, 2012

Mini Project on Bellman-Ford algorithm using OpenGL


Descriptions : The Bellman-Ford algorithm also known as Ford-Fulkerson algorithm is based on the principle that is intuitively easy to understand. Each node A knows the shortest path to node Z, then node A can determine its shortest path to Z by calculating the minimum cost.
Each node connected to another node with a cost, now when the packet flows through a path it result some cost to the network . To minimize the cost of network communication Bellman-Ford algorithm is implemented and the packet flow to the path which costs less in the communication. 

Working Principle
       
               First  we draw the nodes and connecting lines by passing co-ordinate values to a GL_LINES .It will draw the network and connections of the network. The shortest path is calculated by using Bellman-Ford algorithm using the following formula-
1.Initialization
                                             Di=∞; for all i≠ d                                 (3.1)
                                             Dd=0                                                     (3.2)
            2.Updation
                                             Di=minj{Cij+Dj}                                              (3.3)
Repeat step 2 until no more change occur in iteration.

To draw the packet we pass the co-ordinate values to the GL_QUAD. Now to move the packet from one node to another node we draw the packet at different points of co-ordinate using for loop. The loop will make the polygon in the certain color specified from the starting co-ordinate to the end with the incremented value. Now we cover the part of the long polygon which is generated in the loop using the same co-ordinate values and loop coloring with black. The black color cover the previous color and this makes the sense for the movement of the packet. Similar thing is done for all the packet movement

Usages : 
Mouse interaction : Click on the node to choose the node from where the shortest distance is to be measured. Click on quit block to exit the program.
Key board : The program will ask after every node select, showing the shortest path if you wan to continue or not press y to continue press n to exit the program.

Download : Project Code

Friday, June 22, 2012

OpenGL mini project on Traffic signal

Descriptions : As we know, the traffic signals direct the flow of traffic with the exemption of signals with turning arrows which should be compulsory in accord with each other.Traffic signals helps us to drive our vehicles in a safer manner lowering the risk of accidents, if properly followed.

In this Project simulation, we are implementing  Traffic Signal. We have three lights in the signal Red , Green and Orange. Each light have some meaning . Red means stop , Green means go, Orange means ready to go.
Same method we implemented in our project which used in real life .We have used this traffic signal in a cross road to avoid misshapening. When there is green signal it means vehicle can move or run on the road but if this green signal turnoff  and the red signal is turn on then its indicate the driver to stop his vehicle and same time signal allows some other side vehicle to cross the road. But if the vehicle is in the middle of cross or vehicle have cross the signal then there is no meaning of red light for the driver. When we press button R then red light will glow and all vehicles are stop n when we press Y button then  yellow light will glow and all vehicles ready to go .When  we press button G  green light will glow and then vehicle start  moving.  

In this project we have written a loadBMP function to load bitmap images. Bitmaps take up a lot of space compared to image formats, like .PNG, but I chose to use bitmaps because they are relatively easy to load into format that we need. Take a look at imageloader.h. This gives us the basic idea of what loadBMP does. (The actual code for loadBMP is in imageloader.cpp.) Given a filename, it returns an Image object, which contains the width and height of the image, as well as the array pixels, which stores the pixels' colors in the format we want. 


Usages : As mentioned above.

Download : Project code
                    road image
                    image loader.cpp
                    image loader.h

Saturday, May 12, 2012

Interactive font program for OpenGL

In previous post  there was simple demo how to display different Font style. Now in this Project, an interactive Program will be shown which have user interaction to play with.This program allow user to choose different sets of things related to font display, more can be added.  Different Fonts style declared, which can be selected by right click. 

Right click and there will be options for different Fonts type like of Times Roman and Helvetica, with size value.  Also bitmap fonts being added. To give color to fonts, selection options are given to select the color,  red, blue, green and white. Lastly a message option is there to select which message to display on the screen. There is two options added in this program - abc that denotes the small caps letters while,  ABC meant for Message to be in Capital letters. Further addition is possible by adding more menus and messages in the program.




Monday, May 7, 2012

Minesweeper Game in Computer graphics

Minesweeper is a logical game which we might have seen in every version of windows. Here  it has been developed on openGL platform. Minesweeper is a single-player game. The objective of the game is to clear, an abstract minefield without detonating a mine.




Playing Strategy  

First of all make the random selection of one of its boxes. If we are in safe zone (i.e avoided any mines),then move further. we can get the clue by looking adjacent to uncovered box about probable mines location. we also get an idea about exact number of mines in adjacent to the boxes by looking at the numbers in uncovered adjacent boxes. If we get an empty uncovered box then there are no mines around that particular box.

There can be maximum of eight mines around the box. Based on the numbers of uncovered boxes we assess of being mines and to avoid it. It is somewhat uncertain about presence of mine based upon the uncovered boxes at that moment we make an random selection once again. If we press the all right location not consisting of mines then the player will win the game . If we press at the wrong location consisting of mines then the player loses the game.

CONCLUSION


  • We got satisfaction problem and explores the application of constraint propagation technique to interactively determine safe and mined squares. 
  • Understand and demystify human fascination with puzzles. 

Future scope


  • It will help students to gain cognitive asset of “making inferences and hypothetical thinking.
  • It is also being developed on  3D platform for more interactivness.

Video Demo

Source Code

Tuesday, May 1, 2012

Escapa, a brainy game with fun



Description : Escapa is a lot of fun, but as a brain training tool it is limited. Each game trains a different skill such as concentration, maths ability, or short-term memory. Playing these games a few minutes per day helps your brain grow stronger.
In this project a simple game is made, with black wall in the corners cover the area. In that area, some obstacle are placed which are blocks in blue colours. There is red colour block which moves and have to control by the player. The objective of the game is to move the red block around without getting hit by the blue blocks or touching the black walls. If you can go longer than 18 seconds, you are phenomenal.





Monday, April 30, 2012

The Taj Mahal



Description:  No need description of this project as previously in the tutorial to build mini project on Taj Mahal most of the things were told. Let's remind few things like the Taj Mahal project is based on keeping cubes and spheres in place to build the gumbazz and the minars. Here two forms are made with one for outer and other the wire farmed, for inner one, with the tombs inside it.

Usages: 

Mouse interaction :  Right click to see the options
                                Taj : To see the outer Taj with full-spaced walled building.
                                Wired Taj : Wired Taj, with tomb inside which is made visible.
                                Exit : Quit program
Keyboard interaction: 
                                 w : Increase animation for Wired Taj
                                 e :  Decrease animation for Taj
                                 r :  Decrease animation for Wired Taj
                                 t :  Increase animation for Taj


Project Code:

Sunday, April 29, 2012

Shadowfun : Program to make fun with shadow of different objects





Description:  
This program demonstrates a light source and object of arbitrary geometry 
casing a shadow on arbitrary geometry.  The program uses OpenGL's feedback, stencil, and boundary tessellation support.

In other word it poses shadow of the different objects selected over the walls. There are two views in which one is normal say our eyes and other the object's eye. It look cool when you choose the object eye to view. Keeping the lights on/off make the things more delicate. There are many other things that is included in this with vast amount of understanding to implement those.

Usages:  Right click to see the options

Object shape : Selects the below objects with sub-menu selection
                           Torus
                           Cube
                           Sphere
                           Icosahedron
                           Double Torus
  Viewpoint :
                           Normal view : Normal Display
                           Light source view : Display as from the eyes of the objects (light source).
  Render mode :

                             With shadow : Shadow view on/off
                             With front shadow volume : Only Front shadow
                             With back shadow volume : Only Back shadow
                              Without shadow : No shadow
                              Without light : Light on/off
                              2D shadow boundary :  2d shadow boundaries.
  Action :
                  Spin object : Spin the objects.
                  Swing light : Swing the lights.
                  Stop : Stop
  Step rotate : increment the steps of movement.
  Quit : Exit Program.

Download : Project code


Those who want to works it on the Linux or Unix can compiles the code as below :

cc -o shadowfun shadowfun.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm 

make sure you have OpenGl libray in the file system, if not get installed it.

Saturday, April 28, 2012

Fluid Filtration : a demo working of filtration of fluids


Description:  As name suggest this project will demo the filtration process of water or the other fluids. In this project a simple box which is the container is made with handle on the side. The simple line diagram is used to make the container box, for which appropriate functions is used. It is similar like drawing any polygons, the normals and vertices are precisely designed to make the accurate cuboidal box. Similarly with other polygon the filters is designed.
The animation of the fluid is designed with controlling the drawing of polygon mainly rectangular with proper vertices and normals, this is used within the loop. Also apart from animation of fluids in the pipes, the project adds additional controls to move the whole things - container and the fluids within the pipes along an axis with mouse.

Usages: Hold the mouse button to move the  container and the fluids within the pipes. As You leave the mouse the movements will stop. To move in forward hold left mouse button and fro backward hold right mouse button.

Download : Project code*

*There is some bug in the program so sometime it might not works like left and right mouse button didn't work or it will shows no respond .

Friday, April 27, 2012

Rigid Body Transformation : A project demonstrate Rotation, Scaling, Transformation



Description:  Rigid Body Transformations is one of  the most important applications in computer graphics.  It means Rotation, Scaling, Transformation of 3-Dimensional objects, like teapot, torus, cone, cube and octahedron. It also includes changes of background colors and rotations, including the 3 ways, like of  x-axis, y-axis and z-axis.The above operation can be done by using mouse interface.

A part from this a small header section is there at the top, which contains informations, like project name with it associates. The angle and velocity of rotation, is indicated on the header bar. A timer is also placed on header, which shows the times elapse as the program executed.


Usages:  Right click to see the options


 Rotation On : Set the rotation in the object.               
 Translation :
                         X - axis Translation On : Move objects in x-direction.
                         Y - axis Translation On : Move objects in y-direction.
                         Z - axis Translation On : Move objects in z-direction.
 Objects : Selects the below mentioned objects with sub-menu selection

                           Teapot
                          Cone
                          Cube
                          Torus
                         Octahedran
 Change Background :  Selects the colours mentioned below with sub-menu selection

                       Red 
                       Blue
                       Green 
                       Black
 Scaling On:  Put the scaling on objects.

Download : Project code

Thursday, April 26, 2012

Glutplane : Draw Planes with computer graphics in OpenGL

glutplane

Description:  There are many things we can play with paper. In our childhood we used to make things like ships, planes, frogs, birds etc. with the paper. That was just only child's play but still have creativity in it. There are complex things that can be made with paper. There are many branches of this, in which people use their creative mind to make things with papers like paper cutting or origami.

The projects on simple paper folding was demonstrated earlier, along with the video for the origami project. Now introducing the another paper creative work, with computer graphics. With figure you would have easily get that the project deals with making the planes. Simple figure planes are created in different types of colours. The projects allows to add more planes and also to remove them from the screen. It also allow to see static planes or watch them flying on the screen.

Basic Trigonometric functions has been used to bend the shape to make it look like plane. Also to have diffrent colours at the time of adding the planes, random function is used to select the colours randomly.  This same function is utilized for animation of the planes in different speed and directions. While for more glutVisibilityFunc is used for static or animation turns.

Usages: Right Click to see the options


Add plane : Add new plane from the screen in random colours.
Remove plane : Remove already present plane from the screen.
Motion : To keep the animation or movement on/off.
Quit : Exit program

Project Code: Download

Wednesday, April 25, 2012

Create Multiple instances of Stars


Description : Program to demonstrate the use of display lists: loads a shape using display lists then calls several instances. Also demonstrates the use of glutIdleFunc to animate the shapes.
 This program uses display lists to create multiple instances of a single object. The object used here is Star. Stars are created using the polygons with different points, which can be alerted.  The multiple instances of stars are called with the number of stars which too can be changed.

usages :
Mouse interaction

Right mouse button: Speed up the animation.
Middle mouse button: Slow down the animation.
Left mouse button: Reset to the default speed.

Keyboard interaction 


r: Speed up the animation.
t: Slow down the animation.
y: Reset to the default speed.
q: quit program.

Video demo


Download : Project code*

* If you have edited something, modified the program discuss about.

Saturday, April 21, 2012

Dynamic Sorting Algorithm Visualizer : Computer Graphics Project


Sorting can be defined as arranging list, number, or any times in an systematic way in a certain order of sequence having comparable properties. In simple word Sorting  is the process to rearrange the items of a given list in Ascending Order/Descending Order.

Previously in our Computer Graphics Project blog we have discussed about Bucket sort program a sorting program. In that Computer Graphics Project program the user uses to provide two input array to store and show the sorting process and result, while in this project the sorting is show dynamically with Circles representing the input list to sort. 


Description: The underlying concept of sorting algorithm includes the comparisons, swapping of elements, and assignments. The DSAV ( Dynamic Sorting Algorithm Visualizer ),  Visualizes the Bubble Sort Algorithm. In this algorithm, comparisons starts from the first two elements of the array and finding the largest item and move (or bubble) it to the top. With each subsequent iteration, find the next largest item and bubble it up towards the top of the array. 

This DSA Visualizer depicts the swapping of elements by swapping the circles (which are the items of the array in our case), for each item different radii of circle is generated according to the value of the item. This swapping process occurs for at the max of n iterations. Thus at the end of nth iteration,  the array of elements are sorted in the ascending order which is the desired output of the DSAV. Below is the logic or say short algorithm of  the Dynamic Sorting Algorithm Visualizer Computer Graphics Project.

Logic of sorting :
If not in the process of swapping of 2 circles then only get 2 new circles to swap.
While the counter_i < 10
While counter_j <9
If the a[counter_j] > a[counter_j]
Swap 2 circles
Once exchanged goto swap
Increment counter_j
                   Increment counter_i
            Swap:
             Print which circles are getting swapped.
            Call swap_circles function again with counter_j and counter_j+1 values.
            Mark the end of the function sort.


Usages: First the window generate will ask 'press enter to continue.....' ; press enter key
Menu is written with what to do on the screen it self.

Following is what keyboard will do after it get pressed - 

s  :      To start sorting
r :       To randomizes the sorted list
esc :   Exit

Project Code and Report for the program :

Video Demo

Wednesday, April 18, 2012

Build Taj Mahal mini projects in OpenGL, Computer Graphics

Taj Mahal (ताज महल), is the symbol of love. It  is a white Marble mausoleum located in Agra, INDIA. It was built by Mughal emperor Shah Jahan in memory of his third wife, Mumtaz Mahal. For more info read wikipedia.

Here, we are going to develop basic structure of Taj Mahal in computer graphics. In this tutorial I will tell how to make Taj like structure using the OpenGL. We will develop simple structure, not exactly same as it looks in real but some what idealistic. This project is mainly mean for the VTU Computer Graphics mini-projects.




Taj Mahal is basically a structure with many minars and gumbazz. We will use the simple objects like spheres and cubes to build these units. First for the main part we use box or a large cube and then point small sphere over them. Thereafter, we place a small cubical structure with very low height, a egg like sphere is also placed over it. Similarly,we going to place four long minars over each four corners.

We are also developing the wired framed structure of the Taj as well. In the wired framed Taj, the large cube block will go transparent and the two tombs will be place in the middle with small cubes.

Lets start coding!



/* Draw the bottom box */
glPushMatrix();
glScaled(0.8,0.04,0.8);
glTranslatef(0.0,-30.2,0.0);
glutSolidCube(7.0);
glPopMatrix();

    //main cube
    glTranslatef(0.0,-.6,0.0);
glutSolidCube(2.0);

//main gumbazz
glPushMatrix();
glScaled(0.8,1.0,0.8);
glTranslatef(0.0,1.5,0.0);
glutSolidSphere(0.8,80,120);
glPopMatrix();

glTranslatef(0.0,1.0,0.0);
glScaled(1.2,0.25,1.2);
glutSolidCube(0.9);

//gumbaz pointer

glPushMatrix();
glScaled(0.03,0.5,0.03);
glTranslatef(0.0,10.8,0.0);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//Minars
glPushMatrix();
glTranslated(2,-1.9,2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//minar's sphere
glPushMatrix();
glTranslated(2,0.8,2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//Minars
glPushMatrix();
glTranslated(-2,-1.9,2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//minar's sphere
glPushMatrix();
glTranslated(-2,0.8,2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();


//Minars
glPushMatrix();
glTranslated(-2,-1.9,-2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//minar's sphere
glPushMatrix();
glTranslated(-2,0.8,-2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//Minars
glPushMatrix();
glTranslated(2,-1.9,-2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();
 
//minar's sphere
glPushMatrix();
glTranslated(2,0.8,-2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//short Minars
glPushMatrix();
glTranslated(0.6,-0.5,0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();

//short minar's sphere
glPushMatrix();
glTranslated(0.6,0.5,0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//short Minars
glPushMatrix();
glTranslated(0.6,-0.5,-0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();

//short minar's sphere
glPushMatrix();
glTranslated(0.6,0.5,-0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//short Minars
glPushMatrix();
glTranslated(-0.6,-0.5,-0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();

//short minar's sphere
glPushMatrix();
glTranslated(-0.6,0.5,-0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();

//short Minars
glPushMatrix();
glTranslated(-0.6,-0.5,0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();

//short minar's sphere
glPushMatrix();
glTranslated(-0.6,0.5,0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();



Project Docs : 

Saturday, April 14, 2012

Tutorial How to display strings in OpenGL mini projects

In the previous post, which highlights on making a front screen for the OpenGL mini projects a function called drawstring was shown but didn't explained well as it was assumed to be understood easily by the students but few of them demand it's code, which was not there. To help them out and sort the error they have,  here I made a simple tutorial to show, how we can display a string in the projects.

To display strings in the project we can make function in different ways, call the defined front in OpenGL API. How to code is depend on the coder, what he want to do with the string and how he want to display it. Matter of fact is that the necessary things is to make sure once a function is made it must be flexible enough that Front sizes and the colours can be changed easily when ever needed, wherever needed. Keeping in the mind that A simple function is code, of which stepwise process is defined below. You can also see the different fonts demo.



First declared  a indentifire that will hold the current font type -

void *currentfont;

After the declaration of this, we define a function which will change the fonts or say set the font which we can to to display with the strings. Code for this is easy, just make a function called setFont(), code given below -


void setFont(void *font)
{
currentfont=font;                      // Set the currentfont to the font
}


Sunday, April 1, 2012

A mini project on Clock using OpenGL





Description: The Project is idea to display the clock with computer graphics.  This project just used the local time, fetching from the computer and display it on screen. This project  implements the wall clock with the round circular board and three conic geometrics which forms the different (sec, min & hour) hands. Small cubes are also made for the minutes, while each hour is represented with a large block. Digit display of the clock timing is also placed at the bottom.
The 'localtime(&ltime)'  function is used to get the local time. With proper maths and conversion of the time for sec, min and hours the graphical hands are made to make movement. This project made two views one ortho and other perspective.

Usages: Right click for the options
                     About the Project : Display information about the project
                     Toggle Ortho/Perspective view : Switch between the Ortho and Perspective views.
                     Light on/off : For light on clock and off it.
                      Quit : Exit program.

Project Code: Download