Jump to content
  • Advertisement
Sign in to follow this  
jahan

OpenGL help with print function

This topic is 5471 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hI, I M KINDA NEW with opengL and i was wondering if i could get around a printing problem. I know this forum has a nice print method and mine is similar to that one... I was wondering where i have to write a print statement that would make the winner print out on screen. i know display function does that but then i need a way to check if the winner button was clicked. I am confused as to what to do. Can someone look at the code please and give me any clue? I would be gr8 ful. I have put comment on the winner part of the code so u can understand. its using C code w/ vc++ 6.0 compile..and glut.

#include <stdlib.h>
#include <GL/glut.h>
#include <stdio.h>  // need for function Output
#include <stdarg.h> // need for function Output



float ww=500,wh=500;
float xoffset1=0.0;
float deltax1=0.01;
float xoffset2=0.0;
float deltax2=0.01;



void Output(GLfloat x, GLfloat y, char *format,...)
{
	va_list args;
	char buffer[200], *p;

	va_start(args,format);
	vsprintf( buffer,format,args);
	va_end(args);
	glRasterPos2f(x,y);
	for (p=buffer ; *p ; p++)
		glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *p);
}




void display(void)
{
 
// pick a background color

    glClearColor(1.0f,0.9f,1.0f,1.0f);

// clear screen
    glClear(GL_COLOR_BUFFER_BIT);

    
    
 
  
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

 

   glColor3f(0.8,0.9,0.9);
   glRectf(0,19,2,20);
   glColor3f(0.0,0.0,0.0);
   Output(0,19.5,"START");

   glColor3f(0.9,0.8,0.9);
   glRectf(0,17.5,2,18.5);
   glColor3f(0.0,0.0,0.0);
   Output(0,18.5,"STOP");

   //WINNER
   //Need a way to check which car is winner.
   //And print it on the screen
   
   glColor3f(0.9,0.8,0.9);
   glRectf(0,16,2,17);
   glColor3f(0.0,0.0,0.0);
   Output(0,16.5,"WINNER");


//draw 2-d objects
//car1

  
     glTranslatef(xoffset1,0,0.0);
     glNormal3f(0.0,0.0,1.0);
	 glColor3f(1.0,1.0,0.7);
	 
	 glBegin(GL_POLYGON);
	      glVertex2f(0,6.0);
		  glVertex2f(3.0,6.0);
		  glVertex2f(3.0,6.4);
		  glVertex2f(2.2,6.4);
		  glVertex2f(2.0,6.8);
		  glVertex2f(1.0,6.8);
		  glVertex2f(0.6,6.4);
		  glVertex2f(0.2,6.4);
		  glVertex2f(0.1,6.4);
		  glVertex2f(0.0,6.0);
		  
	 glEnd();
	 
     glTranslatef(-xoffset1,0.0,0.0);


 
	 
//car2

	 glTranslatef(xoffset2,0,0.0);
     glNormal3f(0.0,0.0,1.0);
	 
	 glColor3f(1.0,0.7,1.0);
	 glBegin(GL_POLYGON);
	      glVertex2f(0,8.0);
		  glVertex2f(3.0,8.0);
		  glVertex2f(3.0,8.4);
		  glVertex2f(2.2,8.4);
		  glVertex2f(2.0,8.8);
		  glVertex2f(1.0,8.8);
		  glVertex2f(0.6,8.4);
		  glVertex2f(0.2,8.4);
		  glVertex2f(0.1,8.4);
		  glVertex2f(0.0,8.0);
		  
	 glEnd();
	 
     glTranslatef(-xoffset2,0.0,0.0);


 
	 

     
     
     
glutSwapBuffers();
glFlush();

}



void Reshape(int w, int h)
{
  
    glViewport(0, 0, w, h);

// use orthographic  projection 

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0,20.0,0.0,20.0,-1.0,1.0);
	ww=w;wh=h;

 
}

void mouse(int button,int state,int x,int y)  
{ 
   
	if (button==GLUT_LEFT_BUTTON  &
		( (x<0.10*wh) & (y<0.05*wh))) {
		deltax1=0.1;
		deltax2=0.2;
	}
	else if (button==GLUT_LEFT_BUTTON  &
		( (x<0.10*wh) & (y<0.12*wh) & (y>0.07*wh))) 
		 {
		deltax1=0.0;
		deltax2=0.0
	}

		//winner method : if left click then car1 iis winner
         // else if right click then car2 is winner.  i want
        //this to be printed out on the screen but since this
        //is not in the display function it won't show up


	else if (button==GLUT_LEFT_BUTTON  &
		( (x<0.10*wh) & (y<0.19*wh) & (y>0.14*wh))) 
		 {
		deltax1 = .4;
		glColor3f(0.6, 0.9, 0.6);
		Output(10,20,"Winner");
	}

	else if (button==GLUT_RIGHT_BUTTON  &
		( (x<0.10*wh) & (y<0.19*wh) & (y>0.14*wh))) 
		 {
		deltax1=0.0;
		deltax2=0.0
	}

	glutPostRedisplay();
	
}

void vrooom()  
{ 

	
    
    xoffset1 = xoffset1+deltax1;
	if  (xoffset1>20.0) { xoffset1=0;xoffset2=xoffset2-20.0;}
	else if (xoffset2>20.0) {xoffset2=0;xoffset1=xoffset1-20.0;}
	xoffset2 = xoffset2+deltax2;
	  
	glutPostRedisplay();
	
}



void main(int argc, char **argv)
{
    glutInit(&argc, argv);
//create window
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(600, 600);
    glutCreateWindow("races");

//register callback functions
    glutReshapeFunc(Reshape);
    glutDisplayFunc(display);
    glutIdleFunc(vrooom);
  	glutMouseFunc(mouse);
	
	


//enter event loop
    glutMainLoop();
}


[Edited by - jahan on September 29, 2004 1:38:05 PM]

Share this post


Link to post
Share on other sites
Advertisement
Anyone, please, i have looked over all possibilities but i can't get any idea...i tried to make a global variable win and check it if the car is winning when it is going at certain speed even..but i guess, i m missing something in the display function or idle function...i can't quiet put my finger to it...any help is appreciated..

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!