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 4 of 4

Thread: help drawing two cylinder

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    2

    help drawing two cylinder

    i'm trying to draw two cylinder, both filled with the same texture, but I have managed to draw only the first one, here is my draw func:

    Code :
        void display(void)
        {
            // Projection plane
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            //a->draw(mouseY);
            //draw first cylinder WORKING
            glPushMatrix();
                glRotatef(mouseY, 0, 0, 1); 
                quadratic = gluNewQuadric();
                gluQuadricNormals(quadratic, GLU_SMOOTH);
                gluQuadricTexture(quadratic, GL_TRUE);
                glMatrixMode(GL_TEXTURE);
                    glLoadIdentity();
                    glRotatef(90,0,0,1);
                    glTranslatef(0,-1.0,0);
                glMatrixMode(GL_PROJECTION);
                gluCylinder(quadratic,fh_cyl,fh_cyl,fw_cyl,50,1000);
                if(!exec) //used only one time to get a visible cylinder
                {
                    glTranslatef(fX_cylpos,fY_cylpos,0);
                    glRotatef(90, 0.0, 1, 0.0); //rotate object 90 on Y axis
                    glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0 = vertical / 90 = horizontal
                    exec=true;
                }
            glPopMatrix();
            glPushMatrix();
                //draw second cylinder NOT WORKING
                glRotatef(mouseY, 0, 0, 1);
                quadratic2 = gluNewQuadric();
                gluQuadricNormals(quadratic2, GLU_SMOOTH);
                gluQuadricTexture(quadratic2, GL_TRUE);
                gluCylinder(quadratic2,fh_cyl,fh_cyl,fw_cyl,50,1000);
                if(!exec2) 
                {
                    glTranslatef(fX_cylpos+200,fY_cylpos,0);
                    glRotatef(90, 0.0, 1, 0.0); //rotate object 90 on Y axis
                    glRotatef(fangle_cyl, 1.0, 0.0, 0.0);  //0 = vertical / 90 = horizontal      
                    exec2=true;
                }
            glPopMatrix();
           //b->draw(mouseY);
           glutSwapBuffers();
        }

    And this is the reshape func:

    Code :
        void reshape(int w, int h)
        {
           glViewport (0, 0, (GLsizei) w, (GLsizei) h);
           glLoadIdentity();
           glMatrixMode(GL_PROJECTION);
           //glOrtho(-1000.0, 1000.0*(screen_h/screen_w), -1000.0, 1000.0*(screen_h/screen_w), 1000.0, -110.0);
           glOrtho(fOrtoXinit, fOrtoXend, fOrtoYinit, fOrtoYend , 1000, -1000.0);
           glMatrixMode(GL_MODELVIEW);
        }

    the code in the if statement is used to draw the cylinder vertical.

  2. #2
    Intern Contributor
    Join Date
    Jul 2014
    Location
    Italy, Lissone
    Posts
    60
    well, i think because you are drawing the cylinders in the same position

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    2
    Quote Originally Posted by Ruggero Visitnin View Post
    well, i think because you are drawing the cylinders in the same position
    If I disable the first cylinder the second is correctly drawn, in a different position thanks to: glTranslatef(fX_cylpos+200,fY_cylpos,0);

    Anyway I've now put the code before drawiing the cylinder, edit below now I have 2 cylinder but in the position that i want (one next to the other)

    Code :
    if(!exec) //basically IF not used anymore
    {
        glTranslatef(fX_cylpos,fY_cylpos,0);
        glRotatef(90, 0.0, 1, 0.0); //rotate object 90 on Y axis
        glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0 = vertical / 90 = horizontal
        //exec=true;
    }
    gluCylinder(quadratic,fh_cyl,fh_cyl,fw_cyl,50,1000);            
    glPopMatrix();
     
    glPushMatrix();
    //draw second cylinder NOT WORKING
    glRotatef(mouseY, 0, 0, 1);
    quadratic2 = gluNewQuadric();
    gluQuadricNormals(quadratic2, GLU_SMOOTH);
    gluQuadricTexture(quadratic2, GL_TRUE);
    if(!exec2) 
    {
        glTranslatef(fX_cylpos+200,fY_cylpos,20);
        glRotatef(90, 0.0, 1, 0.0); //rotate object 90 on Y axis
        glRotatef(fangle_cyl, 1.0, 0.0, 0.0);  //0 = vertical / 90 = horizontal      
        exec2=true;
    }
    gluCylinder(quadratic2,fh_cyl,fh_cyl,fw_cyl,50,1000);
     
    glPopMatrix();
    Last edited by p4ever; 08-22-2014 at 06:10 PM.

  4. #4
    Intern Contributor
    Join Date
    Jul 2014
    Location
    Italy, Lissone
    Posts
    60
    Quote Originally Posted by p4ever View Post
    If I disable the first cylinder the second is correctly drawn, in a different position thanks to: glTranslatef(fX_cylpos+200,fY_cylpos,0);

    Anyway I've now put the code before drawiing the cylinder, edit below now I have 2 cylinder but in the position that i want (one next to the other)

    Code :
    if(!exec) //basically IF not used anymore
    {
        glTranslatef(fX_cylpos,fY_cylpos,0);
        glRotatef(90, 0.0, 1, 0.0); //rotate object 90 on Y axis
        glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0 = vertical / 90 = horizontal
        //exec=true;
    }
    gluCylinder(quadratic,fh_cyl,fh_cyl,fw_cyl,50,1000);            
    glPopMatrix();
     
    glPushMatrix();
    //draw second cylinder NOT WORKING
    glRotatef(mouseY, 0, 0, 1);
    quadratic2 = gluNewQuadric();
    gluQuadricNormals(quadratic2, GLU_SMOOTH);
    gluQuadricTexture(quadratic2, GL_TRUE);
    if(!exec2) 
    {
        glTranslatef(fX_cylpos+200,fY_cylpos,20);
        glRotatef(90, 0.0, 1, 0.0); //rotate object 90 on Y axis
        glRotatef(fangle_cyl, 1.0, 0.0, 0.0);  //0 = vertical / 90 = horizontal      
        exec2=true;
    }
    gluCylinder(quadratic2,fh_cyl,fh_cyl,fw_cyl,50,1000);
     
    glPopMatrix();
    i'm sorry i miss that line of code

Posting Permissions

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