PDA

View Full Version : Rendering Context With Docking



serkank
07-10-2014, 02:29 PM
i have to problem with rendering context.
iam using DGLOpengl Header and i found some Sample code.
and i am create Redering context with this code. its Render to a Tpanel




FDC:=GetDC(fChwnd);


InitOpenGL;
fpfd.dwFlags := PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER;
SetPixelFormat ( fDC, ChoosePixelFormat ( fDC, @fpfd ), @fpfd );
fhlgrc:=wglCreateContext ( fDC );
ActivateRenderingContext( fDC, fhlgrc, TRUE );
fStart := GetTickCount;
fElapsedTime:=1;
//load simple glsl shader
fglslsimpleprog := TGLSLProgram.Create();
fglslsimplevert := TGLSLShader.Create('Resources\Shaders\simple.vert' );
fglslsimplefrag := TGLSLShader.Create('Resources\Shaders\simple.frag' , GL_FRAGMENT_SHADER_ARB);
fglslsimpleprog.Attach(fglslsimplevert);
fglslsimpleprog.Attach(fglslsimplefrag);
fglslsimpleprog.Link;
fglslsimpleprog.Enable;
fglslsimpleprog.Set2F('resolution',fwidth*2,fheigh t*2);


when Docking or unDocking i call this this code


fpaint:=false;
fglslsimpleprog.Disable;


DeactivateRenderingContext;
ReleaseDC(fChwnd, fDC);
fchwnd:=hwnd;
fdc:=GetDC(FChwnd);
InitOpenGL;
fpfd.dwFlags := PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER;
SetPixelFormat ( fDC, ChoosePixelFormat ( fDC, @fpfd ), @fpfd );
fhlgrc:=wglCreateContext ( fDC );
ActivateRenderingContext( fDC, fhlgrc, TRUE );
fglslsimpleprog.Enable;
fpaint:=true;

while Panel Docking There isnt any Problem. But When Undock this Panel its not Render on Panel

What is wrong i dont understand . How i should change rendering Context ?

User137
08-10-2014, 07:40 AM
I doubt that you can use SetPixelFormat() for TPanel, or even TForm. Where do you get fChwnd? Shouldn't it be FDC:=GetDC(panel1.handle); Then you should call ReadExtensions; after the InitOpenGL;

laggyluk
08-10-2014, 08:32 AM
I guess fChwnd is panel1.handle if this works
And if there's a need to call the second part of code at all then I guess panel handle changes while docking/dragging?

serkank
22-10-2014, 07:03 PM
Long time Later i found where i do wrong
if handle is change its need use SetPixelFormat and ActivateRenderingContext

my wrong i tryed to delete RC,DC ..




pfd.dwFlags := PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER;
SetPixelFormat ( DC, ChoosePixelFormat ( DC, @pfd ), @pfd );
ActivateRenderingContext( DC, wglCreateContext ( DC ), TRUE );