Results 1 to 5 of 5

Thread: Placing a rectangle on top of a gluCylinder?

  1. #1
    Junior Member Newbie
    Join Date
    May 2009
    Posts
    7

    Placing a rectangle on top of a gluCylinder?

    I have trouble drawing a rectangle, on top of a gluCylinder, and rotating the newly created object (both the rectangle and the cylinder around the same axis). Can anyone explain to me how to manipulate this? I am struggling to translate them together somehow but it doesn't work. Thanks a lot.

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Placing a rectangle on top of a gluCylinder?

    I have trouble drawing a rectangle, on top of a gluCylinder, and rotating the newly created object (both the rectangle and the cylinder around the same axis).[...] I am struggling to translate them together somehow but it doesn't work. Thanks a lot.
    And finally is your problem about translation or rotation?

  3. #3
    Senior Member Regular Contributor
    Join Date
    Dec 2008
    Location
    USA
    Posts
    134

    Re: Placing a rectangle on top of a gluCylinder?

    Something like this should work:

    Code :
    do your transformations
     
    drawCylinder();
    drawRectangle();

  4. #4
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Placing a rectangle on top of a gluCylinder?

    you need to clearly tell to opengl that you are youfing depth buffer bit
    if some where you call
    glClear(GL_BLABLA_BUFFER_BIT )
    you replace with
    glClear(GL_BLABLA | GL_DEPTH_BUFFER_BIT);

    and also if you use glut library
    you need to replace
    glutInitDisplayMode(GLUT_BLABLA);
    with
    glutInitDisplayMode(GLUT_BLABLA | GLUT_ DEPTH);
    and also enable GL_DEPTH_TEST

    Here is a sample perhapes you looking for
    try to compile it (if Linux thats better cause makefile)

    main.cpp:

    #include <stdlib.h>
    #include <GL/glut.h>

    int WinWidth = 640,WinHeight = 480;
    void Cylinder(GLdouble base, GLdouble top, GLdouble height);
    void Disk(GLdouble inner, GLdouble outer);
    void pyram(GLfloat rad,GLfloat Height)
    {// every wall with different color so i can identify its Pyramidical

    GLUquadric *Cy;
    Cy = gluNewQuadric ();
    gluQuadricDrawStyle ( Cy, GLU_FILL);
    gluQuadricNormals ( Cy, GLU_SMOOTH);
    gluQuadricOrientation ( Cy, GLU_INSIDE);
    glColor3f(1.0f,0.0f,0.0f);
    gluCylinder (Cy, 0.0f, rad, Height, 32,24);
    glColor3f(0.0f,1.0f,0.0f);
    glTranslatef(0.0f,0.0f,Height);
    gluDisk ( Cy, 0.0f, rad,32,24);
    }
    GLfloat zr = 0.5f;
    void RScene()
    {
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glDepthMask(GL_TRUE);
    glEnable(GL_CCW);
    glEnable(GL_DEPTH_TEST);
    glRotatef(zr,1.0f,0.0f,0.0f);

    glPushMatrix();
    pyram(0.5,0.5);
    glPopMatrix();
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CCW);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    zr+= 0.5f;
    glutSwapBuffers();
    glutPostRedisplay();
    }

    void WinSize(GLsizei w,GLsizei h)
    {
    GLfloat Ratio = (GLdouble)w/(GLdouble)h;
    if(h==0)h=1;



    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0f,Ratio,-100.0f,100.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0,0,w,h);

    }
    void Idle(){glutPostRedisplay();}
    int main(int argc,char *argv[])
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(WinWidth,WinHeight);
    glutCreateWindow("Thats Perhaps you need");
    glutDisplayFunc(RScene);
    glutReshapeFunc(WinSize);

    glutMainLoop();


    }

    void Cylinder(GLdouble base, GLdouble top, GLdouble height)
    {
    }
    void Disk(GLdouble inner, GLdouble outer)
    {GLUquadric *Dsk;
    Dsk = gluNewQuadric ();
    gluQuadricDrawStyle ( Dsk, GLU_FILL);
    gluQuadricNormals ( Dsk, GLU_SMOOTH);
    gluQuadricOrientation ( Dsk, GLU_INSIDE);

    }
    At Linux condition try make with below file

    makefile:

    LIB = -I/usr/lib
    INC = -I/usr/include
    SRC = main.cpp
    COMP = gcc
    LINK = -lglut -lGL
    1st:
    $(COMP) -o cam1 $(SRC) $(LIB) $(INC) $(LINK)
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  5. #5
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Placing a rectangle on top of a gluCylinder?

    you need to clearly tell to opengl that you are using depth buffer bit
    if some where you call
    glClear(GL_BLABLA_BUFFER_BIT )
    you replace with
    glClear(GL_BLABLA | GL_DEPTH_BUFFER_BIT);

    and also if you use glut library
    you need to replace
    glutInitDisplayMode(GLUT_BLABLA);
    with
    glutInitDisplayMode(GLUT_BLABLA | GLUT_ DEPTH);
    and also enable GL_DEPTH_TEST

    Here is a sample perhapes you looking for
    try to compile it (if Linux thats better cause makefile)

    main.cpp:

    #include <stdlib.h>
    #include <GL/glut.h>

    int WinWidth = 640,WinHeight = 480;
    void Cylinder(GLdouble base, GLdouble top, GLdouble height);
    void Disk(GLdouble inner, GLdouble outer);
    void pyram(GLfloat rad,GLfloat Height)
    {// every wall with different color so i can identify its Pyramidical

    GLUquadric *Cy;
    Cy = gluNewQuadric ();
    gluQuadricDrawStyle ( Cy, GLU_FILL);
    gluQuadricNormals ( Cy, GLU_SMOOTH);
    gluQuadricOrientation ( Cy, GLU_INSIDE);
    glColor3f(1.0f,0.0f,0.0f);
    gluCylinder (Cy, 0.0f, rad, Height, 32,24);
    glColor3f(0.0f,1.0f,0.0f);
    glTranslatef(0.0f,0.0f,Height);
    gluDisk ( Cy, 0.0f, rad,32,24);
    }
    GLfloat zr = 0.5f;
    void RScene()
    {
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glDepthMask(GL_TRUE);
    glEnable(GL_CCW);
    glEnable(GL_DEPTH_TEST);
    glRotatef(zr,1.0f,0.0f,0.0f);

    glPushMatrix();
    pyram(0.5,0.5);
    glPopMatrix();
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CCW);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    zr+= 0.5f;
    glutSwapBuffers();
    glutPostRedisplay();
    }

    void WinSize(GLsizei w,GLsizei h)
    {
    GLfloat Ratio = (GLdouble)w/(GLdouble)h;
    if(h==0)h=1;



    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0f,Ratio,-100.0f,100.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0,0,w,h);

    }
    void Idle(){glutPostRedisplay();}
    int main(int argc,char *argv[])
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(WinWidth,WinHeight);
    glutCreateWindow("Thats Perhaps you need");
    glutDisplayFunc(RScene);
    glutReshapeFunc(WinSize);

    glutMainLoop();


    }

    void Cylinder(GLdouble base, GLdouble top, GLdouble height)
    {
    }
    void Disk(GLdouble inner, GLdouble outer)
    {GLUquadric *Dsk;
    Dsk = gluNewQuadric ();
    gluQuadricDrawStyle ( Dsk, GLU_FILL);
    gluQuadricNormals ( Dsk, GLU_SMOOTH);
    gluQuadricOrientation ( Dsk, GLU_INSIDE);

    }
    At Linux condition try make with below file

    makefile:

    LIB = -I/usr/lib
    INC = -I/usr/include
    SRC = main.cpp
    COMP = gcc
    LINK = -lglut -lGL
    1st:
    $(COMP) -o cam1 $(SRC) $(LIB) $(INC) $(LINK)
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

Similar Threads

  1. Billboards - placing text on the screen.
    By ssallen in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-21-2012, 08:35 AM
  2. Placing many different 2D elements in a window
    By Lefteris in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-28-2012, 03:12 PM
  3. Placing text in 3D world.
    By Zalewa in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-06-2009, 04:52 PM
  4. placing objects on a heightmap
    By Andrew Davey in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-15-2004, 11:38 AM
  5. Placing trees on Terrain with mouse?
    By ironduke in forum OpenGL: Advanced Coding
    Replies: 27
    Last Post: 01-17-2001, 01:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean