Jump to content
  • Advertisement
Sign in to follow this  
soumya_iiitc

OpenGL Double Rendering

This topic is 3710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!