Hi there,
that’s what i wrote:
#include <GL/glut.h>
#include <stdlib.h>
float x = 0,
y = 0;
void draw()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//cor corrente: verde (0, 127, 0)
glColor3f(0.0f, .5f, 0.0f);
//lado 1
glBegin(GL_TRIANGLES);
glVertex3f(0, 0, 0); //vertice superior
glVertex3f(-.2, -.4, -.5); //vertice inferior esquerdo
glVertex3f(.1, -.25, .5); //vertice inferior direito
glEnd();
glColor3f(0.0f, .6f, 0.0f);
//lado 2
glBegin(GL_TRIANGLES);
glVertex3f(0, 0, 0); //vertice superior
glVertex3f(.2, -.4, -.5); //vertice inferior direito
glVertex3f(.1, -.25, .5); //vertice inferior esquerdo
glEnd();
glColor3f(0.0f, .3f, 0.0f);
//base
glBegin(GL_TRIANGLES);
glVertex3f(.1, -.25, .5); //vertice superior
glVertex3f(-.2, -.4, -.5); //vertice inferior esquerdo
glVertex3f(.2, -.4, -.5); //vertice inferior direito
glEnd();
glFlush();
}
void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
exit(0);
break;
case 'A':
case 'a':
printf("%i
", x);
x--;
glRotatef(0, x, y, 0);
break;
case 'S':
case 's':
printf("%i
", y);
y--;
glRotatef(0, x, y, 0);
break;
case 'W':
case 'w':
printf("%i
", y);
y++;
glRotatef(0, x, y, 0);
break;
case 'D':
case 'd':
printf("%i
", x);
x++;
glRotatef(0, x, y, 0);
break;
}
glutPostRedisplay();
}
void idle()
{
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB |GLUT_SINGLE);
glutInitWindowSize(400,400);
glutInitWindowPosition(10,10);
glutCreateWindow("Quadrado");
glutKeyboardFunc(key);
glutDisplayFunc(draw);
glutIdleFunc(idle);
glutMainLoop();
}