Jump to content
  • Advertisement
Sign in to follow this  
shreejan

OpenGL opengl rendering

This topic is 3786 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

I have an application which uses OpenGL. In that application I have a function which will use gl* functions to render. The rendering is done only when the size of the view, orientation, position of the object in the view and/or camera changes. Otherwise I rely on the swapbuffer mechanism to display the correct image, hoping that the backbuffer is always ok. But this didn't work for all hardware. Currently I have been fixing the problem by rendering at OnDraw() message. But this fix is not a proper solution for my application as I have lots of object with so many polygons. I also have set PFD_SWAP_COPY while choosing PIXELFORMATDESCRIPTOR for open gl, so that the back buffer will always have the correct rendered image. But this also in vain, as I came to know that PFD_SWAP_COPY is just a hint to hardware driver. Currently I want to try this logic: 1) render using gl functions 2) capture the back buffer 3) use the captured back buffer to draw using windows GDI from OnDraw I cannot think about any solution so any help or reference will be highly appreciated. Following is the code snippet which I want to use: // gl functions to render void COGLView::Draw3DObject() { wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC); // gl functions gluLookAt(....); glBegin(....); //...... //...... //...... glEnd(); glFinish(); SwapBuffer(m_pDC->GetSafeHdc(), m_hRC); } void COGLView::OnDraw(CDC* pDC) { wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC); // swap the buffer for allowing windows to draw in this view SwapBuffers(m_pDC->GetSafeHdc()); glFinish(); } void COGLView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); if(cx <= 0 || cy <= 0) { return; } wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC); glViewport(0, 0, cx, cy); SetProjection(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); wglMakeCurrent(NULL, NULL); Draw3DObject(); } void COGLView::OnMouseMove(UINT nFlags, CPoint point) { BOOL bRefresh = TRUE; // free rotation in opengl x and y axes m_cCamera3D.RotateX(0.5 * (m_pntCursor.x - point.x)); m_cCamera3D.RotateY(0.5 * (m_pntCursor.y - point.y)); if(bRefresh == TRUE) { Draw3DObject(); } } But have been fixing by calling Draw3DObject() at OnDraw().

Share this post


Link to post
Share on other sites
Advertisement
I guess that logic could work, but have you thought about rendering to a completly seperate framebuffer and drawing from that on update?

Share this post


Link to post
Share on other sites
Thanks RIZAX for your interest.

I haven't thought about completely separate frame buffer. Do you mean by some kind of pBuffer, offscreen buffer with the help of some opengl extensions? I tried to find some information but didn't find such a good one which will help me to implement it. Else do you have any some other kinds of thing meaning completely separate frame buffer.

Thanks in advance, it will be of great help if you have any further information.

Share this post


Link to post
Share on other sites
Yes, I meant to an offscreen rendering location. I don't know if you have any constraints on the system, but you could - as that your trying to restrict updates - keep a copy of your current image in one framebuffer that is always referenced on a redraw and then another copy in a seperate buffer that you can use to draw in, effectively creating your own front and back buffer.

GD has some articles about using them:

http://www.gamedev.net/reference/articles/article2331.asp
http://www.gamedev.net/reference/programming/features/fbo2/

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!