Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How to use for in opengl

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    4

    Unhappy How to use for in opengl

    Hi im new at opengl i wanna make rectangular prisms
    where the first is the base and the second is above the first, and so the following
    to make a pyramid
    Already did this, but only shows 1 prism why is that?
    how should I use "for" it to show all

    Code cpp:
    double rotate_y=0;
    double rotate_x=0;
    double x=0.50;
    double y=0;
     
    // ----------------------------------------------------------
    // Función de retrollamada “display()”
    // ----------------------------------------------------------
    void display(){
     
      //  Borrar pantalla y Z-buffer
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     
      // Resetear transformaciones
      glLoadIdentity();
     
     
      glRotatef( rotate_x, 1.0, 0.0, 0.0 );
      glRotatef( rotate_y, 0.0, 1.0, 0.0 );
     
      //PIRAMIDE
     
     
          //PRISMA1
           //LADO FRONTAL
           glBegin(GL_POLYGON);
     
           glColor3f(0, 0,  1.0 );
           glVertex3f(  x,y, -x );
           glVertex3f(  x,  y+.12, -x );
           glVertex3f( -x,  y+.12, -x );
           glVertex3f( -x, y, -x );
     
           glEnd();
     
           // LADO TRASERO
           glBegin(GL_POLYGON);
           glColor3f(    0, 0,  1 );
           glVertex3f(  x, y, x );
           glVertex3f(  x,  y+.12, x );
           glVertex3f( -x,  y+.12, x);
           glVertex3f( -x, y, x);
           glEnd();
     
           // LADO DERECHO
           glBegin(GL_POLYGON);
           glColor3f(  0,  1,  0 );
           glVertex3f( x, y, -x );
           glVertex3f( x,  y+.12, -x);
           glVertex3f( x,  y+.12,  x );
           glVertex3f( x, y,  x );
           glEnd();
     
           // LADO IZQUIERDO
           glBegin(GL_POLYGON);
           glColor3f(   0,  1,  0 );
           glVertex3f( -x, y,  x );
           glVertex3f( -x,  y+.12,  x );
           glVertex3f( -x,  y+.12, -x);
           glVertex3f( -x, y, -x );
           glEnd();
     
     
     
           // LADO TAPA
           glBegin(GL_POLYGON);
           glColor3f(   0.9,  0.0,  .10 );
           glVertex3f(  x, y+.12, -x );
           glVertex3f(  x, y+.12,  x );
           glVertex3f( -x, y+.12,  x);
           glVertex3f( -x, y+.12, -x);
           glEnd();
     
     
     
     
     
      glFlush();
        glutSwapBuffers();
     
     
     
      }
     
    // ----------------------------------------------------------
    // Función de retrollamada “specialKeys()”
    // ----------------------------------------------------------
    void specialKeys( int key, int x, int y ) {
     
      //  Flecha derecha: aumentar rotación 5 grados
      if (key == GLUT_KEY_RIGHT)
        rotate_y += 5;
     
      //  Flecha izquierda: disminuir rotación 5 grados
      else if (key == GLUT_KEY_LEFT)
        rotate_y -= 5;
     
      else if (key == GLUT_KEY_UP)
        rotate_x += 5;
     
      else if (key == GLUT_KEY_DOWN)
        rotate_x -= 5;
     
      //  Solicitar actualización de visualización
      glutPostRedisplay();
     
    }
     
    // ----------------------------------------------------------
    // Función “main()”
    // ----------------------------------------------------------
    int main(int argc, char* argv[]){
     
      //  Inicializar los parámetros GLUT y de usuario proceso
     
        glutInit(&argc,argv);
     
      //  Solicitar ventana con color real y doble buffer con Z-buffer
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowSize(500, 500);
      // Crear ventana
      glutCreateWindow("Cubo asombroso");
     
      //  Habilitar la prueba de profundidad de Z-buffer
      glEnable(GL_DEPTH_TEST);
     
      // Funciones de retrollamada
    // HERE IS THE FOR
    Code cpp:
    for(int i=0;i<=3;i++){
      glutDisplayFunc(display);
     
      x=x-.10;
      y=y+.12;
      }
      glutSpecialFunc(specialKeys);
     
      //  Pasar el control de eventos a GLUT
      glutMainLoop();
     
      //  Regresar al sistema operativo
      return 0;
     
    }
    Last edited by Dark Photon; 12-15-2017 at 05:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •