Kako da opengl crta recimo na panelu ili nekom odredjenom delu forme a bez koriscenja 3rd party komponenti?
Opengl na odredjenom delu forme
Zaključano
Zakačeno
Mozes da postavis glViewport na panel.
npr da kazes glViewport(0,0,panel.width,panel.heigth).
Mada bi ti najlakse bilo da koristis GLScene,potpuno su besplatne,i ima jedna komponenta GLSceneViewer,
koju mozes da postavis na panel i preko nje iscratavas to sta ti treba.
Poz
npr da kazes glViewport(0,0,panel.width,panel.heigth).
Mada bi ti najlakse bilo da koristis GLScene,potpuno su besplatne,i ima jedna komponenta GLSceneViewer,
koju mozes da postavis na panel i preko nje iscratavas to sta ti treba.
Poz
Potpis
SERVIA NOSTRUM REGNUM!
Ovo ne radi vec samo bude resize. Znaci kako da mi rendering context ne bude canvas forme vec recimo panel ili nesto drugo.
Evo kako ja radim:
i kod kreiranja forme pozoves
SetupGLWindow(Panel1);
Code:
procedure SetupGLWindow(AWindow: TWinControl);
var
DC:HDC;
RC:HGLRC;
begin
DC:=GetDC(AWindow.Handle);
SetupPixelFormat(DC);
RC:=wglCreateContext(DC);
wglMakeCurrent(DC, RC);
end;
procedure SetupPixelFormat(DC:HDC);
const
pfd:TPIXELFORMATDESCRIPTOR = (
nSize:sizeof(TPIXELFORMATDESCRIPTOR); // size
nVersion:1; // version
dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
// support double-buffering
iPixelType:PFD_TYPE_RGBA; // color type
cColorBits:24; // prefered color depth
cRedBits:0;
cRedShift:0; // color bits (ignored)
cGreenBits:0;
cGreenShift:0;
cBlueBits:0;
cBlueShift:0;
cAlphaBits:0;
cAlphaShift:0; // no alpha buffer
cAccumBits: 0;
cAccumRedBits: 0; // no accumulation buffer,
cAccumGreenBits: 0; // accum bits (ignored)
cAccumBlueBits: 0;
cAccumAlphaBits: 0;
cDepthBits:24; // depth buffer
cStencilBits:0; // no stencil buffer
cAuxBuffers:0; // no auxiliary buffers
iLayerType:PFD_MAIN_PLANE; // main layer
bReserved: 0;
dwLayerMask: 0;
dwVisibleMask: 0;
dwDamageMask: 0; // no layer, visible, damage masks */
);
var pixelFormat:integer;
begin
pixelFormat := ChoosePixelFormat(DC, @pfd);
if (pixelFormat = 0) then begin
MessageBox(WindowFromDC(DC), 'ChoosePixelFormat failed.', 'Error',
MB_ICONERROR or MB_OK);
exit;
end;
if (SetPixelFormat(DC, pixelFormat, @pfd) <> TRUE) then begin
MessageBox(WindowFromDC(DC), 'SetPixelFormat failed.', 'Error',
MB_ICONERROR or MB_OK);
exit;
end;
end;
procedure SetupGLWindow(AWindow: TWinControl);
var
DC:HDC;
RC:HGLRC;
begin
DC:=GetDC(AWindow.Handle);
SetupPixelFormat(DC);
RC:=wglCreateContext(DC);
wglMakeCurrent(DC, RC);
end;
procedure SetupPixelFormat(DC:HDC);
const
pfd:TPIXELFORMATDESCRIPTOR = (
nSize:sizeof(TPIXELFORMATDESCRIPTOR); // size
nVersion:1; // version
dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
// support double-buffering
iPixelType:PFD_TYPE_RGBA; // color type
cColorBits:24; // prefered color depth
cRedBits:0;
cRedShift:0; // color bits (ignored)
cGreenBits:0;
cGreenShift:0;
cBlueBits:0;
cBlueShift:0;
cAlphaBits:0;
cAlphaShift:0; // no alpha buffer
cAccumBits: 0;
cAccumRedBits: 0; // no accumulation buffer,
cAccumGreenBits: 0; // accum bits (ignored)
cAccumBlueBits: 0;
cAccumAlphaBits: 0;
cDepthBits:24; // depth buffer
cStencilBits:0; // no stencil buffer
cAuxBuffers:0; // no auxiliary buffers
iLayerType:PFD_MAIN_PLANE; // main layer
bReserved: 0;
dwLayerMask: 0;
dwVisibleMask: 0;
dwDamageMask: 0; // no layer, visible, damage masks */
);
var pixelFormat:integer;
begin
pixelFormat := ChoosePixelFormat(DC, @pfd);
if (pixelFormat = 0) then begin
MessageBox(WindowFromDC(DC), 'ChoosePixelFormat failed.', 'Error',
MB_ICONERROR or MB_OK);
exit;
end;
if (SetPixelFormat(DC, pixelFormat, @pfd) <> TRUE) then begin
MessageBox(WindowFromDC(DC), 'SetPixelFormat failed.', 'Error',
MB_ICONERROR or MB_OK);
exit;
end;
end;
i kod kreiranja forme pozoves
SetupGLWindow(Panel1);
All right, a kako sada da mi pozadina bude u boji panela, tj da ne bude crna.
Vrlo jednostavno. Postavi ClearColor na boju forme, i kad god budes brisao RT, boja brisanja ce biti boja forme.