5

I'm trying to find a way to rubber band in OpenGL and Visual Studio C++. The problem I'm coming across is some Win 7 computers (i.e. My boss') won't allow me to read or draw to the front buffer thus killing drawing straight to it.

glDrawBuffer( GL_FRONT );
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp( GL_XOR );
glPolygonMode(GL_FRONT, GL_LINE);
glRecti(X0, Y0, X1, Y1);
X1 = X;
Y1 = Y;
glRecti(X0, Y0, X1, Y1);
*//Doesn't draw lines*

or copying the front buffer to the back buffer (redrawing to it would take to long) calling a swapbuffers drawing and then swaping agian

glReadBuffer( GL_FRONT );
glDrawBuffer( GL_BACK );
glCopyPixels(0, 0, Width, Height, GL_COLOR);

glEnable(GL_COLOR_LOGIC_OP);
glLogicOp( GL_XOR );
glPolygonMode(GL_BACK, GL_LINE);
SwapBuffers(hdc);
glRecti(X0, Y0, X1, Y1);
X1 = X;
Y1 = Y;
glRecti(X0, Y0, X1, Y1);
SwapBuffers(hdc);   
*//Doesn't display original drawing*

any ideas?

genpfault
  • 51,148
  • 11
  • 85
  • 139
kaiken
  • 77
  • 7
  • 2
    Are there any errors? Please experiment with glGetError(). – R. Martinho Fernandes Jul 27 '11 at 17:30
  • @Martinho there are no errors – kaiken Jul 27 '11 at 17:59
  • 1
    What does it mean to "rubber band"? Can you add an explanation of exactly what you're trying to accomplish to your question? – Merlyn Morgan-Graham Jul 31 '11 at 06:58
  • Can you post a complete working example with a GLUT window? It won't be hard to make it work, the bother is to type out all the glue and test it – rep_movsd Jul 31 '11 at 17:18
  • @Merlyn by rubber band I mean to draw a selection box over an area. Most paint and image programs do this. – kaiken Aug 01 '11 at 16:20
  • you copy pixels between buffers, but then do nothing to change content of any of them, and swap them (first swap), than draw something (and thus changing content of back buffer), and then swap it (now it good reason for it). Second example lines 6-9 do nothing to alter content of 2 identical buffers, so why do you perform swap??? – przemo_li Aug 12 '11 at 15:46

1 Answers1

1

I'd do it like this:

  • draw the scene to an offscreen buffer (back buffer or other)
  • use glReadPixels to read the image to main memory
  • make a texture out of the image in main memory

After this, to draw the image on screen, you can just draw a single quad covering the whole render area, textured with created texture. This way there's no need to re-render the actual scene when drawing the image to screen.

Modern OpenGL implementations can also render to texture, with no need to move the image to main memory and back. Then again, if rendering the scene is already slow, the performance difference here won't be noticeable.

Niko Kiirala
  • 194
  • 3