Search Projects

Sunday, March 25, 2012

How to add front screen in your OpenGL Project

In VTU lab for Computer Graphics, developing a mini-project is part of it. While developing CG mini-projects using OpenGL, there is need to present the project well. One must add front screen to the project which show the names of college, projects, guides and the project developers. It is good to have front screen as it provides introduction of the project.

There are many ways of adding front screen to the project. Here I explains, the basic way of adding front screen to the mini-project. Typically what looks in the picture below. Let's get started.

front screen in OpenGL mini-project



Simple keyboard interaction to start with

First set a variable, initialized it to zero.        
int flag=0;


Write a function called frontscreen, which contains all the details which you want to display.

void frontscreen(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0,0,1);
drawstring(20.0,90.0,0.0,"NAME OF THE COLLEGE ");
glColor3f(0.7,0,1);
drawstring(21,82,0.0,"DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING");
glColor3f(1,0.5,0);
drawstring(38,70,0.0,"A MINI PROJECT ON");
glColor3f(1,0,0);
drawstring(40,60,0.0,"PROJECT TITLE");
glColor3f(1,0.5,0);
drawstring(20,50,0.0,"BY:");
glColor3f(0.5,0,0.5);
drawstring(10,40,0.0,"NAME FIRST           (USN)");
drawstring(10,34,0.0,"NAME SECOND         (USN)");
glColor3f(1,0.5,0);
drawstring(68,50,0.0,"GUIDES:");
glColor3f(0.5,0.2,0.2);
drawstring(63,40,0.0,"GUIDE NAME FIRST");
drawstring(63,34,0.0,"GUIDE NAME SECOND");
glColor3f(1,0.1,1);
drawstring(32,10,0.0,"PRESS ENTER TO START");
glFlush();
}

Next is to write the code for the keyboard interaction which let user start the program. As in our case we have taken 'enter' key as our starting point. So when user press the 'enter' program leave the front page and start executing the main part of the project. Different keys may be assign for this job. Let's code a function called
myKeyboardFunc. This function will set flag value to 1  if the assigned key is press, thus making the way for displaying the main ideology of project.


void myKeyboardFunc( unsigned char key, int x, int y )

{
switch(key)
{
case 13:if(flag==0) //Ascii of 'enter' key is 13
flag=1;
break;
       }
    mydisplay();
}

The
mydisplay() function is called which will display the program execution on the screen. In this function we check the flag value and display according to that. If flag is not set to 1 (mean user has not pressed the key assign to start), front screen will display and if it set to 1 (mean user had started the program by pressing assigned key), the project will execute for what it is mean for. The code is simple as given below.

void mydisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
if(flag==0)
frontscreen ();
if(flag==1)
display();
}

The display() called above should contained and properly designed (coded) according to the requirement of the project. Functions need to be adjusted as one develop the project, so precaution must be taken and adjustment can be made to codes to make sure project work properly.

Note :  drawstring in above will display the strings so proper function need to be call for this. Also make sure  you must call 'glutDisplayFunc(mydisplay)' and 'glutKeyboardFunc(myKeyboardFunc)', in main function. Also do not confuse with display and mydisplay in main.

5 comments:

  1. i am getting error like drawstring is undeclared identifier...so what to do plzzzzz help

    ReplyDelete
  2. even i am getting the same error

    ReplyDelete
  3. As i mentioned in the end of the article you should write the code for drawstring. you have not written it, so probably the error will be there.

    I am posting the article for this so get the code from there ok!

    ReplyDelete
  4. you too try to get the code for drawstring and then error will not be there.

    ReplyDelete
  5. i am getting an error like
    error C2371: 'mydisplay' : redefinition; different basic types
    how to resolve it...

    ReplyDelete