I am trying to draw a box on top of a QGLWidget i have inside a Qt application. This code works on a Solaris machine with OpenGL 1.3 but does not work on a Linux machine running RedHat 4 with OpenGL 2.0. I am allowing the user to use the mouse to draw a box on top of my QGLWidget. I have 3 sets of variables that are arrays containing 2 floats, an X and Y value. My ortho and viewport is all set up and working properly. I draw what I call an old box followed by the new box. I use blending with XOR so I can draw the box from the start point to the mouse. Then when the user moves the mouse, I want to redraw over the old box and draw the new box based on the mouse’s current position. The code to draw my box on top of all my other drawings looks like the following.
if( drawBox == true )
{
setAutoBufferSwap( false );
qglColor( mBoxColor );
glDrawBuffer( GL_FRONT );
glEnable( GL_LOGIC_OP );
glEnable( GL_BLEND );
glBlendEquationEXT( GL_LOGIC_OP );
glLogicOp( GL_XOR );
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glLineWidth( 2.0 );
// Erase the old box
glBegin( GL_LINE_LOOP );
glVertex3d( mBeginBox[0], mBeginBox[1], 0.0 );
glVertex3d( mBeginBox[0], mOldEndBox[1], 0.0 );
glVertex3d( mOldEndBox[0], mOldEndBox[1], 0.0 );
glVertex3d( mOldEndBox[0], mBeginBox[1], 0.0 );
glEnd( );
// Draw the new box based on the current mouse position
glBegin( GL_LINE_LOOP );
glVertex3d( mBeginBox[0], mBeginBox[1], 0.0 );
glVertex3d( mBeginBox[0], mEndBox[1], 0.0 );
glVertex3d( mEndBox[0], mEndBox[1], 0.0 );
glVertex3d( mEndBox[0], mBeginBox[1], 0.0 );
glEnd( );
glDisable( GL_LOGIC_OP );
glDisable( GL_BLEND );
glDrawBuffer( GL_BACK );
setAutoBufferSwap( true );
}
Can anybody see what is wrong in this code? My guess is it has something to do with the glBlendEquationEXT call. What I get is if my mBoxColor == Qt::black, I see every single black box that was drawn from stop to finish. It draws both boxes, but never XORs the boxes and erases the older of the boxes. Why does this work on Solaris 8 running OpenGL 1.3 but not RedHat 4 with OpenGL 2.0? I have also tried using glColor3f( 0.0, 1.0, 0.0 ); and this did not change anything except the color of the boxes. Thanks for all your help!