i want to program a simple drag'n'drop mechanism for a opengl shape but
it suffers from an incredible strong flickering although i am using
double-buffering.
that's the mouse listener (GLUT):
void onMousePressedMove(int x, int y){
GLdouble wx,wy,wz,realY;
GLint viewport[4];
(...)
realY=viewport[3]-(GLint)y-1;
gluUnProject(x,realY,0.0,modelMatrix,projectionMatrix,viewport,&wx,&wy,&wz);
transX=wx-startX;
transY=wy-startY;
transZ=wz-startZ;
if(getTick()==1)
{
startX=wx;
startY=wy;
startZ=wz;
glutPostRedisplay();
}
}
getTick() only calls the function at a constant framerate of about
30fps. I did this because I experienced the flickering before when I
called glutPostRedisplay() directly and I assumed that the sampling rate
oft the mouse is much higher than the screen's.
the display function:
void display(void)
{
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glPopMatrix();
//glPushMatrix();
glTranslated(transX,transY,transZ);
image(startX,startY,startZ);
glutSwapBuffers();
}
I assumed that there might be a problem that I am calling
glutPostRedisplay() too often and I therefore interrupt the drawing
process. But it somehow didn't get better with the FPS-limited
approach... Please help me! I guess I just misunderstood a simple
conceptual issue. :-(
Thanks in advance ;-)
David
|
|
0
|
|
|
|
Reply
|
d.zellhoefer (8)
|
10/21/2004 12:37:14 PM |
|
David Zellhoefer wrote:
> i want to program a simple drag'n'drop mechanism for a opengl shape but
> it suffers from an incredible strong flickering although i am using
> double-buffering.
>
> that's the mouse listener (GLUT):
>
> void onMousePressedMove(int x, int y){
> GLdouble wx,wy,wz,realY;
> GLint viewport[4];
> (...)
> realY=viewport[3]-(GLint)y-1;
> gluUnProject(x,realY,0.0,modelMatrix,projectionMatrix,viewport,&wx,&wy,&wz);
>
>
> transX=wx-startX;
> transY=wy-startY;
> transZ=wz-startZ;
>
> if(getTick()==1)
> {
> startX=wx;
> startY=wy;
> startZ=wz;
> glutPostRedisplay();
> }
> }
>
> getTick() only calls the function at a constant framerate of about
> 30fps. I did this because I experienced the flickering before when I
> called glutPostRedisplay() directly and I assumed that the sampling rate
> oft the mouse is much higher than the screen's.
>
> the display function:
>
> void display(void)
> {
> glClearColor(0,0,0,1);
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>
> //glPopMatrix();
> //glPushMatrix();
> glTranslated(transX,transY,transZ);
> image(startX,startY,startZ);
>
> glutSwapBuffers();
> }
>
> I assumed that there might be a problem that I am calling
> glutPostRedisplay() too often and I therefore interrupt the drawing
> process. But it somehow didn't get better with the FPS-limited
> approach... Please help me! I guess I just misunderstood a simple
> conceptual issue. :-(
What's your operating system? Linux?
Try to call export __GL_SYNC_TO_VBLANK=1
in the shell before you start your program (in the same shell!).
That tells OpenGL to swap the buffers while the vertical retrace
takes place. Under windows, this is the default,
but not under Linux (as far as I know).
Regards,
Toni
--
for mail, mirror: ed.lausivksa@elielb
|
|
0
|
|
|
|
Reply
|
Antonio
|
10/21/2004 12:57:30 PM
|
|
Antonio Bleile wrote:
> David Zellhoefer wrote:
>
>
>
> What's your operating system? Linux?
>
> Try to call export __GL_SYNC_TO_VBLANK=1
> in the shell before you start your program (in the same shell!).
>
> That tells OpenGL to swap the buffers while the vertical retrace
> takes place. Under windows, this is the default,
> but not under Linux (as far as I know).
>
> Regards,
>
> Toni
>
It is Windows and I already tried to switch on VSync for all
applications at my driver settings dialog. I also tried the code on a
different machine.
david
|
|
0
|
|
|
|
Reply
|
David
|
10/21/2004 1:05:24 PM
|
|
"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> a �crit dans le message de
news: 2tpoopF23giogU1@uni-berlin.de...
>i want to program a simple drag'n'drop mechanism for a opengl shape but it
>suffers from an incredible strong flickering although i am using
>double-buffering.
Using glLogicOp (xor mode) twice enable to display and erase a shape
without changing the frame buffer.
Probably, you will have to disable the depth buffer...
CM
|
|
0
|
|
|
|
Reply
|
Charles
|
10/21/2004 1:20:52 PM
|
|
David Zellhoefer wrote:
>
> It is Windows and I already tried to switch on VSync for all
> applications at my driver settings dialog. I also tried the code on a
> different machine.
>
Are you sure you have double buffers?
Even with bad vsync settings you won't get
"incredible strong flickering", only tearing
of the image.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. The Cheat is not dead!
|
|
0
|
|
|
|
Reply
|
fungus
|
10/21/2004 1:22:50 PM
|
|
Charles Melice wrote:
>
> Using glLogicOp (xor mode) twice enable to display and erase a shape
> without changing the frame buffer.
What do you mean? Should I include the glLogicOp between the glBegin()
and glEnd()? Could you post a code hint?
>
> Probably, you will have to disable the depth buffer...
I tried this as well, but :-(
|
|
0
|
|
|
|
Reply
|
David
|
10/21/2004 1:32:34 PM
|
|
fungus wrote:
> David Zellhoefer wrote:
>
>>
>> It is Windows and I already tried to switch on VSync for all
>> applications at my driver settings dialog. I also tried the code on a
>> different machine.
>>
>
> Are you sure you have double buffers?
>
> Even with bad vsync settings you won't get
> "incredible strong flickering", only tearing
> of the image.
>
>
Yes, when I run a simple animation using the idle() function I
experience no flickering at all.
david
|
|
0
|
|
|
|
Reply
|
David
|
10/21/2004 1:33:25 PM
|
|
Charles Melice wrote:
>
> Using glLogicOp (xor mode) twice enable to display and erase a shape
> without changing the frame buffer.
>
Ugly, ugly, ugly.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. The Cheat is not dead!
|
|
0
|
|
|
|
Reply
|
fungus
|
10/21/2004 1:34:38 PM
|
|
David Zellhoefer wrote:
> fungus wrote:
>
>> Are you sure you have double buffers?
>>
>
> Yes, when I run a simple animation using the idle() function I
> experience no flickering at all.
>
That's nice....but what value does
glGetIntegerv(GL_DOUBLEBUFFER, ...)
return?
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. The Cheat is not dead!
|
|
0
|
|
|
|
Reply
|
fungus
|
10/21/2004 2:10:06 PM
|
|
"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> a �crit dans le message de
news: 2tps0iF22b1rkU1@uni-berlin.de...
> Charles Melice wrote:
>
>
>>
>> Using glLogicOp (xor mode) twice enable to display and erase a shape
>> without changing the frame buffer.
>
> What do you mean? Should I include the glLogicOp between the glBegin() and
> glEnd()? Could you post a code hint?
I don't have code sample.
Another system I have used:
-Draw normal shape in the back buffer.
-Draw temporary shape in the front buffer.
-Use SwapBuffers (copy -not exchange- mode) to erase only
the front shape.
That enable to not redraw all the objects...
>>
>> Probably, you will have to disable the depth buffer...
>
> I tried this as well, but :-(
|
|
0
|
|
|
|
Reply
|
Charles
|
10/21/2004 2:11:58 PM
|
|
fungus wrote:
> David Zellhoefer wrote:
>
>> fungus wrote:
>>
>>> Are you sure you have double buffers?
>>>
>>
>> Yes, when I run a simple animation using the idle() function I
>> experience no flickering at all.
>>
>
> That's nice....but what value does
> glGetIntegerv(GL_DOUBLEBUFFER, ...)
> return?
>
>
>
it returns 1. :-(
|
|
0
|
|
|
|
Reply
|
David
|
10/21/2004 2:28:30 PM
|
|
David Zellhoefer wrote:
>>> fungus wrote:
>>>
>>>> Are you sure you have double buffers?
>>>>
>>>
>>> Yes, when I run a simple animation using the idle() function I
>>> experience no flickering at all.
>>>
>>
>> That's nice....but what value does
>> glGetIntegerv(GL_DOUBLEBUFFER, ...)
>> return?
>>
>>
>>
> it returns 1. :-(
does anyone know if there could be a problem using GLUT with windows
2000??? I already programmed a GTA-like game in OpenGL but when I am
using the mouse everything goes wrong (or flickers...).
David
|
|
0
|
|
|
|
Reply
|
David
|
10/21/2004 2:32:44 PM
|
|
Just a second:
Are you absolutely sure, that before the glSwapBuffers, you drew
everything below the dropdown box as well as the box itself?
Add a "Sleep(1000);" after each call to glSwapBuffers.
I bet it's this.
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
|
|
0
|
|
|
|
Reply
|
Gernot
|
10/21/2004 2:46:19 PM
|
|
Gernot Frisch wrote:
> Just a second:
> Are you absolutely sure, that before the glSwapBuffers, you drew
> everything below the dropdown box as well as the box itself?
> Add a "Sleep(1000);" after each call to glSwapBuffers.
>
> I bet it's this.
>
>
i thought so, that's the actual code:
void display(void)
{
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glTranslated(transX,transY,transZ);
image(startX,startY,startZ);
glutSwapBuffers();
}
image() draws a simple plane. transX/Y/Z are derrived from the mouse
movement.
as long the user moves the mouse (while holding down a mouse button) the
mouse event handler calls glutPostRedisplay() to notify that the scene
has to be drawn again.
i am pretty sure that the error lies somwhere there. i assumed that the
sampling rate of the input device and the output device(screen) differ
too much so OpenGL gets interrupted while swapping buffers. (if this is
possible.)
cheers,
david
|
|
0
|
|
|
|
Reply
|
David
|
10/21/2004 3:00:37 PM
|
|
David Zellhoefer wrote:
> fungus wrote:
>
>> That's nice....but what value does
>> glGetIntegerv(GL_DOUBLEBUFFER, ...)
>> return?
>>
> it returns 1. :-(
Surely that's a ":-)"...
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. The Cheat is not dead!
|
|
0
|
|
|
|
Reply
|
fungus
|
10/21/2004 3:04:55 PM
|
|
Charles Melice wrote:
>>
>>>Using glLogicOp (xor mode) twice enable to display and erase a shape
>>>without changing the frame buffer.
>>
>>What do you mean? Should I include the glLogicOp between the glBegin() and
>>glEnd()? Could you post a code hint?
>
>
> I don't have code sample.
>
> Another system I have used:
>
> -Draw normal shape in the back buffer.
> -Draw temporary shape in the front buffer.
> -Use SwapBuffers (copy -not exchange- mode) to erase only
> the front shape.
>
> That enable to not redraw all the objects...
>
This doesn't solve any problems. With backbuffering
there should be no flicker. Period.
I think your problem isn't with OpenGL, it's
with the rest of your program.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. The Cheat is not dead!
|
|
0
|
|
|
|
Reply
|
fungus
|
10/21/2004 3:07:38 PM
|
|
> void display(void)
> {
>
> glClearColor(0,0,0,1);
// Maybe leaving this line out might help.. I've never worked with
GLU(T)
> glClear(GL_COLOR_BUFFER_BIT);
// Surely this would help
DrawMySceneBelowTheImage();
> glTranslated(transX,transY,transZ);
> image(startX,startY,startZ);
> glutSwapBuffers();
> }
|
|
0
|
|
|
|
Reply
|
Gernot
|
10/21/2004 3:32:03 PM
|
|
David Zellhoefer wrote:
> Gernot Frisch wrote:
>
>> Just a second:
>> Are you absolutely sure, that before the glSwapBuffers, you drew
>> everything below the dropdown box as well as the box itself?
>> Add a "Sleep(1000);" after each call to glSwapBuffers.
>>
>> I bet it's this.
>>
>>
> i thought so, that's the actual code:
>
> void display(void)
> {
>
> glClearColor(0,0,0,1);
> glClear(GL_COLOR_BUFFER_BIT);
>
> glTranslated(transX,transY,transZ);
> image(startX,startY,startZ);
>
> glutSwapBuffers();
> }
>
> image() draws a simple plane. transX/Y/Z are derrived from the mouse
> movement.
> as long the user moves the mouse (while holding down a mouse button) the
> mouse event handler calls glutPostRedisplay() to notify that the scene
> has to be drawn again.
>
> i am pretty sure that the error lies somwhere there. i assumed that the
> sampling rate of the input device and the output device(screen) differ
> too much so OpenGL gets interrupted while swapping buffers. (if this is
> possible.)
just an idea: have you called glutSwapBuffers() twice? What happens
if you just remove it from the display() func?
Toni
--
for mail, mirror: ed.lausivksa@elielb
|
|
0
|
|
|
|
Reply
|
Antonio
|
10/21/2004 3:39:52 PM
|
|
Hi!
Well, after causing a lot of discussion about double buffering I decided
to change the topic slightly.
First the source (using GLUT):
http://www.f4.fhtw-berlin.de/~s0502726/new_approach.c
I am going to implement a user interface using OpenGL including a
drag'n'drop mechanism for boxes (that will become images later).
Unfortunately the drag'n'drop mechanism suffers from extreme flickering
although I am using double-buffering.
For example:
I am holding down a mouse button at the screen and move the mouse. This
leads to a movement of the white plane (fine!), but it flickers like
hell :-( .
Sometimes the plane itself disapears completly if you release the mouse
button at a unlucky moment.
If I use a keyboard as input device everything works fine.
The question is now: did someone out there program a drag'n'drop capable
user interface in OpenGL??? or something related to my problem? any hints?
I had the assumption that it could be related to the difference of the
sample rate of the input device and the screen, but I figured out that
mouses get sampled with ca. 80 Hz if they are good.
I have really no clue, but the drag'n'drop mechanism is crucial for my
application.
Cheers,
David
|
|
0
|
|
|
|
Reply
|
David
|
10/22/2004 6:50:23 PM
|
|
David Zellhoefer wrote:
>
> The question is now: did someone out there program a drag'n'drop capable
> user interface in OpenGL???
>
Ne.
> I had the assumption that it could be related to the difference of the
> sample rate of the input device and the screen, but I figured out that
> mouses get sampled with ca. 80 Hz if they are good.
>
> I have really no clue, but the drag'n'drop mechanism is crucial for my
> application.
I think your problem is that you're calling
OpenGL functions inside GLUT event handlers
and they don't always work.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. The Cheat is not dead!
|
|
0
|
|
|
|
Reply
|
fungus
|
10/22/2004 7:04:53 PM
|
|
"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message
news:2tt30dF23rdriU1@uni-berlin.de...
> Hi!
>
> Well, after causing a lot of discussion about double buffering I decided
> to change the topic slightly.
>
> First the source (using GLUT):
> http://www.f4.fhtw-berlin.de/~s0502726/new_approach.c
>
> I am going to implement a user interface using OpenGL including a
> drag'n'drop mechanism for boxes (that will become images later).
> Unfortunately the drag'n'drop mechanism suffers from extreme flickering
> although I am using double-buffering.
>
> For example:
> I am holding down a mouse button at the screen and move the mouse. This
> leads to a movement of the white plane (fine!), but it flickers like
> hell :-( .
> Sometimes the plane itself disapears completly if you release the mouse
> button at a unlucky moment.
> If I use a keyboard as input device everything works fine.
>
> The question is now: did someone out there program a drag'n'drop capable
> user interface in OpenGL??? or something related to my problem? any hints?
>
> I had the assumption that it could be related to the difference of the
> sample rate of the input device and the screen, but I figured out that
> mouses get sampled with ca. 80 Hz if they are good.
>
> I have really no clue, but the drag'n'drop mechanism is crucial for my
> application.
>
> Cheers,
>
> David
>
You have a logic problem in your application, it's just that simple.
The fact the the object disappears proves it, if you think about it.
-jbw
|
|
0
|
|
|
|
Reply
|
JB
|
10/23/2004 2:50:48 AM
|
|
JB West wrote:
>
>
> You have a logic problem in your application, it's just that simple.
> The fact the the object disappears proves it, if you think about it.
>
> -jbw
>
I am pretty sure about this. But I don't get it! It must be possible to
implement a drag'n'drop effect.
1) Draw a scene and refresh it from time to time.
2) if a mouse move appears change the translation for the scene and
recall the drawing methods.
3) swap buffers.
That's how it should work in my naive world. Does anyone have a clue
what my logic problem might be, although we are probably off-topic?
David
|
|
0
|
|
|
|
Reply
|
David
|
10/23/2004 11:06:49 AM
|
|
David Zellhoefer <d.zellhoefer@fhtw-berlin.de> writes:
> 1) Draw a scene and refresh it from time to time.
> 2) if a mouse move appears change the translation for the scene and
> recall the drawing methods.
> 3) swap buffers.
1. Clear the back buffer.
2. Draw your scene into the back buffer.
3. Swap buffers.
4. Repeat at step 1.
In step 2. you can update the transformation for a dragged object, or you
can do that after step 3.
HTH,
Jens.
--
mailto:jjk@acm.org As the air to a bird, or the sea to a fish,
http://www.bawue.de/~jjk/ so is contempt to the contemptible. [Blake]
|
|
0
|
|
|
|
Reply
|
Jens
|
10/23/2004 1:01:07 PM
|
|
David Zellhoefer wrote:
> Hi!
>
> Well, after causing a lot of discussion about double buffering I decided
> to change the topic slightly.
>
> First the source (using GLUT):
> http://www.f4.fhtw-berlin.de/~s0502726/new_approach.c
>
> I am going to implement a user interface using OpenGL including a
> drag'n'drop mechanism for boxes (that will become images later).
> Unfortunately the drag'n'drop mechanism suffers from extreme flickering
> although I am using double-buffering.
>
> For example:
> I am holding down a mouse button at the screen and move the mouse. This
> leads to a movement of the white plane (fine!), but it flickers like
> hell :-( .
> Sometimes the plane itself disapears completly if you release the mouse
> button at a unlucky moment.
> If I use a keyboard as input device everything works fine.
>
> The question is now: did someone out there program a drag'n'drop capable
> user interface in OpenGL??? or something related to my problem? any hints?
We do this all time, e.g. move a 2d overlay around the screen, it
does not flicker when using doublebuffering (and yes, we use the mouse).
Just a suggestion: Get rid of glut, it's anyway only useful for small
applications. Check out trolltech's qt for example.
Regards,
Toni
--
for mail, mirror: ed.lausivksa@elielb
|
|
0
|
|
|
|
Reply
|
Antonio
|
10/23/2004 2:03:49 PM
|
|
"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message
news:2tus77F24sfp1U1@uni-berlin.de...
> JB West wrote:
> >
> >
> > You have a logic problem in your application, it's just that simple.
> > The fact the the object disappears proves it, if you think about it.
> >
> > -jbw
> >
>
> I am pretty sure about this. But I don't get it! It must be possible to
> implement a drag'n'drop effect.
>
> 1) Draw a scene and refresh it from time to time.
> 2) if a mouse move appears change the translation for the scene and
> recall the drawing methods.
> 3) swap buffers.
>
> That's how it should work in my naive world. Does anyone have a clue
> what my logic problem might be, although we are probably off-topic?
>
> David
>
It has to be that your "refresh from time to time" and your mouse-draw
are interfering with each other
I'd personally never redraw in a mouse callback if I also had a free-running
redraw (like an idle function). Rather, I'd just have the mouse callback
change the transform -- and do nothing else. I'd let the idle function
or periodic redraw take care of updating the scene.
Are you assuming that the periodic redraw is stopping while you are dragging
?
Do you actually stop it as long as , say, the mouse button is down ?
Do you realize that a mouse callback isn't sampled, rather, it only gets
called
when the mouse moves?
-jbw
|
|
0
|
|
|
|
Reply
|
JB
|
10/23/2004 3:37:24 PM
|
|
|
24 Replies
400 Views
(page loaded in 0.243 seconds)
|