Jump to content
  • Advertisement
Sign in to follow this  
GoldenMustang

OpenGL Opengl+MFC(sorry if this topic isn't for this forum)-problems after resizing window

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

So, I've got a problem after resizing window in mfc project. This is the code: void CCubeView::DrawGraphic() { CRect clientRect; GetClientRect(&clientRect); glViewport(0, 0, clientRect.right, clientRect.bottom); glMatrixMode(GL_PROJECTION); glOrtho(0,1,0,1,0,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f (1.0, 0.0, 0.5); glBegin(GL_LINES); glVertex3f( 0.5, 0.5, 0 ); //полезная область будет от 0 до 1 glVertex3f( 0 , 0, 0 ); glEnd(); } void CCubeView::OnDraw(CDC* pDC) { CCubeDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); glClearColor (0,0,0,0); glClear (GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT); DrawGraphic(); SwapBuffers(pDC->m_hDC); } In the beginning of a program the line that is described in func DrawGraphic() is painted in a window. after calling a modal dialog in a program, function InvalidateRect(NULL,FALSE) is called. After calling invalidateRect the line isn't painted in a window. If there is a resizing in a program (I think this way the func InvalidateRect is called aswell) the line isn't painted too. What it can be?

Share this post


Link to post
Share on other sites
Advertisement
Try debugging and see if the DrawGraphic gets called when it's supposed to be called. My advice - think outside the box. :)

Share this post


Link to post
Share on other sites
Yes, I use debug and the func is called. So,sth wrong happens during InvalidateRect(...). what is think outside the box? it's just like to take coffe and do sth else while thinking over the problem?

Share this post


Link to post
Share on other sites
The problem with MFC (in this case with Opengl) is the need to become familiar/intimate with how/when the messaging system works to update various elements (i.e what happens without ensuring a message is sent to do something (i.e. system will send message(s) automagically) and when you need to explicitly send a message to make something happen.

There are few ways to deal with this problem. Typically I have found many examples of/and use the CWnd::RecalcLayout() function (but typically when the state of something in a CCubeView needs to be updated/changed). [Google on
CWnd::RecalcLayout() for more info].

In your case I would try CCubeView::RecalcLayout() from within or
at sometime after the dialog has finished doing what it does: it should put your
CCubeView back into the reasonable state it was in before the dialog was put into action.

Try it a see. If it helps, then good I guess.
But you may also want to take a minimalist's approach and substitute it for any other better solutions (e.g. performance wise?) that may come along/be recommended (depending on the nature of your app).

Share this post


Link to post
Share on other sites
void CCubeView::DrawGraphic()
{
// ...

// the last two parameters of glViewport() are
// widith and height of your view port.
glViewport(0, 0, clientRect.width(), clientRect.height());

// ...
}


void CCubeView::OnDraw(CDC* pDC)
{
// insert this line before you draw with OpenGL
// m_hGLContext is the OpenGL context
wglMakeCurrent(pDC->m_hDC,m_hGLContext);


// your drawing code
// ...
}

Share this post


Link to post
Share on other sites
Think outside the box means to look for a bug somewhere else in your code. The drawing functions probably don't contain a bug. When running your application, try to drag your window completely off screen and then back. It should make the window redraw itself. I remember when I was using MFC and OpenGL, I made an ugly hack in a timer, which would always call InvalidateRect(0, 0). That way the window always redrew itself.

Can you show us the code which calls the InvalidateRect function?

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!