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

Thread: wireframe cube

  1. #1
    Intern Newbie
    Join Date
    Nov 2010
    Posts
    31

    wireframe cube

    I have this little function that draws 3d cube. I would like to use it also to draw the cube as wireframe that result I am getting is not correct. It keeps adding diagonal lines between corners of each side.

    Code :
     
    void myFunction(int myVar){
     
    glBegin(GL_QUADS);
     
     
        glVertex3f(myVar,myVar,myVar);
        glVertex3f(-myVar,myVar,myVar);
        glVertex3f(-myVar,-myVar,myVar);
        glVertex3f(myVar,-myVar,myVar);
     
        glVertex3f(myVar,myVar,-myVar);
        glVertex3f(-myVar,myVar,-myVar);
        glVertex3f(-myVar,-myVar,-myVar);
        glVertex3f(myVar,-myVar,-myVar);
     
        glVertex3f(myVar,myVar,myVar);
        glVertex3f(myVar,-myVar,myVar);
        glVertex3f(myVar,-myVar,-myVar);
        glVertex3f(myVar,myVar,-myVar);
     
        glVertex3f(-myVar,myVar,myVar);
        glVertex3f(-myVar,-myVar,myVar);
        glVertex3f(-myVar,-myVar,-myVar);
        glVertex3f(-myVar,myVar,-myVar);
     
        glVertex3f(myVar,myVar,myVar);
        glVertex3f(-myVar,myVar,myVar);
        glVertex3f(-myVar,myVar,-myVar);
        glVertex3f(myVar,myVar,-myVar);
     
        glVertex3f(myVar,-myVar,myVar);
        glVertex3f(-myVar,-myVar,myVar);
        glVertex3f(-myVar,-myVar,-myVar);
        glVertex3f(myVar,-myVar,-myVar);
     
    glEnd();
     
    }

    Can anyone suggest whats wrong or how to use this same function to draw cube in wireframe.

  2. #2
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    354

    Re: wireframe cube

    I tested your code, just add glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); before glBegin(). Then if you want to fill your polygon as before, call glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); after glEnd();

Posting Permissions

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