Forum > OpenGL
Delphi OpenGL and CrossPlatform Lazarus (Multilang)
TheProgrammer:
--- Code: ---unit foforras;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, dglOpenGL, ExtCtrls, StdCtrls, Math;
type
Tfoablak = class(TForm)
timer: TTimer;
procedure Create(Sender: TObject);
procedure Destory(Sender: TObject);
procedure gltimer(Sender: TObject);
procedure SetupGL;
procedure Render;
private
{ Private }
public
{ Public }
end;
var
foablak : Tfoablak;
DC : HDC;
RC : HGLRC;
NearClipping : integer;
FarClipping : integer;
StartTime, TimeCount, FrameCount : Cardinal;
Frames, DrawTime : Cardinal;
implementation
{$IFNDEF FPC}
{$R *.dfm}
{$ELSE}
{$R *.lfm}
{$ENDIF}
procedure Tfoablak.Create(Sender: TObject);
begin
DC := GetDC(Handle);
if not InitOpenGL then Application.Terminate;
RC := CreateRenderingContext( DC,
[opDoubleBuffered],
32,
24,
0,0,0,
0);
ActivateRenderingContext(DC, RC);
SetupGL;
InitOpenGL;
end;
procedure Tfoablak.SetupGL;
begin
glClearColor(0, 0, 0, 0); //hattér színe: RGBx, X = ?
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
end;
procedure Tfoablak.Destory(Sender: TObject);
begin
DeactivateRenderingContext;
DestroyRenderingContext(RC);
ReleaseDC(Handle, DC);
end;
procedure Tfoablak.Render;
begin
NearClipping := 1;
FarClipping := 1000;
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glTranslatef(0, 0, -500); //+-415x +-210y a max -500nál, eddig látható
SwapBuffers(DC);
end;
procedure Tfoablak.gltimer(Sender: TObject);
begin
inc(FrameCount);
Render;
If FrameCount = 20 then
begin
FrameCount := 0;
end;
end;
end.
--- End code ---
How can i create crossplatform OpenGL Appliction in Lazarus?
I must use Windows Library because i use HDC and HGLRC.
I would like to use dglOpenGL library because this is newer version. (OpenGL Shading Language 4.20)
Hogyan tudok platformfüggetlen alkalmazást csinálni?
Muszáj használnom a Windows könyvtárat a HDC és HGLRC miatt.
Szeretném a dpgOpenGL könyvtárat használni mert ez újabb. (OpenGL Shading Language 4.20)
BigChimp:
I know nothing about OpenGL, but have you checked the wiki:
http://wiki.lazarus.freepascal.org/OpenGL
There's also an OpenGL tutorial linked to there...
Hope this helps,
BigChimp
User137:
If you want you could look for hints from my game engine nxPascal:
http://www.pascalgamedevelopment.com/showthread.php?8785-nxPascal
It compiles with Lazarus and Delphi, and because it does not include Windows in uses-list anywhere it should be crossplatform. There are code differences between Lazarus and Delphi which can be solved with compiler directives {$IFDEF ...} I have included samples for 2 different methods of window creation. Mainly with Lazarus you want to use lazOpenGLContext package.
I also use latest dglOpenGL header.
There is also many more graphics libs on pascalgamedevelopment.
TheProgrammer:
Thanks!
Kössz!
avra:
If I remember well, OpenGL sample in Lazarus CT edition were multiplatform.
http://www.pilotlogic.com/codetyphon/help/opengl_samples.htm
http://www.pilotlogic.com/codetyphon/help/index.html?glscene_samples.htm
Navigation
[0] Message Index
[#] Next page