OpenGL in separated forms


2005-10-12 06:23:46 PM
cppbuilder65
Hi everybody,
I would like to know how to show the same 3D images on OpenGL
Components
in different forms (e.g. Displaying the same 3D Images on Panel2 of
Form1 and
Panel2 of Form2 at the same time) WITHOUT using the 3rd party OpenGL
components.
So far, when I add the button to show OpenGL on Panel2 of Form2, ONLY
Panel2 of Form2
would display OpenGL Image, but NOT on Panel2 of Form1.
I heard that I need to play aroudn with MDI or so .... But I have No
clue how to do that.
Okay, Let's take a look on my Codes:
// ----------- Form 1 --------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
InitializeControls();
Application->OnIdle = IdleLoop;
_control87(MCW_EM, MCW_EM); // Thisshould be called ONLY ONCE at
the constructor
m_hdc = GetDC(Form1->Panel2->Handle); // < - This is the problem
SetPixelFormatDescriptor();
m_hglrc = wglCreateContext(m_hdc);
wglMakeCurrent(m_hdc, m_hglrc);
SetupRC();
}
__fastcall TForm1::~TForm1()
{
::ReleaseDC(Panel2->Handle, m_hdc);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hglrc);
}
void __fastcall TForm1::IdleLoop(TObject* Sender, bool &Done)
{
Done = false;
RenderGLScene(); // Draw OpenGL HERE
SwapBuffers(m_hdc); // openGL call
}
void TForm1::SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->Show(); // This is another problem
}
//---------------------------------------------------------------------------
// ----------- Form2 -----------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
// m_XAngle = 27;
// m_YAngle = -35;
m_XAngle = 0;
m_YAngle = 0;
m_ZAngle = 0;
m_ZTranslate = -5;
m_YTranslate = 0;
m_XTranslate = 0;
InitializeControls();
Application->OnIdle = IdleLoop;
_control87(MCW_EM, MCW_EM);
m_hdc = GetDC(Form2->Panel2->Handle);
SetPixelFormatDescriptor();
m_hglrc = wglCreateContext(m_hdc);
wglMakeCurrent(m_hdc, m_hglrc);
SetupRC();
}
__fastcall TForm2::~TForm2()
{
::ReleaseDC(Panel2->Handle, m_hdc);
// wglMakeCurrent(m_hdc, NULL);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hglrc);
}
void __fastcall TForm2::IdleLoop(TObject* Sender, bool &Done)
{
Done = false;
RenderGLScene();
SwapBuffers(m_hdc); // openGL call
}
// -----------------------------------------------------------
Is there ANYWAY to enable the OpenGL Display on Multiple Forms at the
same time?
If so, please show me how to do so.