I am making an application that has a bunch of small windows and controls in it (2D rendering), and I would like to render each window and control to its own bitmap. This is what have so far:
uses dglOpenGL;
...
var BMP: TBitmap;
DC, RC: HDC;
...
function TMainForm.Init: Boolean;
begin
Result := InitOpenGL;
if Result = True then
begin
BMP := TBitmap.Create;
BMP.PixelFormat := pf24bit;
BMP.Width := 1280;
BMP.Height := 1024;
DC := (BMP.Canvas.Handle);
RC := CreateRenderingContext(DC,
[opGDI, opDoubleBuffered], // tried changing, didn't help
24,
24,
0,
0,
0,
0);
ActivateRenderingContext(DC, RC);
glClearColor(0.27, 0.4, 0.7, 0.0); // light blue
glViewport(0, 0, 1280, 1024);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glOrtho(0, 1280, 0, 1024, -1, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
end;
end;
Rendering procedure:
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
// red quad
glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glVertex2f(100, 100);
glVertex2f(1280-100, 100);
glVertex2f(1280-100, 1024-100);
glVertex2f(100, 1024-100);
glend;
// swap
SwapBuffers(DC);
But there is no output.
If I use MainForm.Canvas.Draw(0, 0, BMP);
then a white rectangle will appear.
I want to do rendering stuff on bitmaps because I can do a lot of things with bitmaps (draw other images, paint text, blur), but if there another way to do off-screen render then it's okay...
So how do I set up my application for off-screen rendering?