PDA

View Full Version : Maybe Simple problem,but strange to me



Sourpotato
05-20-2003, 04:39 PM
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();

morbac
05-22-2003, 02:09 AM
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.