Recent

Author Topic: Delphi OpenGL and CrossPlatform Lazarus (Multilang)  (Read 10034 times)

TheProgrammer

  • New Member
  • *
  • Posts: 48
  • Translator and programmer/Fordító és programozó
    • SourceCodePower.com
Delphi OpenGL and CrossPlatform Lazarus (Multilang)
« on: September 04, 2011, 09:18:11 am »
Code: [Select]
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.

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)
« Last Edit: September 04, 2011, 09:20:30 am by TheProgrammer »
Translator and programmer/Fordító és programozó (Multilang)
My webpage/Weboldalam:
www.sourcecodepower.com

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Delphi OpenGL and CrossPlatform Lazarus (Multilang)
« Reply #1 on: September 04, 2011, 10:06:54 am »
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
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Delphi OpenGL and CrossPlatform Lazarus (Multilang)
« Reply #2 on: September 04, 2011, 01:25:44 pm »
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

  • New Member
  • *
  • Posts: 48
  • Translator and programmer/Fordító és programozó
    • SourceCodePower.com
Re: Delphi OpenGL and CrossPlatform Lazarus (Multilang)
« Reply #3 on: September 04, 2011, 01:52:29 pm »
Thanks!
Kössz!
Translator and programmer/Fordító és programozó (Multilang)
My webpage/Weboldalam:
www.sourcecodepower.com

avra

  • Hero Member
  • *****
  • Posts: 2368
    • Additional info
Re: Delphi OpenGL and CrossPlatform Lazarus (Multilang)
« Reply #4 on: September 05, 2011, 10:06:27 am »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

TheProgrammer

  • New Member
  • *
  • Posts: 48
  • Translator and programmer/Fordító és programozó
    • SourceCodePower.com
Re: Delphi OpenGL and CrossPlatform Lazarus (Multilang)
« Reply #5 on: September 05, 2011, 05:47:41 pm »
Thanks!
Kössz!
Translator and programmer/Fordító és programozó (Multilang)
My webpage/Weboldalam:
www.sourcecodepower.com

 

TinyPortal © 2005-2018