__fastcall TFormMain::TFormMain(TComponent* Sender)
: TForm(Sender)
{
hdc = GetDC(Handle);
Control_Zone->Top =0 ;
Control_Zone->Left =FormMain->Width;
Control_Zone->Width = 0;
Control_Zone->Height = FormMain->Height;
float nRange =75.0;
w = ClientWidth ;
h = ClientHeight;
if( h==0 ) h = 1;
if ( w<=h ) glOrtho( -nRange, nRange, -nRange*h/w,nRange*h/w,-nRange,nRange );
else glOrtho( -nRange*w/h,nRange*w/h,-nRange, nRange, -nRange,nRange );
Application->OnIdle = IdleLoop; //空闲时执行IdleLoop函数
Left_Button_Down = FALSE; //
key_and_mouse_down = FALSE; //
inclined = TRUE;//FALSE;
zoom = 0.99;
}
void __fastcall TFormMain::FormResize(TObject *Sender)
{
Control_Zone->Top = 0;
Control_Zone->Left = Control_Zone->ClientWidth;
Control_Zone->Width = 0;
Control_Zone->Height=ClientHeight;
float nRange =75.0;
w = ClientWidth ;
h = ClientHeight;
if( h==0 ) h = 1;
glViewport(0, 0, w, h);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
if ( w<=h ) glOrtho( -nRange, nRange, -nRange*h/w,nRange*h/w,-nRange,nRange );
else glOrtho( -nRange*w/h,nRange*w/h,-nRange, nRange, -nRange,nRange );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
inclined = TRUE;
key_and_mouse_down = FALSE;
}
void __fastcall TFormMain::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat( hdc, PixelFormat, &pfd );
}
以上三个函数就定义了一个显示窗口