glClear issue

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

glClear issue

caderape
Hello, i come here cuz i have a problem, and after hours of research, i can't find a solution.

I want to keep my previous draws and not clear all the canvas every time in the display() method. So i tried to remove the 'gl.glClear(GL2.GL_COLOR_BUFFER_BIT);'

But when i do that, the frame keep switching between the color i want, and the default color, black.

How can i fix it ? Thx

code on pastebin

Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

gouessej
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

caderape
hey, thx for reply.

I tried differents ways to swap buffers for make it work, but i keep getting a white screen with nothing. And somtimes i get the red screen as wanted, but no draw on it.

NB: the captcha is insane here. Took me like 2 minuts for confirm i'm not a bot..
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

gouessej
Administrator
If you want to paint only on demand, you will have to stop using an animator too and call GLAutoDrawable.display() by yourself.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

caderape
Still doesn't work, the double buffered keep annoy me when i invoke the display() method, and when i turn the double buffering to false, there's no draw on the screen.

What i want to do, for resume, it's create a circle to the mouse position, and if the mouse move, i create a new circle at the new postition, but not removing the circle from the old position.

In graphics2D, it's such a basic function, and i don't want to store every draw into a list for draw it again. Look like a waste of ressource.
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

gouessej
Administrator
It's doable in JOGL as a Graphics2D implementation based on JOGL exists:
https://github.com/brandonborkholder/glg2d

In my humble opinion, you could redraw everything at each frame and convert the mouse positions into geometries instead.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

caderape
GLG2D, this totally can do it for the 2D draw, but for the 3D ?

I can't store each draw made by each display, and repaint it everytime.

Or may be store the GL2 object in a global variable at the init() then get that objet in an external loop for draw.

the question is, can we draw outside of the display() method ?
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

caderape
This post was updated on .
Okay, i found a solution. A tricky one with double condition, but the point is, it work as i want.

The display is called two time at begining, so we have to skip the first frame, and clear the surface at the second display.
Then we can keep the background color and not have a flip between the black screen and the colored screen, and we can save old draws.

https://pastebin.com/d1uV2hmX

edit: nvm, when i change the color of the background while running, it start flipping with the old color. I will just give up. Thx for the help, i'm gonna try javaFX  
Reply | Threaded
Open this post in threaded view
|

Re: glClear issue

gouessej
Administrator
caderape wrote
GLG2D, this totally can do it for the 2D draw, but for the 3D ?
Yes but if you need much more information about this API, contact its maintainer. It's even possible to use an overlay above a JOGL drawable to use both JOGL and Graphics2D but it's not optimal.

caderape wrote
I can't store each draw made by each display, and repaint it everytime.
It's not what I meant. You can simply let JOGL draw your scene as trivially as possible, convert each new mouse positions into geometries (circles in your case), store their coordinates into a VBO and draw them with the rest of your scene. It's the easiest solution in my humble opinion.

caderape wrote
Or may be store the GL2 object in a global variable at the init() then get that objet in an external loop for draw.
No, don't do that, storing a GL instance is a bad practice (except locally for a local use) because you can be tempted to use it on the wrong thread, on the right thread but when the OpenGL isn't current or when the GL instance is no longer valid.

caderape wrote
the question is, can we draw outside of the display() method ?
Yes, it's possible but it's a bit tricky and probably not the way to go in your case.

caderape wrote
Okay, i found a solution. A tricky one with double condition, but the point is, it work as i want.

The display is called two time at begining, so we have to skip the first frame, and clear the surface at the second display.
Then we can keep the background color and not have a flip between the black screen and the colored screen, and we can save old draws.

https://pastebin.com/d1uV2hmX

edit: nvm, when i change the color of the background while running, it start flipping with the old color. I will just give up. Thx for the help, i'm gonna try javaFX
You didn't really try my suggestion.
Julien Gouesse | Personal blog | Website