اینو ببین شاید رستگار شدی
#include <windows.h>
#include<GL/glut.h>
#include <math.h>
#include <time.h>
void init()
{
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 200, 0, 200);
}
GLint i = 0, j = 30,GLcounter=0;
GLdouble k = 3;
void Display()
{
//for (k = 0; k<20; k++){
GLcounter++;
if (GLcounter > 50) {
k = -k;
GLcounter = 0;
}
static float fElect1 = 0.0;
glRotatef(fElect1, 0.0, 1.0, 0.0);
Sleep(100);
glTranslatef(k, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex2i(i, j);
glVertex2i(i + 15, j + 30);
glVertex2i(i + 45, j + 30);
glVertex2i(i + 60, j);
glEnd();
glEnable(GL_POINT_SMOOTH);
glPointSize(35);
glBegin(GL_POINTS);
glColor3f(1, 1, 1);
glVertex2i(i + 20, j);
glColor3f(1, 1, 1);
glVertex2i(i + 40, j);
glEnd();
glFlush();
glutSwapBuffers();
//}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case '1':
Sleep(180);
if (k < 0) k = -k;
glutPostRedisplay();
break;
case '2':
Sleep(290);
if (k > 0) k = -k;
glutPostRedisplay();
break;
case '3':
exit(1);
break;
case 'X':
exit(2);
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(200, 200);
glutCreateWindow("Moving Car");
init();
glutDisplayFunc(Display);
glutKeyboardFunc(keyboard);
glutIdleFunc(Display);
glutMainLoop();
return 0;
}