opengl - Animation with VCL Component (WM_PAINT) -
the problem opengl animation stops while mouse button clicked on tform component (border, caption ..). mouse button released 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 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 done not stop animation while changing sizes of form, usefull links?
that because main message loop blocked , secondary message loop running while window being dragged/resized. same thing happens when menus active, modal dialogs shown, etc. there nothing can that, how windows operates.
btw, assuming panel3d a
tpanelor similar vcl control, should subclass its
windowprocproperty instead of
setwindowslong(), since the
twincontrol::handle` property not persistent.
and need rid of use of application->processmessages()
altogether. never call directly unless absolutely necessary.
try instead:
class tmainform : public tform { private: hdc hdc; bool animation; twndmethod oldwindowprocpanel3d; void drawglscene(); void __fastcall newwindowprocpanel3d(tmessage &message); public: __fastcall tmainform(tcomponent *owner); };
// creating oldwindowprocpanel3d - __fastcall tmainform::tmainform(tcomponent *owner) : tform(owner) { oldwindowprocpanel3d = panel3d->windowproc; panel3d->windowproc = &newwindowprocpanel3d; } // 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 void __fastcall tmainform::newwindowprocpanel3d(tmessage &message) { switch (message.msg) { case wm_erasebkgnd : { message.result = 1; break; } case wm_paint : { drawglscene(); if (animation) updatescene(); break; } default: { oldwindowprocpanel3d(message); break; } } } // generation event wm_paint void tmainform::updatescene() { panel3d->invalidate(); } // animation code ( turn on 'animation' if radiobutton chosen) void __fastcall tmainform::radiogroupclick(tobject *sender) { if (radiogroup->itemindex == 0) animation = false; else if (radiogroup->itemindex == 1) animation = true; if (animation) updatescene(); }
Comments
Post a Comment