Difference between revisions of "OpenGL Tutorial/de"
From Lazarus wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
{{OpenGL Tutorial}} | {{OpenGL Tutorial}} | ||
− | == Beispiel in OpenGL == | + | == OpenGL Tutorial == |
+ | === Beispiel in OpenGL === | ||
<syntaxhighlight> | <syntaxhighlight> | ||
unit unit1; | unit unit1; |
Revision as of 18:35, 29 May 2018
│
Deutsch (de) │
English (en) │
español (es) │
français (fr) │
日本語 (ja) │
한국어 (ko) │
русский (ru) │
中文(中国大陆) (zh_CN) │
OpenGL Tutorial
Beispiel in OpenGL
unit unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, OpenGLContext, gl;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
oglControl: TOpenGLControl; // Kontext für OpenGL
end;
var
Form1: TForm1;
implementation
procedure TForm1.Timer1Timer(Sender: TObject);
begin
// Hintergrundfarbe
glClearColor(0.8, 0.5, 0.3, 1.0);
// Zeichenbuffer löschen
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
// Projectionsmatrix aktivieren
glMatrixMode(GL_PROJECTION);
glLoadIdentity; // Matrix zurücksetzten ( Einheitsmatrix )
// Hier kann die ProjectionsMatrix manipuliert werden.
// Modelmatrix aktivieren
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
// Dreieck drehen ( Winkel ist in Grad.)
glRotatef(5.0, 0.0, 0.0, 1.0);
// Zeichnet ein einfache Dreieck
glBegin(GL_TRIANGLES);
glColor3f(0.8, 0.0, 0.0);
glVertex3f(0, 0.8, 0.0);
glColor3f(0.0, 0.8, 0.0);
glVertex3f(-0.8, -0.8, 0.0);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.8, -0.8, 0.0);
glEnd();
oglControl.SwapBuffers;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Interval := 40;
// OpenGL Kontext erzeugen
oglControl := TOpenGLControl.Create(Self);
// Kontext auf Form-Client anpassen
oglControl.Align := alClient;
// Kontext mit Form verbinden.
oglControl.Parent := Self;
// Automatische Grössenanpassung
oglControl.AutoResizeViewport := True;
end;
initialization
{$I unit1.lrs}
end.
Modernes OpenGL / OpenGL 3.3
Da ich mein Tutorial nicht zweigleisig erstellen will, verlinke ich es. ;-)
- Lazarus OpenGL 3.3 - Tutorial- (deutsch) (extern)