opengl rendering

Started by
3 comments, last by shreejan 15 years, 10 months ago
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().
Advertisement
I guess that logic could work, but have you thought about rendering to a completly seperate framebuffer and drawing from that on update?
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.
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/
Thanks RIZAX

I will have a look at the links provided.

This topic is closed to new replies.

Advertisement