elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  OpenGL
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: OpenGL  (Leído 2,071 veces)
cazagavilan

Desconectado Desconectado

Mensajes: 82


Ver Perfil
OpenGL
« en: 25 Abril 2012, 22:46 pm »

Hola!

Se supone que tengo que crear un triangulo y rotarlo a 45 grados en el eje y el problema esta en que en el curso que hago no explica bien la implementacion de glRotatef... y me da error.

Código
  1. #include <Windows.h>
  2. #include <gl\glut.h>
  3. #include <gl\gl.h>
  4. #include <gl\GLU.h>
  5. void animacion(void);
  6. void init(void);
  7. void dibujar(void);
  8. void redimensionar(int, int);
  9. void teclado (unsigned char, int);
  10. void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
  11.  
  12. void init(void)
  13. {
  14. glClearColor(0.0,0.0,0.0,0.0);
  15. glEnable(GL_DEPTH_TEST);
  16. glShadeModel(GL_FLAT);
  17. }
  18.  
  19. void redimensionar(int ancho, int alto)
  20. {
  21. glViewport(0,0,(GLint)ancho, (GLint)alto);
  22. glMatrixMode(GL_PROJECTION);
  23. glLoadIdentity();
  24. gluPerspective(35,((float)ancho/alto), 0.1, 1000);
  25. }
  26.  
  27. void dibujar(void)
  28. {
  29. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  30. glMatrixMode(GL_MODELVIEW);
  31. glLoadIdentity();
  32. gluLookAt(3,2,3,0,0,0,0,1,0);
  33. glPushMatrix();
  34. glRotatef(45, 0, 0, 1);
  35. // Primera cara
  36. glBegin(GL_TRIANGLES);
  37. glColor3f(1.0,0.5,1.0);
  38. glVertex3f(0,1,0);
  39. glVertex3f(1,0,1);
  40. glVertex3f(-1,0,1);
  41. glEnd();
  42. // Segunda cara
  43. glBegin(GL_POLYGON);
  44. glColor3f(1.0,1.0,0.0);
  45. glVertex3f(0,1,0);
  46. glVertex3f(-1,0,1);
  47. glVertex3f(-1,0,-1);
  48. glEnd();
  49. // Tercera cara
  50. glBegin(GL_POLYGON);
  51. glColor3f(0.5,0.9,1.0);
  52. glVertex3f(0,1,0);
  53. glVertex3f(-1,0,-1);
  54. glVertex3f(1,0,-1);
  55. glEnd();
  56. // Cuarta cara
  57. glBegin(GL_POLYGON);
  58. glColor3f(0.5,0.9,1.0);
  59. glVertex3f(0,1,0);
  60. glVertex3f(1,0,-1);
  61. glVertex3f(1,0,1);
  62. glEnd();
  63. glPopMatrix();
  64. glutSwapBuffers();
  65. }
  66.  
  67. void teclado(unsigned char key, int x, int y)
  68. {
  69. if(key==27) exit(0);
  70. }
  71.  
  72. void main( int argc, char** argv)
  73. {
  74. glutInit(&argc,argv);
  75. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  76. glutInitWindowSize(320,240);
  77. glutCreateWindow("Intro");
  78.  
  79. // Registrar funciones
  80. init();
  81. glutIdleFunc(animacion);
  82. glutKeyboardFunc(teclado);
  83. glutDisplayFunc(dibujar);
  84. glutReshapeFunc(redimensionar);
  85.  
  86. // Bucle de eventos principal
  87. glutMainLoop();
  88. }

Muchas gracias.


En línea

cazagavilan

Desconectado Desconectado

Mensajes: 82


Ver Perfil
Re: OpenGL
« Respuesta #1 en: 26 Abril 2012, 16:47 pm »

Solucionado.

Código
  1. #include <gl\glut.h>
  2.  
  3. void init(void);
  4. void dibujar(void);
  5. void redimensionar(int, int);
  6. void teclado (unsigned char, int);
  7.  
  8. void init(void)
  9. {
  10. glClearColor(0.0,0.0,0.0,0.0);
  11. glEnable(GL_DEPTH_TEST);
  12. glShadeModel(GL_FLAT);
  13. }
  14.  
  15. void redimensionar(int ancho, int alto)
  16. {
  17. glViewport(0,0,(GLint)ancho, (GLint)alto);
  18. glMatrixMode(GL_PROJECTION);
  19. glLoadIdentity();
  20. gluPerspective(35,((float)ancho/alto), 0.1, 1000);
  21. }
  22.  
  23. void dibujar(void)
  24. {
  25. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  26.    glMatrixMode(GL_MODELVIEW);
  27. glLoadIdentity();
  28. gluLookAt(3,2,3,0,0,0,0,1,0);
  29. glPushMatrix();
  30. glRotatef(45, 0, 0, 1);
  31. // Primera cara
  32. glBegin(GL_TRIANGLES);
  33. glColor3f(1.0,0.5,1.0);
  34. glVertex3f(0,1,0);
  35. glVertex3f(1,0,1);
  36. glVertex3f(-1,0,1);
  37. glEnd();
  38. // Segunda cara
  39. glBegin(GL_POLYGON);
  40. glColor3f(1.0,1.0,0.0);
  41. glVertex3f(0,1,0);
  42. glVertex3f(-1,0,1);
  43. glVertex3f(-1,0,-1);
  44. glEnd();
  45. // Tercera cara
  46. glBegin(GL_POLYGON);
  47. glColor3f(0.5,0.9,1.0);
  48. glVertex3f(0,1,0);
  49. glVertex3f(-1,0,-1);
  50. glVertex3f(1,0,-1);
  51. glEnd();
  52. // Cuarta cara
  53. glBegin(GL_POLYGON);
  54. glColor3f(0.5,0.9,1.0);
  55. glVertex3f(0,1,0);
  56. glVertex3f(1,0,-1);
  57. glVertex3f(1,0,1);
  58. glEnd();
  59. glutSwapBuffers();
  60. }
  61.  
  62. void teclado(unsigned char key, int x, int y)
  63. {
  64. if(key==27) exit(0);
  65. }
  66.  
  67. void main( int argc, char** argv)
  68. {
  69. glutInit(&argc,argv);
  70. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  71. glutInitWindowSize(320,240);
  72. glutCreateWindow("Intro");
  73.  
  74. // Registrar funciones
  75. init();
  76. glutKeyboardFunc(teclado);
  77. glutDisplayFunc(dibujar);
  78. glutReshapeFunc(redimensionar);
  79.  
  80. // Bucle de eventos principal
  81. glutMainLoop();
  82. }[code=gml]
[/code]


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
OpenGL Dev C++
Programación C/C++
Monica_Barcelona 7 5,552 Último mensaje 12 Mayo 2010, 18:38 pm
por [Zero]
opengl
Programación General
mapers 4 3,065 Último mensaje 29 Octubre 2010, 23:50 pm
por bolivianito
OPENGL
Programación C/C++
mapers 0 1,696 Último mensaje 13 Enero 2011, 07:08 am
por mapers
Programacion Opengl
Programación C/C++
latinoalfredo 1 1,415 Último mensaje 6 Mayo 2014, 01:41 am
por Miseryk
VAOs en OpenGL
Programación C/C++
4dr14n31t0r 3 2,000 Último mensaje 31 Enero 2017, 00:12 am
por ivancea96
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines