The problem is OpenGL animation stops while any mouse button is clicked on the TForm component (border, caption ..). As soon as the mouse button released the animation goes on.
// Drawing Scene
void TMainForm::DrawGLScene()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawFigure();
SwapBuffers(hDC);
}
// Catching WM_PAINT
LRESULT CALLBACK NewWindowProcPanel3D(HWND hWnd, UINT msg, WPARAM w, LPARAM l)
{
switch (msg)
{
case WM_ERASEBKGND :
{
return 1;
}
case WM_PAINT :
{
MainForm->DrawGLScene();
}
default: return CallWindowProc((FARPROC)MainForm->OldWindowProcPanel3D,
hWnd, msg, w, l);
}
return 0;
}
// Creating OldWindowProcPanel3D -
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
OldWindowProcPanel3D = (WNDPROC)SetWindowLong(Panel3D->Handle,
GWL_WNDPROC, (long)NewWindowProcPanel3D);
}
// --------- *.h :
class TMainForm : public TForm
{
private:
HDC hDC;
public:
WNDPROC OldWindowProcPanel3D;
}
// Generation event WM_PAINT
void TMainForm::UpdateScene()
{
InvalidateRect(Panel3D->Handle, NULL, false);
}
// Animation code ( turn on 'animation' if RadioButton is chosen)
void __fastcall TMainForm::RadioGroupClick(TObject *Sender)
{
if (RadioGroup->ItemIndex == 0)
animation = false;
else if (RadioGroup->ItemIndex == 1)
animation = true;
if (animation)
{
while (animation)
{
Application->ProcessMessages();
UpdateScene();
}
}
}
What is to be done not to stop animation while changing sizes of the form, any usefull links?
That is because your main message loop is blocked and a secondary message loop is running while the window is being dragged/resized. The same thing happens when menus are active, modal dialogs are shown, etc. There is nothing you can do about that, that is simply how Windows operates.
BTW, assuming
Panel3D is a
TPanelor similar VCL control, you should subclass its
WindowProcproperty instead of
SetWindowsLong(), since the
TWinControl::Handle` property is not persistent.And you need to get rid of your use of
Application->ProcessMessages()
altogether. Never call that directly unless absolutely necessary.Try this instead: