Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't swap the buffers in the middle. Just draw the selection box on the back-buffer like everything else:</p> <p><a href="https://i.stack.imgur.com/TR8NG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TR8NG.png" alt="selection"></a> <br></p> <pre><code>#include &lt;GL/glut.h&gt; int StartX = -1; int StartY = -1; int EndX = -1; int EndY = -1; void mouse( int button, int state, int x, int y ) { if( button == GLUT_LEFT &amp;&amp; state == GLUT_DOWN ) { StartX = x; StartY = y; } if( button == GLUT_LEFT &amp;&amp; state == GLUT_UP ) { StartX = -1; StartY = -1; EndX = -1; EndY = -1; } } void motion( int x, int y ) { EndX = x; EndY = y; glutPostRedisplay(); } void display() { double w = glutGet( GLUT_WINDOW_WIDTH ); double h = glutGet( GLUT_WINDOW_HEIGHT ); glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); double ar = w / h; glOrtho( -2 * ar, 2 * ar, -2, 2, -1, 1 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glBegin( GL_TRIANGLES ); glColor3ub( 255, 0, 0 ); glVertex2i( -1, -1 ); glColor3ub( 0, 255, 0 ); glVertex2i( 1, -1 ); glColor3ub( 0, 0, 255 ); glVertex2i( 0, 1 ); glEnd(); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, w, h, 0, -1, 1 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); if( StartX &gt; 0 &amp;&amp; StartY &gt; 0 &amp;&amp; EndX &gt; 0 &amp;&amp; EndY &gt; 0 ) { glLogicOp(GL_XOR); glEnable(GL_COLOR_LOGIC_OP); glColor3f(1.0, 1.0, 1.0); glLineWidth(3.0); glBegin(GL_LINE_LOOP); glVertex2i(StartX, StartY); glVertex2i(EndX, StartY); glVertex2i(EndX, EndY); glVertex2i(StartX, EndY); glEnd(); glDisable(GL_COLOR_LOGIC_OP); } glutSwapBuffers(); } int main( int argc, char **argv ) { glutInit( &amp;argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); glutInitWindowSize( 640, 480 ); glutCreateWindow( "GLUT" ); glutDisplayFunc( display ); glutMouseFunc( mouse ); glutMotionFunc( motion ); glutMainLoop(); return 0; } </code></pre> <p>Since you weren't specifying them I added projection and modelview matrices.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload