Double Rendering

Started by
9 comments, last by soumya_iiitc 15 years, 10 months ago
Below is the brief problem description 1. I have created a small opengl application 2. I have implemented some small drawing function like rectangle and triangle 3. I am enabling user to draw rectangle/triangle on the application window. 4. At the same time this rectangle/triangle are also rendered into an off screen buffer (created using createDIBSection). 5. Then i am bliting this off screen buffer to a secondary monitor. I have to constantly change the current rendering context for drawing in to two buffers sequentially So i have to render constantly my drawing functions all the time? I can't stop rendering while i am not drawing anything. This is taking more CPU. What will be the possible solution? Thanks, Soumyadipta De
Advertisement
Quote:Original post by soumya_iiitc
3. I am enabling user to draw rectangle/triangle on the application window.


Sounds like you are misunderstanding the concept of double buffering. All drawing must be done to the back buffer, and at the end of the frame, the buffer is copied to the screen (that's how it works conceptually, in practice it might do something called Page Flipping, see the reference below).

See this article for more info (just ignore the Java-related bits).
I am taking about double buffering. I am using two buffer one for primary monitor and one buffer for secondary monitor.

I have used two buffers and one is off screen buffer.

I have to use any rendering loop twice two render simultaneously into two monitors.
Why don't you use PBOs or FBOs to render to one offscreen buffer then draw a textured fullscreen quad twice?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Yes, you are right, i am using Pbuffer for off screen rendering but i am facing performance problem with PBuffer.

when my secondary monitor size is large like 1920 x 1080 i have to create a PBuffer of that dimension and have to update that amount of data in each rendering loop. For larger PBuffer i am getting worst frame rate.

Yes, I am rendering twice and that's giving me lower performance.

Also i have to render my drawquad() all the time means even when i am not moving my mouse to draw anything. Because when i change the context to PBuffer it's clearing my main opengl windows screen and all rendered drawings gets cleared.

opengl window RC--- current
Drawquad()
PBuffer rendering RC--- current
Drawquad()

This avove for loop is running for ever. I just want to run this loop when i am drawing something.

am i doing anything wrong? please suggest me a valid flow.

Thanks,
Soumyadipta De
In Win32 programming, you would just update when you get a WM_PAINT message. In MFC, your OnPaint or OnDraw function gets called. If you are using some other thing, then you need to let users know if you want some sort of answer.
That would reduce CPU usage to almost 0%

Also, why are you creating a new thread every week or every day?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I am using PBuffer for off screen rendering but my off screen buffer dimension is not same as my opengl window dimension.

PBuffer dimension is larger than opengl window dimension.

I have to calculate the points according to PBuffer. Is there is any opengl API which automatically give the new points.

Also in my rendering loop each time i have to calculate opengl coordinate from window coordinate.

Is there any opengl command which will automatically give me opengl coordinate from window/screen coordinate?

When i click on my window it give me current mouse point suppose (500,500).

Then i have to calculate opengl window coordinate of this point in the range 0 to 1. Is there any opengl API for doing this?

Regards,
Soumyadipta De
AFAIK there's no OpenGL command to convert mouse coordinates from viewport to screen space, e.g. from 0-800 to -1 - +1. You could use the viewport information you can aquire via glGet() but the conversion should be done by yourself.

It's not that hard a task that you would need a special OpenGL function ;)

Or, if you just want to draw a line from mouse1 to mouse2 which both are given in viewport/window coordinates you could use an ortho projection matrix with dimensions equal to the viewport dimensions.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
I have found this link
gluUnProject

Can this link be used to convert window/screen coordinates to opengl coordinates?

If yes how can i use and compile my project with gluUnProject?
Is gluUnProject is an API or i need this library?

Regards,
Soumyadipta De
As far as your rendering problem goes, I would suggest that you save off two display buffers and two render buffers and just swap them when its update time. This way you control the update and not the system. This will use more memory but itll save you some processing. Figuring out when to swap/blit will be up to you and youll have to tune it - although if your already doing this, which I found unclear if you were then please ignore this :).

As far as gluUnproject goes - yes that will convert mouse coordinates for you, even though it is using the same process that you would use by hand to convert the coordinates - i have found it to be rather iffy especially when dealing with perspective projections in the far plane - as far as realtime updating is concerned, those values tend to head to zero really really quick. If you want to use this method then I'd suggest converting (if you havent done or arent doing it) everything to doubles to maintain precision. If you have problems you can always try and implement it yourself so you can tweak it.

This topic is closed to new replies.

Advertisement