World changes day by day!

Sunday, March 25, 2012

Develop front screen in OpenGL mini-project

24 comments
(Cross posted on OpenGL Projects)

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.

24 comments :

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

    ReplyDelete
  2. it says drawstring identifier not found

    ReplyDelete
  3. HEY! can i get an opengl project for butterfly?

    ReplyDelete
  4. SIR,
    i need to draw the front screen but it's showing an error as [linker error]undefined reference to drawstring , and how do i clear that error , Could u please help me sir

    ReplyDelete
    Replies
    1. Share the code to me then i can help you out post it on G+ or Fb or email me

      Delete
  5. my front screen iam getting it as white, iam not getting any text can please tell suggestion please its urgent.

    ReplyDelete
  6. yes sir i have used that function in timer() , iam getting white screen, after pressing enter its going to output image screen. why text not getting printing on that white screen??

    ReplyDelete
    Replies
    1. Send the code let me try it out or check if you using true push pop matrix and also flush as well as the other functions for display.

      Delete
  7. sir any modifications to be maid to that code sir?

    ReplyDelete
  8. sir pls tell me code for drawstring

    ReplyDelete
  9. sir can i have the option of changing the color of the water in aquarium project,
    i tried but getting error.,pls can u help.

    ReplyDelete
    Replies
    1. and if u get it send me the code to this id vasavibit128@gmail.com

      Delete
  10. I need to add few more screens like menu screen which contains help proceed and back option..how do i do that

    ReplyDelete
  11. sir,my front screen is not getting displayed,no text id displayed on the screen can you please suggest please its really very urgent.aftre enter key is pressed it goes to the output screen..

    ReplyDelete
  12. for any suggestion plz mail me at ikmaks@gmail.com

    ReplyDelete
  13. the above anonymous person is me..plz suggest for the above problem

    ReplyDelete
  14. i dunno why the HECK the people create this kind of sites :/ if they are not interested in replying to the posts.. or if the can't be connected to their sites regularly..

    ReplyDelete
  15. sir.. i hv implemented this code.. but i could only see the black screen as my output.. can please help me out...

    ReplyDelete

Leave Your comments