Sign in Join
Wiki copytemporary

Revision 1 of 1, by WikiArchive on 11-4-2026. The page as it is now.

OpenGL Tutorial/de

OpenGL Tutorial

Modernes OpenGL ( ab Version 3.3 )

Da ich mein Tutorial nicht zweigleisig erstellen will, verlinke ich es. ;-)

Beispiel in OpenGL ( veraltet )

Einfaches Beispiel welches ein Dreieck zeichnet.

pascal
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.

From the Free Pascal wiki, page "OpenGL Tutorial/de", as it stood on 2019-06-16 after a change by Mathias, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.