PDA

View Full Version : سوال: opengl



mezood
جمعه 31 مرداد 1393, 11:37 صبح
دوستان لطفا راهنمایی کنید برای اصلاح کد چیکار کنم

#include<glut.h>



void init()
{
glClearColor(0,0,0,0);
gluOrtho2D(-5,5,-5,5);
}


void display();


void idle();


main(int argc, char**argv)
{
glutInit(&argc,argv);//initialize GLUT
glutInitWindowSize(800,600);//define the window size
glutInitWindowPosition(10,50);//position the window
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);//define the drawing mode
glutCreateWindow("lesson 3");// create our Window
float time=0;//variable to record the how much time has passed
init();//initialize our variables
glutDisplayFunc(display);//tell Glut what our display funcion is
glutIdleFunc(idle);
glutMainLoop();//keep the program running
return 0;
}


void display()
{
glClear(GL_COLOR_BUFFER_BIT);//clear the screen


glColor3f(1,0,0);//set color to red


glPushMatrix();//create a new matrix


glRotatef(time,0,0,1);//rotate the triangle on z axis based on how much time has passed


glBegin(GL_TRIANGLES);//start drawing triangles
glVertex2f(3,-4);
glVertex2f(3.5,-3);
glVertex2f(4,-4);
glEnd();//stop drawing triangles


glPopMatrix();//stops current transformations to the matrix
//
glColor3f(0,1,0);
glPushMatrix();


glTranslatef(time/50,0,0);//slide the object on the x axis based on time


glBegin(GL_QUADS);
glVertex2f(-4,-4);
glVertex2f(-4,-2);
glColor3f(0,0,1);// change the color to blue halfway through to creat a neat color effect
glVertex2f(-2,-2);
glVertex2f(-2,-4);
glEnd();
glPopMatrix();
//
glPushMatrix();


glScalef(time/200,time/200,time/200);//scale the object on all axiis based on time


glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex2f(-2,2);
glColor3f(0,1,0);
glVertex2f(-1,3);
glColor3f(0,0,1);
glVertex2f(0,2);
glColor3f(1,0,1);
glVertex2f(-.5,0);
glColor3f(1,1,0);
glVertex2f(-1.5,0);
glEnd();
glPopMatrix();
//
//
//
glFlush(); //draw everything to the screen
glutPostRedisplay();//start drawing again
}


void idle()
{
time=time+0.1;//increase the time variable


if(time>360)
time=0;//reset the time variable
}