glutTimerFunc

I am having a lot of trouble with this function. I am trying to fly a plane, and it flies, but the plane polygons just overlap with one another.
I started with a plane.
Then it moved left for planee.
And again planeee.
I hope you understand what my problem is, and I thank you in advance for your help.

I am not sure the glutTimerfunc is your problem… post some code and maybe more informaton.

Originally posted by Nelah:
I am having a lot of trouble with this function. I am trying to fly a plane, and it flies, but the plane polygons just overlap with one another.
I started with a plane.
Then it moved left for planee.
And again planeee.
I hope you understand what my problem is, and I thank you in advance for your help.

Are you maybe using single buffering and not clearing your scene before redisplaying it? It’s not real clear what problem you’re seeing, so I might be way off…

This is my program. Thanks!

int house1, house2, house3;
static float x,y;
int i;

void init()
{ BACKGROUND;
glShadeModel(GL_SMOOTH);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears buffers
glEnable(GL_DEPTH_TEST); // Hidden surface removal

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

}

void display (int value)
{ glPushMatrix();
glLoadIdentity();

LANDCOLOR; drawland();

drawhouse1();
drawhouse2();
drawhouse3();
flyplane();
//eraseplane();

glPopMatrix();
glFlush();
glutSwapBuffers();

}

void animate (int value)
{
glutPostRedisplay();
glutTimerFunc(200, animate, x );
}

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case ‘t’:
house2++;
break;
case ‘r’:
house3++;
break;
case ‘q’:
if (house1 == house2 == house3 == 2) printf(“You win!”);
else printf(“You lose!”);
exit(0);
break;
default:
glutIdleFunc(flyplane);
}

}

int main (int argc, char** argv)
{
house1 = house2 = house3 = NOTSAFE;
beam = OFF;
x = -1.5;
y = 0.6;

glutInit(&argc, argv);

// Double buffering
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
//	glutInitDisplayMode(GLUT_RGB);

// Creates window
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Village rescue!");

init();

// Display and scene modification functions functions
glutDisplayFunc(display);
glutTimerFunc(200,animate,x);

// glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
}

void drawland()
{
glBegin(GL_POLYGON);
glVertex3f(-1, -1, 0.5);
glVertex3f(1, -1, 0.5);
glVertex3f(1, -0.5, 0.5);
glVertex3f(-1, -0.5, 0.5);
glEnd();
}

void drawhouse1()
{ // Determine state of house
switch( house1 ) {
case NOTSAFE: COLOR1; break;
case IP: WARPCOLOR; break;
case SAFE: return; }
printf(“House1 is %d”, house1);

// Draws front of house
glBegin(GL_POLYGON);
	glVertex3f(-0.8, -0.7, 0);
	glVertex3f(-0.3, -0.7, 0);
	glVertex3f(-0.3, -0.4, 0);
	glVertex3f(-0.8, -0.2, 0);
glEnd();
// Draws top of house
glBegin(GL_POLYGON);
	glVertex3f(-0.8, -0.2, 0);
	glVertex3f(-0.3, -0.4, 0);
	glVertex3f(-0.2, -0.3, 0.1);
	glVertex3f(-0.7, -0.1, 0.1);
glEnd();
// Draws side of house
glBegin(GL_POLYGON);
	glVertex3f(-0.3, -0.7, 0);
	glVertex3f(-0.2, -0.6, 0.1);
	glVertex3f(-0.2, -0.3, 0.1);
	glVertex3f(-0.3, -0.4, 0);
glEnd();

}

void drawhouse2()
{

switch( house2 ) {
case NOTSAFE: COLOR2; break;
case IP: WARPCOLOR; break;
case SAFE: return; }
printf("House2 is %d", house2);

// Draws front of house
glBegin(GL_POLYGON);
	glVertex3f(0, -0.6, 0.4);
	glVertex3f(0.3, -0.6, 0.4);
	glVertex3f(0.3, 0, 0.4);
	glVertex3f(0, 0, 0.4);
glEnd();
// Draws top of house
glBegin(GL_POLYGON);
	glVertex3f(0, 0, 0.4);
	glVertex3f(0.3, 0, 0.4);
	glVertex3f(0.4, 0.1, 0.5);
	glVertex3f(0, 0.1, 0.5);
glEnd();
// Draws side of house
glBegin(GL_POLYGON);
	glVertex3f(0.3, -0.6, 0.4);
	glVertex3f(0.4, -0.5, 0.5);
	glVertex3f(0.4, 0.1, 0.5);
	glVertex3f(0.3, 0, 0.4);
glEnd();

}

void drawhouse3()
{
switch( house3 ) {
case NOTSAFE: COLOR3; break;
case IP: WARPCOLOR; break;
case SAFE: glutPostRedisplay(); return; }
printf(“House3 is %d”, house3);

// Draws front of house
glBegin(GL_POLYGON);
	glVertex3f(0.7, -0.1, -0.2);
	glVertex3f(0.5, -0.4, -0.2);
	glVertex3f(0.6, -0.4, -0.2);
	glVertex3f(0.6, -0.8, -0.2);
	glVertex3f(0.8, -0.8, -0.2);
	glVertex3f(0.8, -0.4, -0.2);
	glVertex3f(0.9, -0.4, -0.2);
glEnd();
// Draws top of house
glBegin(GL_POLYGON);
	glVertex3f(0.7, -0.1, -0.2);
	glVertex3f(0.9, -0.4, -0.2);
	glVertex3f(1, -0.3, -0.1);
	glVertex3f(0.8, 0, -0.1);
glEnd();
// Draws side of house
glBegin(GL_POLYGON);
	glVertex3f(0.8, -0.8, -0.2);
	glVertex3f(0.9, -0.7, -0.1);
	glVertex3f(0.9, -0.3, -0.1);
	glVertex3f(0.8, -0.4, -0.2);
glEnd();

}

void drawplane()
{
glBegin(GL_POLYGON);
glVertex3f(x, 0.7, 0);
glVertex3f(x + 0.1, 0.6, 0);
glVertex3f(x + 0.4, 0.6, 0);
glVertex3f(x + 0.4, 0.9, 0);
glVertex3f(x + 0.3, 0.8, 0);
glVertex3f(x + 0.1, 0.8, 0);
glEnd();
}

void eraseplane()
{
SKYCOLOR; drawplane();
}

void flyplane()
{
PLANECOLOR; drawplane();
x-=0.05;
if (x < -1.5)
x += 3;
}

As I suspected. You only do a glClear in your Init function. You should be clearing it at the beginning of your draw function. You’re using double buffering, so unless you clear the scene, there’s no telling what could have been in the backbuffer at the beginning of your draw routine.

Thanks so much! That solved all of the problems I was having! Now the plane flies!Thank you! Thank you! Thank you!