PDA

View Full Version : rubberbanding in opengl



princeoflightning
02-24-2004, 01:11 AM
Hi, I'm stuck with yet another problem in Opengl.
Here we go-
I need to use rubberbanding in my graphics package that is more or less similar to the Paint Brush app in Windows.
Right now, i've implemented it somewhat like this:
1)Enter XOR mode.
2)Draw the line to display it.
3)And redraw the old line(to erase it) and redraw it(to draw the new line) whenever the mouse motion callback function is invoked.
The code works just fine, but for the flicker when I move the mouse rapidly.

It gets worse for the rectangle, worser for the circle( and ellipse) and worst for the bezier curve (for the bezier I cant just see the curve at certain times.)

The code is similar to F.S. hill Jr' code for rubberbanding.

Ya, I cant afford a SGI workstation until I get a solution for this prob!!

My comp has a TNT2 (AGP) as the graphics accelerator (decelerator!!).
HELP!!!!

AdrianD
02-24-2004, 01:05 PM
are you using doublebuffering ?

princeoflightning
02-25-2004, 04:12 AM
Nope i'm not doing so at present coz i'm stuck trying to implement it- fullscreen mode activation occurs only after I send an event to the mouse.
That should not happen- Fullscreen mode should be activated without any stimuli.

AdrianD
02-25-2004, 05:23 AM
Originally posted by princeoflightning:
Nope i'm not doing so at present coz i'm stuck trying to implement it....

But you have to use it, to avoid the flickering.
plaese go to the beginner forum, and ask for doublebuffering or just take a look at _any_ code for openGL... its one of the most basic functions.(take a look at the codeexamples at this site...)

jwatte
02-25-2004, 05:27 PM
I agree that "beginners" is probably better.

double-buffering != full-screen. SWAP_COPY is used when not full-screen (and is usually quite fast).

princeoflightning
02-26-2004, 04:23 AM
Thanks for mentioning double-buffering != full-screen.
But does it not work in full-screen mode?
If so , why?
And can you suggest any other alternative that for full-screen mode operation, since I've already got the program use double-buffering in windowed mode(it works even in maximized mode).
using glutSwapBuffers() just creates problems.

princeoflightning
02-26-2004, 04:29 AM
Oops, I meant using glutFullScreen();
just creates problems.

nexusone
02-26-2004, 05:09 AM
I think part of the problem is maybe you are trying to do it in the traditional 2D way of rubberbanding. And not leting openGL do the low level work for you. You have to think diffrently when using OpenGL, else you will see a real slow down when not done in the correct openGL way.

First openGL renders the scene, so everything should be redrawn each time the scene is updated.

So we clear the screen each update and draw the line in a new location and redraw past objects.

For a 2D paint program you can have unlimited undo's by this aproach. You store each line in a array, and redraw them each update. OpenGL should be able to do this without any trouble or flicker.

Another aproach is that you use what is called render to a texture.

Your past lines, circles, etc are drawn onto a texture. The texture is only updated once the mouse button is released.

Work like this:
You draw a textured quad with our image buffer(texture).
then you draw your rubberband effect over it, so that you only have a few object being draw at any time.

For a undo you can have layered qauds, example 5 undo's

Layer 1. Draw surface
Layer 2. Undo surface 1
Layer 3. Undo surface 2
Layer 4. Undo surface 3
Layer 5. Undo surface 4
Layer 6. Finnal image

That will happen as new lines or objects are drawn, the layers will rotate down.
Layer 5 will merge with 6 so can no longer be undone.
Layer 4 is copied to 5, 3 to 4 and so on.


[This message has been edited by nexusone (edited 02-26-2004).]

princeoflightning
02-26-2004, 05:14 AM
Now, that's probably what I'm searching for.
Can you lead to sites that teach those?
Puhleese.

nexusone
02-26-2004, 10:13 AM
nehe.gamedev.net is a good place to start.

From his tutors you will learn how to create a texture map, load images, blending (which you will need for layers), etc.



Originally posted by princeoflightning:
Now, that's probably what I'm searching for.
Can you lead to sites that teach those?
Puhleese.