Results 1 to 2 of 2

Thread: Maybe Simple problem,but strange to me

  1. #1
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Nanjing,China
    Posts
    116

    Maybe Simple problem,but strange to me

    there are two parts of drawing in my gl program.
    one part is draw the lines, another is draw the square.If i put the part of draw the lines before that draw the square,the program will quit immediately after executed.
    if i put the part of drawing the line after the part of drawing square,the program would be ok.It looks very strange to me.Does anyone has the idea how this happened.

    situation1:the code can not run
    //draw the lines
    glLoadIdentity();
    glBegin(GL_LINE_LOOP);
    glColor3f(0.0f,0.5f,1.0f);
    glVertex3d(-1,1,-2.5);
    glVertex3d(1,1,-2.5);
    glVertex3d(1,-1,-2.5);
    glVertex3d(-1,-1,-2.5);
    glEnd();

    //draw the square
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-10.0f);
    glBegin(GL_QUADS); // Draw A Quad
    glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
    glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Top)
    glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Top)
    glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left Of The Quad (Top)
    glVertex3f( 0.5f, 0.5f, 0.5f); // Bottom Right Of The Quad (Top)
    glColor3f(1.0f,1.0f,0.0f); // Set The Color To Orange
    glVertex3f( 0.5f,-0.5f, 0.5f); // Top Right Of The Quad (Bottom)
    glVertex3f(-0.5f,-0.5f, 0.5f); // Top Left Of The Quad (Bottom)
    glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Bottom)
    glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Bottom)
    glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
    glVertex3f( 0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Front)
    glVertex3f(-0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Front)
    glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Front)
    glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Front)
    glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
    glVertex3f( 0.5f,-0.5f,-0.5f); // Top Right Of The Quad (Back)
    glVertex3f(-0.5f,-0.5f,-0.5f); // Top Left Of The Quad (Back)
    glVertex3f(-0.5f, 0.5f,-0.5f); // Bottom Left Of The Quad (Back)
    glVertex3f( 0.5f, 0.5f,-0.5f); // Bottom Right Of The Quad (Back)
    glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
    glVertex3f(-0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Left)
    glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Left)
    glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Left)
    glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Left)
    glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
    glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Right)
    glVertex3f( 0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Right)
    glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Right)
    glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Right)
    glEnd(); // Done Drawing The Quad

    Situation2:the code can run


    //draw the square
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-10.0f);
    glBegin(GL_QUADS); // Draw A Quad
    glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
    glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Top)
    glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Top)
    glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left Of The Quad (Top)
    glVertex3f( 0.5f, 0.5f, 0.5f); // Bottom Right Of The Quad (Top)
    glColor3f(1.0f,1.0f,0.0f); // Set The Color To Orange
    glVertex3f( 0.5f,-0.5f, 0.5f); // Top Right Of The Quad (Bottom)
    glVertex3f(-0.5f,-0.5f, 0.5f); // Top Left Of The Quad (Bottom)
    glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Bottom)
    glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Bottom)
    glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
    glVertex3f( 0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Front)
    glVertex3f(-0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Front)
    glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Front)
    glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Front)
    glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
    glVertex3f( 0.5f,-0.5f,-0.5f); // Top Right Of The Quad (Back)
    glVertex3f(-0.5f,-0.5f,-0.5f); // Top Left Of The Quad (Back)
    glVertex3f(-0.5f, 0.5f,-0.5f); // Bottom Left Of The Quad (Back)
    glVertex3f( 0.5f, 0.5f,-0.5f); // Bottom Right Of The Quad (Back)
    glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
    glVertex3f(-0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Left)
    glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Left)
    glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Left)
    glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Left)
    glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
    glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Right)
    glVertex3f( 0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Right)
    glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Right)
    glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Right)
    glEnd(); // Done Drawing The Quad

    //draw the lines
    glLoadIdentity();
    glBegin(GL_LINE_LOOP);
    glColor3f(0.0f,0.5f,1.0f);
    glVertex3d(-1,1,-2.5);
    glVertex3d(1,1,-2.5);
    glVertex3d(1,-1,-2.5);
    glVertex3d(-1,-1,-2.5);
    glEnd();

  2. #2

    Re: Maybe Simple problem,but strange to me

    I guess you are having an error somewhere else in your code. There is no reason that can explain the problem in the code you show.
    I had a similar bug once. I thought GL was bugged, but in fact the error was in another part of my code : I was reading/writting data out of an array.
    I think this made the system unstable and it could crash at anytime.

Similar Threads

  1. Strange alpha Problem in simple scene
    By uwi2k2 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-16-2014, 07:02 PM
  2. Replies: 1
    Last Post: 01-05-2007, 11:12 PM
  3. Replies: 5
    Last Post: 01-05-2007, 07:49 PM
  4. Strange thing happening - This simple teapot is distorted!!!
    By jojo555 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-14-2004, 01:11 PM
  5. a simple but strange problem
    By Nil_z in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-21-2003, 09:07 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