Re: weird opengl/mfc problem
I don't know how is your code, but must be:
//initializations:
int CYourGLWindow:OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_hDC = ::GetDC(this->m_hWnd); //get DC from window
SetPixelFormat(m_hDC, m_nPixelFormat, NULL); //set pfd ...
m_hRC = wglCreateContext(m_hDC); ///create rendering context
... bla bla bla... OGL initializations.....
//now init the timer
SetTimer(IDC_TIMER, 100, NULL);
}
//this is Timer func:
void CGLWindow::OnTimer(UINT nIDEvent)
{
InvalidateRect(NULL); //you must invalidate Rect of your glWindow
CWnd::OnTimer(nIDEvent);
}
//OnPaint func:
void CYourGLWWindow::OnPaint()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw rotating cube for example.....
// static float fX = 0.0f; etc...
SwapBuffers(m_hDC);
ValidateRect(NULL);
}
Bye
Re: weird opengl/mfc problem
My OpenGL initialization code is very similar. However, the problem is that the Timer and Paint functions are in different classes. The timer is meant to be running in the Dialog that contains my opengl control. E.g.:
Code:
MyDialog::OnTimerStartButton() {
SetTimer(0, 100, NULL);
}
MyDialog::OnTimer(){
// ... some sort of work done here
}
MyOpenGLControl::OnPaint() {
// Draw something here
}
For some reason, the painting works if I don't use a CPaintDC, but then the timer doesn't work. If I do use a CPaintDC, then the timer works, but the rendering doesn't.
Re: weird opengl/mfc problem
Actually, given your advice I just solved the problem. I left out a pesky "ValidateRect" at the end of my paint function. Everything seems to be working now. Thanks!
Re: weird opengl/mfc problem
Re: weird opengl/mfc problem