- {...}
- var
- MainForm: TMainForm;
- RC: HGLRC;
- DC: HDC;
- ShowFPS: Boolean = false;
- FontBase: GLUInt;
- StartTick: Cardinal;
- Frames: Integer;
- FPS: Single;
- DegX, DegY: integer;
- fZoom: glFloat = 1;
- linewidth: glfloat = 1;
- smoothlines: boolean = false;
- TT, TB, TL, TR, TFront, TBack: TglBitmap2D;
- {...}
- procedure BuildFont(pFontName : String);
- var
- Font : HFONT;
- begin
- FontBase := glGenLists(96);
- Font := CreateFont(16, 0, 0, 0, FW_MEDIUM, 0, 0, 0, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE or DEFAULT_PITCH, PChar(pFontName));
- SelectObject(DC, Font);
- wglUseFontBitmaps(DC, 0, 256, FontBase);
- DeleteObject(Font)
- end;
- procedure PrintText(pX, pY: Integer; const pText: String);
- begin
- if (pText = '') then
- exit;
- glPushAttrib(GL_LIST_BIT);
- glRasterPos2i(pX, pY);
- glListBase(FontBase);
- glCallLists(Length(pText), GL_UNSIGNED_BYTE, PChar(pText));
- glPopAttrib;
- end;
- procedure ShowFPSText;
- begin
- if showfps then
- begin
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_TEXTURE_2D);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- glOrtho(0, mainform.preview.width, mainform.preview.height, 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity;
- PrintText(5, 15, FloatToStr(FPS)+' fps');
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- end;
- end;
- procedure DrawQuad(x, y, z: glfloat);
- begin
- glBegin(GL_QUADS);
- glTexCoord2f(1, 0); glVertex3f(-x, -y, z);
- glTexCoord2f(1, 1); glVertex3f(x, -y, z);
- glTexCoord2f(0, 1); glVertex3f(x, y, z);
- glTexCoord2f(0, 0); glVertex3f(-x, y, z);
- glTexCoord2f(1, 0); glVertex3f(-x, -y, -z);
- glTexCoord2f(1, 1); glVertex3f(-x, y, -z);
- glTexCoord2f(0, 1); glVertex3f(x, y, -z);
- glTexCoord2f(0, 0); glVertex3f(x, -y, -z);
- glTexCoord2f(1, 0); glVertex3f(-x, y, -z);
- glTexCoord2f(1, 1); glVertex3f(-x, y, z);
- glTexCoord2f(0, 1); glVertex3f(x, y, z);
- glTexCoord2f(0, 0); glVertex3f(x, y, -z);
- glTexCoord2f(1, 0); glVertex3f(-x, -y, -z);
- glTexCoord2f(1, 1); glVertex3f(x, -y, -z);
- glTexCoord2f(0, 1); glVertex3f(x, -y, z);
- glTexCoord2f(0, 0); glVertex3f(-x,-y, z);
- glTexCoord2f(1, 0); glVertex3f(x, -y, -z);
- glTexCoord2f(1, 1); glVertex3f(x, y, -z);
- glTexCoord2f(0, 1); glVertex3f(x, y, z);
- glTexCoord2f(0, 0); glVertex3f(x, -y, z);
- glTexCoord2f(1, 0); glVertex3f(-x, -y, -z);
- glTexCoord2f(1, 1); glVertex3f(-x, -y, z);
- glTexCoord2f(0, 1); glVertex3f(-x, y, z);
- glTexCoord2f(0, 0); glVertex3f(-x, y, -z);
- glEnd;
- end;
- procedure TMainForm.FormCreate(Sender: TObject);
- begin
- GB_Pictures.doublebuffered := true;
- Degy := -45;
- Front.Canvas.rectangle(0, 0, Front.width, Front.Height);
- SideL.Canvas.rectangle(0, 0, SideL.width, SideL.Height);
- SideR.Canvas.rectangle(0, 0, SideR.width, SideR.Height);
- Back.Canvas.rectangle(0, 0, Back.width, Back.Height);
- Top.Canvas.rectangle(0, 0, Top.width, Top.Height);
- Bottom.Canvas.rectangle(0, 0, Bottom.width, Bottom.Height);
- InitOpenGL;
- DC := GetDC(Preview.Handle);
- RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);
- ActivateRenderingContext(DC, RC);
- glEnable(GL_CULL_FACE);
- glEnable(GL_TEXTURE_2D);
- glDepthFunc(GL_LESS);
- glClearColor(1, 1, 1, 0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- glViewPort(0, 0, Preview.Width, Preview.Height);
- gluPerspective(45, Preview.Width / Preview.Height, 0.1, 128);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity;
- BuildFont('Arial');
- StartTick := GetTickCount;
- end;
- procedure TMainForm.FormDestroy(Sender: TObject);
- begin
- DeactivateRenderingContext;
- wglDeleteContext(RC);
- ReleaseDC(Handle, DC);
- end;
- procedure TMainForm.ApplicationEvents1Idle(Sender: TObject;
- var Done: Boolean);
- begin
- Done := false;
- inc(Frames);
- if (smoothlines = true) then
- glEnable(GL_LINE_SMOOTH) else
- glDisable(GL_LINE_SMOOTH);
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glLoadIdentity;
- glTranslatef(0, 0, -3.25);
- glScalef(FZoom, FZoom, FZoom);
- glRotatef(degx, 1, 0, 0);
- glRotatef(degy, 0, 1, 0);
- glColor3f(0, 0, 0);
- glLineWidth(linewidth);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- DrawQuad(0.75, 1, 0.2);
- ShowFPSText;
- SwapBuffers(DC);
- if GetTickCount - StartTick >= 500 then
- begin
- FPS := round(Frames / (GetTickCount-StartTick) * 1000);
- Frames := 0;
- StartTick := GetTickCount
- end;
- end;
- procedure TMainForm.RotLClick(Sender: TObject);
- begin
- dec(DegY, 5);
- if DegY = -360 then
- DegY := 0;
- y_l.Caption := 'y: ' + inttostr(DegY);
- end;
- procedure TMainForm.RotUClick(Sender: TObject);
- begin
- dec(DegX, 5);
- if DegX = -360 then
- DegX := 0;
- x_l.Caption := 'x: ' + inttostr(-DegX);
- end;
- procedure TMainForm.RotDClick(Sender: TObject);
- begin
- inc(DegX, 5);
- if DegX = 360 then
- DegX := 0;
- x_l.Caption := 'x: ' + inttostr(-DegX);
- end;
- procedure TMainForm.RUClick(Sender: TObject);
- begin
- dec(DegX, 5);
- if DegX = -360 then
- DegX := 0;
- x_l.Caption := 'x: ' + inttostr(-DegX);
- end;
- procedure TMainForm.RRClick(Sender: TObject);
- begin
- inc(DegY, 5);
- if DegY = 360 then
- DegY := 0;
- y_l.Caption := 'y: ' + inttostr(DegY);
- end;
- procedure TMainForm.RLClick(Sender: TObject);
- begin
- dec(DegY, 5);
- if DegY = -360 then
- DegY := 0;
- y_l.Caption := 'y: ' + inttostr(DegY);
- end;
- procedure TMainForm.RDClick(Sender: TObject);
- begin
- inc(DegX, 5);
- if DegX = 360 then
- DegX := 0;
- x_l.Caption := 'x: ' + inttostr(-DegX);
- end;
- procedure TMainForm.ZIClick(Sender: TObject);
- begin
- fzoom := fzoom + 0.05;
- if fzoom > 1.5 then
- fzoom := 1.5;
- z_l.Caption := floattostr(round(fzoom * 100)) + '%';
- end;
- procedure TMainForm.ZOClick(Sender: TObject);
- begin
- fzoom := fzoom - 0.05;
- if fzoom < 0.5 then
- fzoom := 0.5;
- z_l.Caption := floattostr(round(fzoom * 100)) + '%';
- end;
- procedure TMainForm.ComboBox1Change(Sender: TObject);
- begin
- linewidth := strtoint(combobox1.Items[combobox1.itemindex]);
- end;
- {...}