OpenGL: how to render on 2 different DCs?


If you are trying to render to two separate DCs then you have two separate
OpenGL contexts to consider.

The basics would have to go something like this (forgive me if I am wrong
since I have only been doing OpenGL for three days):

-->get the DC of the window
-->set the pixel format of the dc
-->create a OpenGL context from the DC

Then when you want to render to the context you have to make sure that it is
the current OpenGL context. So for example you might have some code that
looks like this:

procedure TForm1.FormCreate( Sender : TObject );
 // Get the panel DCs.
  P1DC := GetDC( Panel1.Handle );
  P2.DC := GetDC( Panel1.Handle );

 // Try to set the pixel format for each.
  if not SetPanelPixelFormat( P1DC ) then begin
    ReleaseDC( P1DC );
    P1DC := 0;
  if not( SetPanelPixelFormat( P2DC ) then begin
    ReleaseDC( P2DC );
    P2DC := 0;

 // If the pixelformat was set then try to create an OpenGL context for
  if P1DC <> 0 then
    P1RC := wglCreateContext( P1DC );
  if P1RC = 0 then begin
    ReleaseDC( P1DC );

  if P2DC <> 0 then
    P2RC := wglCreateContext( P2DC );
  if P2RC = 0 then begin
    ReleaseDC( P2DC );

 // Now decide which context you initially want to be active......, say the
second one.
  wglMakeCurrent( P2DC, P2RC );


If you use just one panel and therefore just one context then I believe you
can scissor the context to represent multiple windows. I don't think that
this can be done across multiple DCs though. Someone please correct me if I
am wrong on that.
I am also not sure whether with multiple contexts you have to render
mutliple times, or whether you can specify the viewing & projection
transformations and get OpenGL to do the object geometry only once but
generate different views for the view. I shouldn't think so since multiple
depth tests, clipping, hidden surface removal etc. calcs would have to be
done. If anyone knows if this can be done for certain please let me know
since it could save me a lot of coding ( and performance! ).

Best regards,

Tulius Lima wrote in message <>...

>    I am trying to render onto 2 different panels that exist on the same

>form, but it is not working. Neither one of them renders at all.

>    I would like to know what should I do to setup and render on 2
>different panels that are placed on the same form! Shoudl I call
>SetPixelFormat once for each panel?

>    And if anyone knows of any good freeware components, please let me

>    TIA!
>    Tulius Lima