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: outline cube

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2001
    Posts
    20

    outline cube

    void DrawCube(void)
    {
    static GLfloat wAngleX = 0.0f;

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

    glTranslatef(0.0f, 0.0f, 0.0f);
    glRotatef(wAngleX, 0.0f, 1.0f, 0.0f);

    wAngleX += 0.1f;

    glBegin(GL_QUAD_STRIP);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, 0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, -0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.5f, -0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, -0.5f, -0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, 0.5f, -0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, -0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, 0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glEnd();

    glBegin(GL_QUADS);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, 0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.5f, -0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    glEnd();

    glBegin(GL_QUADS);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, -0.5f, 0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, -0.5f, -0.5f);

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glEnd();

    glPopMatrix();

    glFinish();

    glutSwapBuffers();
    }


    The above is part of my program to draw a red rotating cube.
    Now, i am only able to see a solid red cube without its outline...
    how can i edit the code to display the outline of the cube??
    Pls help!!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: outline cube

    If you mean drawing it as wireframe, then insert glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) before drawing the cube. GL_FILL instead of GL_LINE will take you back to filled polygon rendering.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2001
    Posts
    20

    Re: outline cube

    Ok...
    Then how do i apply color to this wireframe now? i.e red cube with black wireframe...

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2001
    Posts
    4

    Re: outline cube

    i think you didn't understand what glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) does ... it does NOT draw the wireframe and the filled cube at once ... instead it draws the cube just as a wireframe object ... if you want the wireframe to be green or something like that plus the solid red cube you need to render the cube twice using polygon offset ...

    the best is to look here :
    http://www.opengl.org/developers/faq...ygonoffset.htm

    if you draw the cube with the help of triangles you will se every line ... but if you just want the lines on the edge of the cube to be seen use glEdgeFlag ...


    [This message has been edited by Sebbi (edited 12-01-2001).]

Posting Permissions

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