Ahi va mi codigo que he hecho:
Código
#include <GL/freeglut.h> #include <GL/glu.h> #include <iostream> int posx=0, posy=0; void resize(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-50,50,-50,50,-10,10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); } //---------------------------------------------------------// void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBegin(GL_LINES); glColor3f(1.0f,1.0f,1.0f); glVertex3f( -50.0f, 0.0f,0.0f); glVertex3f(50.0f, 0.0f,0.0f); glColor3f(1.0f,1.0f,1.0f); glVertex3f( 0.0f, -50.0f,0.0f); glVertex3f(0.0f, 50.0f,0.0f); glEnd(); //----------------1º TRIANGULO----------------// glPushMatrix(); glTranslatef(posx, posy, 0); glColor3f(1,0,0); glutSolidSphere(5, 20, 2); glEnd(); glPopMatrix(); glutSwapBuffers(); } //---------------------------------------------------// void key(unsigned char key, int x, int y) { switch (key) { case 27 : exit(0); break; default: break; } glutPostRedisplay(); } void tecladoEspecial(int tecla, int x, int y) { switch(tecla) { case GLUT_KEY_UP : posy++;break; case GLUT_KEY_DOWN : posy--;break; case GLUT_KEY_RIGHT : posx++;break; case GLUT_KEY_LEFT : posx--;break; } glutPostRedisplay(); } void idle() { glutPostRedisplay(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(640,480); glutInitWindowPosition(10,10); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("Transformacion 1"); glutReshapeFunc(resize); glutDisplayFunc(display); glutKeyboardFunc(key); glutSpecialFunc(tecladoEspecial); glutIdleFunc(idle); glutMainLoop(); return 0; }
Gracias de antemano....