Difference between revisions of "OpenGL Tutorial/de"

From Lazarus wiki
Jump to navigationJump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{OpenGL Tutorial}}
 
{{OpenGL Tutorial}}
  
== Modernes OpenGL / OpenGL 3.3 ==
+
== OpenGL Tutorial ==
 +
=== Modernes OpenGL ( ab Version 3.3 ) ===
  
 
Da ich mein Tutorial nicht zweigleisig erstellen will, verlinke ich es. ;-)
 
Da ich mein Tutorial nicht zweigleisig erstellen will, verlinke ich es. ;-)
 
* [https://wiki.delphigl.com/index.php/Lazarus_-_OpenGL_3.3_Tutorial Lazarus OpenGL 3.3 - Tutorial]- (deutsch) (extern)
 
* [https://wiki.delphigl.com/index.php/Lazarus_-_OpenGL_3.3_Tutorial Lazarus OpenGL 3.3 - Tutorial]- (deutsch) (extern)
 +
 +
=== Beispiel in OpenGL ( veraltet ) ===
 +
Einfaches Beispiel welches ein Dreieck zeichnet.
 +
<syntaxhighlight lang="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.
 +
</syntaxhighlight>
  
 
[[Category:Code]]
 
[[Category:Code]]

Latest revision as of 14:43, 16 June 2019

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

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.

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.