Results 1 to 3 of 3

Thread: why the rendering of my cube is not perfect ?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    why the rendering of my cube is not perfect ?

    there is an error with GL_LINE and more with GL_FILL


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


    void display (void)
    {


    static GLint vertices [] = {1,1,0, 10,1,0, 10,10,0, 1,10,0, -2,8,10, 7,8,10,
    7,17,10, -2,17,10};

    static GLfloat colors_RGB [] = {1.0,0.4,0.4, 0.4,0.4,1.0, 0.8,1.0,0.2, 0.75,0.75,0.75,
    0.35,0.35,0.35, 0.5,0.5,0.5};

    glEnableClientState (GL_COLOR_ARRAY);
    glEnableClientState (GL_VERTEX_ARRAY);
    glColorPointer (3, GL_FLOAT, 0, colors_RGB);
    glVertexPointer (3, GL_INT, 0, vertices);

    static GLubyte toutLesSommets [] = { 0,1,2, 2,3,0, 1,5,6, 6,2,1, 4,5,6, 7,6,4, 4,0,3, 3,7,4, 0,1,5, 5,4,0, 3,2,6, 6,7,3 };

    glPolygonMode (GL_FRONT, GL_LINE) ;
    glFrontFace (GL_CCW) ;
    glEnable (GL_CULL_FACE) ;
    glCullFace (GL_BACK) ;

    glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, toutLesSommets) ;

    glutSwapBuffers() ;
    glFlush () ;
    }

    void main (int argc, char** argv)

    {
    glutInit (&argc, argv) ;
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
    glutInitWindowSize (640, 480) ;
    glutInitWindowPosition (250,250) ;
    glutCreateWindow (argv [0]) ;

    glClearColor (1.0, 1.0, 1.0, 1.0) ;
    glClear (GL_COLOR_BUFFER_BIT) ;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrtho(25.0 , -20.0, 20.0, -20.0, -10.0, 16.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glutDisplayFunc (display) ;
    glutMainLoop () ;

    }

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: why the rendering of my cube is not perfect ?

    Error in what way?

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: why the rendering of my cube is not perfect ?

    Because you
    - didn't enable GL_DEPTH_TEST.
    - didn't clear the depth buffer.
    - have triangle (7,6,4) in the wrong order, it needs to be (6,7,4).

Similar Threads

  1. A cube is not rendering
    By cifacia in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-22-2014, 03:38 AM
  2. Cube not rendering
    By cifacia in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-10-2013, 05:33 AM
  3. Cube Rendering
    By JMoore in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-21-2010, 06:42 PM
  4. Rendering a Cube?
    By Thales in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 01-19-2002, 07:12 AM
  5. rendering a cube
    By joey in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-14-2001, 01:24 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
  •  
Proudly hosted by Digital Ocean