Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Dez 21, 2024 17:56

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 20 Beiträge ]  Gehe zu Seite 1, 2  Nächste
Autor Nachricht
 Betreff des Beitrags: Just Beginning
BeitragVerfasst: Fr Feb 22, 2013 14:12 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
Trust me, I am an absolute Novice. Apologies if I failed to 'search'.

I have previously attempted to use TOGLControl under Lazarus. It turned out to be 'restrictive'. Probably my fault for not trying hard enough. After a Google I found you..

I download and extract dglOpenGL.zip

Then I go to Tutorial 1),

http://wiki.delphigl.com/index.php/Tutorial_Quickstart

My resulting code is,

Code:
  1. unit Unit1;
  2.  
  3. {$mode Delphi}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  9.   LCLType, LCLIntf, dglOpenGL;
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.     { private declarations }
  18.   public
  19.     { public declarations }
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.   DC:    HDC;
  25.   RC:    HDC;
  26.  
  27. implementation
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.   DC := GetDC(Handle);
  34.   if not InitOpenGL then Application.Terminate;
  35.   RC := CreateRenderingContext(DC,[opDoubleBuffered],32,24,0,0,0,0);
  36.   ActivateRenderingContext(DC, RC);
  37. end;
  38.  
  39. initialization
  40.   {$I unit1.lrs}
  41.  
  42. end.


As an aside, and please don't get me wrong, but it would help novices such as myself if, at least at this early stage and even afterwards, there was a full declaration of the units required. Obviously I get used to some of the error messages indicating, perhaps, I have not included the required units but then I have to go Google to find snippets from elsewhere that might give a hint as to what is missing.... I realise, eventually, such matters might become second nature but...

I have placed dglOpenGL.pas in a subdirectory under the directory in which I have saved the 'project'. From the 'Menu Bar' in Lazarus I use 'Project|Project Inspector' and add that file to the 'project'. It appears under Files as,

dglOpenGL/dglOpenGL.pas

When I try to run it seems the above file is initially compiled and then I get the following error messages,

Zitat:
unit1.pas(35,30) Error: Identifier not found "CreateRenderingContext"
unit1.pas(36,27) Error: Identifier not found "ActivateRenderingContext"
unit1.pas(44, stopping


Viewing dglOpenGL.pas in a text editor the declarations appear to be there.

What have I missed?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Fr Feb 22, 2013 14:40 
Offline
Compliance Officer
Benutzeravatar

Registriert: So Aug 08, 2010 08:37
Beiträge: 460
Programmiersprache: C / C++ / Lua
Which OS are you using?

Afaik CreateRenderingContext is only for Windows...

_________________
offizieller DGL Compliance Beauftragter
Never run a changing system! (oder so)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Fr Feb 22, 2013 14:59 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
end hat geschrieben:
Which OS are you using?

Afaik CreateRenderingContext is only for Windows...


Ahh.. :oops: Linux/Ubuntu 10.04.4

Oh, looking through the source I find,

Code:
  1. const
  2. {$IFDEF DGL_WIN}
  3.   OPENGL_LIBNAME = 'OpenGL32.dll';
  4.   GLU_LIBNAME = 'GLU32.dll';
  5. {$ELSE}
  6.   {$IFDEF darwin}
  7.     OPENGL_LIBNAME = 'libGL.dylib';
  8.     GLU_LIBNAME = 'libGLU.dylib';
  9.   {$ELSE}
  10.     OPENGL_LIBNAME = 'libGL.so.1';
  11.     GLU_LIBNAME = 'libGLU.so.1';
  12.   {$ENDIF}
  13. {$ENDIF}
  14.  
  15. function InitOpenGL(LibName: String = OPENGL_LIBNAME; GLULibName: String = GLU_LIBNAME): Boolean;
  16.  
  17. function dglGetProcAddress(ProcName: PAnsiChar; LibHandle: Pointer = nil {$IFDEF DGL_LINUX}; ForceDLSym: Boolean = False{$ENDIF}): Pointer;
  18. function dglCheckExtension(Extension: AnsiString): Boolean;
  19.  
  20. procedure ReadExtensions;
  21. procedure ReadImplementationProperties;
  22.  
  23. // =============================================================================
  24. // Helper-Functions
  25. // =============================================================================
  26. {$IFDEF DGL_WIN}
  27.   function CreateRenderingContext(DC: HDC; Options: TRCOptions; ColorBits, ZBits, StencilBits, AccumBits, AuxBuffers: Integer; Layer: Integer): HGLRC;
  28.   function CreateRenderingContextVersion(DC: HDC; Options: TRCOptions; MajorVersion, MinorVersion : Integer; ForwardCompatible : Boolean; ColorBits, ZBits, StencilBits, AccumBits, AuxBuffers: Integer; Layer: Integer): HGLRC;
  29.   procedure DestroyRenderingContext(RC: HGLRC);
  30.  
  31.   procedure ActivateRenderingContext(DC: HDC; RC: HGLRC; loadext: boolean = true);
  32.   procedure DeactivateRenderingContext;
  33. {$ENDIF}


OPENGL_LIBNAME = 'libGL.so.1';
GLU_LIBNAME = 'libGLU.so.1';

Is Linux and the "helper functions" look like Windows.... Fail at the first hurdle..


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Sa Feb 23, 2013 05:28 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Well the main differences is that all wgl stuff is glx in linux. ActivateRenderingContext's only windows related code is the wglMakeCurrent which is glxMakeCurrent (glx version takes different parameters).

Window creation is completely different. This may help.

I have Linux Mint (Which i never used) installed on my old pc, so ill see if i can work out how to get OpenGL to work with it.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Sa Feb 23, 2013 08:45 
Offline
Compliance Officer
Benutzeravatar

Registriert: So Aug 08, 2010 08:37
Beiträge: 460
Programmiersprache: C / C++ / Lua
Zitat:
Fail at the first hurdle..

Don't worry - I had such problems at the beginning too...

You could use SDL for beginning, we have a few templates in the dglSDK:

http://wiki.delphigl.com/index.php/Archiv:dglsdk_linux_2006_1

But this is quite old, it contains not the newest headers, etc..

I prefer (for a beginner) using easySDL (any where in the DGLSDK, quite old but containing much samples...) or my work, EVFramework (okay, some advertisement, but hey it's free...):

https://dl.dropbox.com/u/51225594/EVFramework.zip
(open the Template.dpr, i'll make some more templates today...)

and the updated SDL-Headers:

https://dl.dropbox.com/u/51225594/SDL_Delphi_x86_x64.zip

and here are the Runtime-Libraries:

http://www.libsdl.org/download-1.2.php

_________________
offizieller DGL Compliance Beauftragter
Never run a changing system! (oder so)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Sa Feb 23, 2013 11:44 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
Thanks for the replies. I am, for the moment, chasing my own tail. Here is what I had previously.. apologies for the size and lack of comments. The OGL stuff is in the last procedure.

Code:
  1. unit unit_oglframe00;
  2.  
  3. {$mode delphi}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Dialogs,
  9.   LCLIntf, Graphics,
  10.   OpenGLContext, gl, glu;
  11.  
  12. type
  13.  
  14.   { TOGLFrame00 }
  15.  
  16.   TOGLFrame00 = class(TFrame)
  17.   private
  18.     { private declarations }
  19.     MyObj: TObject;
  20.   public
  21.     { public declarations }
  22.     constructor Create(TheOwner: TComponent); override;
  23.     destructor  Destroy; override;
  24.   end;
  25.   TOGLControl = Class(TOpenGLControl)
  26.   private
  27.     { private declarations }
  28.   public
  29.     { public declarations }
  30.     procedure Idle(Sender:TObject; var Done:boolean);
  31.     procedure MouseMI(Sender: TOBject);
  32.     procedure MouseMO(Sender: TOBject);
  33.     procedure Move(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  34.     procedure DnKey(Sender: TObject; var Key: Word; Shift: TShiftState);
  35.     procedure Wheel(Sender: TObject; Shift: TShiftState;
  36.               WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  37.     procedure ZoomSheet(Zoom: Boolean);
  38.     procedure FillSheet(Sender: TObject);
  39.     procedure MakeGrids();
  40.     procedure SetColors();
  41.   end;
  42.   TGridPointX = Record
  43.     GPointX: Integer;
  44.     XLocalD: Double;
  45.     XLocalS: String;
  46.     XMajorG: Boolean;
  47.   end;
  48.   TGridPointY = Record
  49.     GPointY: Integer;
  50.     YLocalD: Double;
  51.     YLocalS: String;
  52.     YMajorG: Boolean;
  53.   end;
  54.  
  55. var
  56.   OGLFrame00:     TOGLFrame00;
  57.   OGLControl:     TOGLControl;
  58.  
  59.   GridArrayX:     Array of TGridPointX;
  60.   GridArrayY:     Array of TGridPointY;
  61.   MouseX:         TGridPointX;
  62.   MouseY:         TGridPointY;
  63.   SPointA:        TPoint;
  64.   SPointB:        TPoint;
  65.   RPointA:        TPoint;
  66.   RPointB:        TPoint;
  67.   BaseLevel:      Double;
  68.   ZoomLevel:      Double;
  69.   CursR:          Byte;
  70.   CursG:          Byte;
  71.   CursB:          Byte;
  72.   MajGR:          Byte;
  73.   MajGG:          Byte;
  74.   MajGB:          Byte;
  75.   MinGR:          Byte;
  76.   MinGG:          Byte;
  77.   MinGB:          Byte;
  78.   BackR:          Byte;
  79.   BackG:          Byte;
  80.   BackB:          Byte;
  81.  
  82. implementation
  83.  
  84. uses
  85.   unit_main,
  86.   unit_schvars00;
  87.  
  88. constructor TOGLFrame00.Create(TheOwner: TComponent);
  89. begin
  90.   inherited Create(TheOwner);
  91.   MyObj        := TObject.Create;
  92.   OGLControl   := TOGLControl.Create(OGLFrame00);
  93.   With OGLControl do
  94.   begin
  95.     Align        := alClient;
  96.     Parent       := Self;
  97.     Cursor       := crNone;
  98.     OnResize     := FillSheet;
  99.     OnMouseMove  := Move;
  100.     OnMouseWheel := Wheel;
  101.     OnKeyDown    := DnKey;
  102.     OnMouseEnter := MouseMI;
  103.     OnMouseLeave := MouseMO;
  104.     Application.OnIdle := Idle;
  105.     AutoResizeViewport := true;
  106.   end;
  107. end;
  108.  
  109. destructor TOGLFrame00.Destroy;
  110. begin
  111.   SetLength(GridArrayX,0);
  112.   SetLength(GridArrayY,0);
  113.   OGLControl.Free;
  114.   MyObj.Free;
  115.   inherited Destroy;
  116. end;
  117.  
  118. procedure TOGLControl.MouseMI(Sender: TOBject);
  119. begin
  120.   OGLControl.SetFocus;
  121. end;
  122.  
  123. procedure TOGLControl.MouseMO(Sender: TOBject);
  124. begin
  125.   Form1.Memo1.SetFocus;
  126. end;
  127.  
  128. procedure TOGLControl.Move(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  129. var
  130. Index: Integer;
  131. begin
  132.   If (X > RPointA.X) and (X < RPointB.X) then
  133.   begin
  134.     Index := Trunc(High(GridArrayX)*(X - RPointA.X)/(RPointB.X - RPointA.X));
  135.     If Index > High(GridArrayX) then Index := High(GridArrayX);
  136.     If Index < 0 then Index := 0;
  137.     MouseX.GPointX := GridArrayX[Index].GPointX;
  138.     MouseX.XLocalD := GridArrayX[Index].XLocalD;
  139.     MouseX.XLocalS := GridArrayX[Index].XLocalS;
  140.   end;
  141.   If (Y > RPointA.Y) and (Y < RPointB.Y) then
  142.   begin
  143.     Index := Trunc(High(GridArrayY)*(Y - RPointA.Y)/(RPointB.Y - RPointA.Y));
  144.     If Index > High(GridArrayY) then Index := High(GridArrayY);
  145.     If Index < 0 then Index := 0;
  146.     MouseY.GPointY := GridArrayY[Index].GPointY;
  147.     MouseY.YLocalD := GridArrayY[Index].YLocalD;
  148.     MouseY.YLocalS := GridArrayY[Index].YLocalS;
  149.   end;
  150. end;
  151.  
  152. procedure TOGLControl.Wheel(Sender: TObject; Shift: TShiftState;
  153.   WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  154. begin
  155.   If WheelDelta > 0 then ZoomSheet(Boolean(0))
  156.                     else ZoomSheet(Boolean(1));
  157. end;
  158.  
  159. procedure TOGLControl.DnKey(Sender: TObject; var Key: Word; Shift: TShiftState);
  160. begin
  161.   Case Key of
  162.     33: ZoomSheet(Boolean(1));
  163.     34: ZoomSheet(Boolean(0));
  164.     35: FillSheet(Nil);
  165.   end;
  166. end;
  167.  
  168. procedure TOGLControl.FillSheet(Sender: TObject);
  169. begin
  170.   With unit_schvars00.SCHVars do
  171.   begin
  172.     If SheetX/OGLControl.Width >= SheetY/OGLControl.Height
  173.     then BaseLevel := (OGLControl.Width  - 20)/SheetX
  174.     else BaseLevel := (OGLControl.Height - 20)/SheetY;
  175.   end;
  176.   ZoomLevel := 1;
  177.   MakeGrids();
  178. end;
  179.  
  180. procedure TOGLControl.ZoomSheet(Zoom: Boolean);
  181. begin
  182.   If Zoom then ZoomLevel := ZoomLevel*SQRT(2)
  183.           else ZoomLevel := ZoomLevel/SQRT(2);
  184.   MakeGrids();
  185. end;
  186.  
  187. procedure TOGLControl.MakeGrids();
  188. var
  189. Count:      Integer;
  190. Width:      Integer;
  191. PointI:     Integer;
  192. PointD:     Double;
  193. DGrid:      Double;
  194. IGrid:      Double;
  195. ZoomTotal:  Double;
  196. begin
  197.   With unit_schvars00.SCHVars do
  198.   begin
  199.     ZoomTotal := BaseLevel*ZoomLevel;
  200.     DGrid     := SchMult/SchDivi;
  201.     IGrid     := DGrid*ZoomTotal;
  202.     SPointA.X := Trunc(OGLControl.Width  div 2 - ZoomTotal*SheetX/2);
  203.     SPointA.Y := Trunc(OGLControl.Height div 2 - ZoomTotal*SheetY/2);
  204.     SPointB.X := Trunc(OGLControl.Width  div 2 + ZoomTotal*SheetX/2);
  205.     SPointB.Y := Trunc(OGLControl.Height div 2 + ZoomTotal*SheetY/2);
  206.     RPointA.X := SPointA.X;
  207.     RPointA.Y := SPointA.Y;
  208.     RPointB.X := SPointB.X;
  209.     RPointB.Y := SPointB.Y;
  210.     If RPointA.X < 0 then RPointA.X := -1;
  211.     If RPointA.Y < 0 then RPointA.Y := -1;
  212.     If RPointB.X > OGLControl.Width  then RPointB.X := OGLControl.Width  + 1;
  213.     If RPointB.Y > OGLControl.Height then RPointB.Y := OGLControl.Height + 1;
  214.     Count  := Trunc((RPointA.X - SPointA.X)/IGrid);
  215.     PointI := Trunc(SPointA.X + Count * IGrid);
  216.     Width  := 1;
  217.     While PointI < RPointB.X do
  218.     begin
  219.       PointD := Count * DGrid;
  220.       PointI := Trunc(SPointA.X + Count * IGrid);
  221.       SetLength(GridArrayX,Width);
  222.       GridArrayX[Width-1].GPointX := PointI;
  223.       GridArrayX[Width-1].XLocalD := PointD;
  224.       GridArrayX[Width-1].XLocalS := FloatToStrF(PointD,ffFixed,5,5);
  225.       If Count mod SchDivi = 0
  226.       then GridArrayX[Width-1].XMajorG := True
  227.       else GridArrayX[Width-1].XMajorG := False;
  228.       INC(Count);
  229.       INC(Width);
  230.     end;
  231.     If GridArrayX[High(GridArrayX)].GPointX > SPointB.X
  232.     then SetLength(GridArrayX,Length(GridArrayX) - 1);
  233.     Count  := Trunc((RPointA.Y - SPointA.Y)/IGrid);
  234.     PointI := Trunc(SPointA.Y + Count * IGrid);
  235.     Width  := 1;
  236.     While PointI < RPointB.Y do
  237.     begin
  238.       PointD := Count * DGrid;
  239.       PointI := Trunc(SPointA.Y + Count * IGrid);
  240.       SetLength(GridArrayY,Width);
  241.       GridArrayY[Width-1].GPointY := PointI;
  242.       GridArrayY[Width-1].YLocalD := PointD;
  243.       GridArrayY[Width-1].YLocalS := FloatToStrF(PointD,ffFixed,5,5);
  244.       If Count mod SchDivi = 0
  245.       then GridArrayY[Width-1].YMajorG := True
  246.       else GridArrayY[Width-1].YMajorG := False;
  247.       INC(Count);
  248.       INC(Width);
  249.     end;
  250.     If GridArrayY[High(GridArrayY)].GPointY > SPointB.Y
  251.     then SetLength(GridArrayY,Length(GridArrayY) - 1);
  252.   end;
  253. end;
  254.  
  255. procedure TOGLControl.SetColors();
  256. begin
  257.   With unit_schvars00.SCHVars do
  258.   begin
  259.     CursR := GetRValue(CursCol);
  260.     CursG := GetGValue(CursCol);
  261.     CursB := GetBValue(CursCol);
  262.     MajGR := GetRValue(MajGCol);
  263.     MajGG := GetGValue(MajGCol);
  264.     MajGB := GetBValue(MajGCol);
  265.     MinGR := GetRValue(MinGCol);
  266.     MinGG := GetGValue(MinGCol);
  267.     MinGB := GetBValue(MinGCol);
  268.     BackR := GetRValue(BackCol);
  269.     BackG := GetGValue(BackCol);
  270.     BackB := GetBValue(BackCol);
  271.   end;
  272. end;
  273.  
  274. procedure TOGLControl.Idle(Sender:TObject; var Done:boolean);
  275. var
  276. Count:  Integer;
  277. begin
  278.   glClearColor(1, 1, 1, 1);
  279.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  280.   glMatrixMode (GL_PROJECTION);
  281.   glLoadIdentity();
  282.   glOrtho (0, OGLControl.Width, OGLControl.Height, 0, 0, 1);
  283.   glDisable(GL_DEPTH_TEST);
  284.   glMatrixMode (GL_MODELVIEW);
  285.   glLoadIdentity();
  286.   glColor3f(BackR/255, BackG/255, BackB/255);
  287.   glBegin(GL_QUADS);
  288.     glVertex2f(RPointA.X,RpointA.Y);
  289.     glVertex2f(RPointB.X,RpointA.Y);
  290.     glVertex2f(RPointB.X,RpointB.Y);
  291.     glVertex2f(RPointA.X,RpointB.Y);
  292.   glEnd();
  293.   With unit_schvars00.SCHVars do
  294.   begin
  295.     If SchGMin then
  296.     begin
  297.       glColor3f(MinGR/255, MinGG/255, MinGB/255);
  298.       Count := 0;
  299.       While Count < High(GridArrayX) do
  300.       begin
  301.         glBegin(GL_LINES);
  302.           glVertex2f(GridArrayX[Count].GPointX, RPointA.Y);
  303.           glVertex2f(GridArrayX[Count].GPointX, RPointB.Y);
  304.         glEnd;
  305.         Count := Count + 1;
  306.       end;
  307.       Count := 0;
  308.       While Count < High(GridArrayY) do
  309.       begin
  310.         glBegin(GL_LINES);
  311.           glVertex2f(RPointA.X, GridArrayY[Count].GPointY);
  312.           glVertex2f(RPointB.X, GridArrayY[count].GPointY);
  313.         glEnd;
  314.         Count := Count + 1;
  315.       end;
  316.     end;
  317.     If SchGMaj then
  318.     begin
  319.       glColor3f(MajGR/255, MajGG/255, MajGB/255);
  320.       Count := SchDivi;
  321.       While Count < High(GridArrayX) do
  322.       begin
  323.         glBegin(GL_LINES);
  324.           glVertex2f(GridArrayX[Count].GPointX, RPointA.Y);
  325.           glVertex2f(GridArrayX[Count].GPointX, RPointB.Y);
  326.         glEnd;
  327.         Count := Count + SchDivi;
  328.       end;
  329.       Count := SchDivi;
  330.       While Count < High(GridArrayY) do
  331.       begin
  332.         glBegin(GL_LINES);
  333.           glVertex2f(RPointA.X, GridArrayY[Count].GPointY);
  334.           glVertex2f(RPointB.X, GridArrayY[count].GPointY);
  335.         glEnd;
  336.         Count := Count + SchDivi;
  337.       end;
  338.     end;
  339.   end;
  340.   glColor3f(0, 0, 1);
  341.   glBegin(GL_LINE_LOOP);
  342.     glVertex2f(RPointA.X,RpointA.Y);
  343.     glVertex2f(RPointB.X,RpointA.Y);
  344.     glVertex2f(RPointB.X,RpointB.Y);
  345.     glVertex2f(RPointA.X,RpointB.Y);
  346.   glEnd();
  347.   glColor3f(CursR/255, CursG/255, CursB/255);
  348.   glBegin(GL_LINES);
  349.       glVertex2f(MouseX.GPointX,0);
  350.       glVertex2f(MouseX.GPointX,OGLControl.Height);
  351.   glEnd;
  352.   glBegin(GL_LINES);
  353.       glVertex2f(0,MouseY.GPointY);
  354.       glVertex2f(OGLControl.Width,MouseY.GPointY);
  355.   glEnd;
  356.   glFlush;
  357.   OGLControl.SwapBuffers;
  358.   Done := True;
  359.   Form1.Status.Panels[0].Text := MouseX.XLocalS;
  360.   Form1.Status.Panels[1].Text := MouseY.YLocalS;
  361. end;
  362.  
  363. initialization
  364.   {$I unit_oglframe00.lrs}
  365.  
  366. end.


I am using OpenGLContext, gl, and glu to do the OpenGL stuff. Being warped it is all done in a TFrame which contains a TOpenGLControl which, on creation, is/are parented to a specific panel on the main form.

I am also guilty of picking bits and pieces from elsewhere and welding things on until they work, in some cases with little to no real understanding about what they do.

Ho Hum.

It is an attempt at a CAD program and it 'hits the buffers', pun intended, when it has to go through all of the glBegin/glEnd stuff. Reading on this forum, and elsewhere, I should be able to overcome that by using 'buffers' so, being a bit of a knuckle scraper, I try some of the 'words' and the compiler says 'meh' in a way that suggests the units I have used do not reference such commands.

So.. I try plugging in dglOpenGL and they 'wake up'. I still haven't figured out which ones I should be using or how they should be used but I get the impression that 'mixing and matching' might be a bad idea.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Sa Feb 23, 2013 14:45 
Offline
Compliance Officer
Benutzeravatar

Registriert: So Aug 08, 2010 08:37
Beiträge: 460
Programmiersprache: C / C++ / Lua
Instead of gl/glu you can use dglOpenGL.pas => much more actual, so you can use all functions of OpenGL.

I don't think the code needs changes if you use dglOpenGL.pas - it have the same functions, and more functions.

_________________
offizieller DGL Compliance Beauftragter
Never run a changing system! (oder so)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: So Feb 24, 2013 00:37 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
end hat geschrieben:
Instead of gl/glu you can use dglOpenGL.pas => much more actual, so you can use all functions of OpenGL.

I don't think the code needs changes if you use dglOpenGL.pas - it have the same functions, and more functions.


OK.. I'll give things another poke sometime.

At the moment though it looks like OpenGLContext is the unit that gives me the TOpenGLControl that I can parent to a particular panel on the main form. Presumably dglOpenGL.pas uses other methods...

This was my first hint,

viewtopic.php?f=19&t=9789

but then I fell over because I did not recognise it as being Windows specific. I have to do a lot more reading. If, eventually, the words make sense I'll have to put it in my own words.

Oooops... did not read properly. It looks like you are suggesting OpenGLContext can remain and live with dglOpenGL.pas so gl and glu are no longer required. As I say I'll try again.

It's a good job no nuclear weapons go off when I compile and run my rubbish.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: So Feb 24, 2013 08:15 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Spent all of yesterday trying to get Lazarus to recompile its self so i could see how the TOGLControl control works (As its not defaultly compiled into it. I havn't found out how to convert a TForm.Handle into a PDisplay and TOGLControl should show how its done). And kept getting an error about fpc not being able to run fpcres . Though if i run fpcres using the same command fpc does from the terminal it works perfectly. This is why i like Windows(Things just work).

You need a Linux version of ActivateRenderingContext as it loads the functions/procedures and sets some variables. I havn't been able to test it under linux due to the above problem but as its just swapping the MakeCurrent for a linux one there is a 99.99999% chance it will work.

Code:
  1. procedure ActivateRenderingContext(dpy: PDisplay; drawable: GLXDrawable; ctx: GLXContext; loadext: boolean = true);
  2. begin
  3.   glXMakeCurrent(dpy,drawable,ctx);
  4.  
  5.   {$ifdef DGL_TINY_HEADER}
  6.   ReadCoreVersion;
  7.   {$else}
  8.   ReadImplementationProperties;
  9.  
  10.   if (loadext) then
  11.     ReadExtensions;
  12.   {$endif}
  13. end;


Zitat:
It looks like you are suggesting OpenGLContext can remain and live with dglOpenGL.pas so gl and glu are no longer required.

Don't use any other OpenGL units if you use dglOpenGL. dglOpenGL is a replacement for the "Standard" OpenGL units that come with Delphi/Lazarus/Etc.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Mo Feb 25, 2013 12:50 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
Thanks for looking. Sorry to have added Linux to your pain for the weekend. Lazarus 9.28.? is available from the Ubuntu repositories but I would not know if Mint provides similar.

I had to use |Project|Project Inspector| and add LazOpenGLContext under required packages. However if they are not going to play together and the supplied tools do not come with the additional functionality then I am going to end up binning them.

Chances are that they do but it is just me poking the wrong things. What I did like about the OpenGLContext was that it gave me access to many of the events associated with a normal Pascal control. It looks like if I were to go 'raw' OGL I would have to make 'calls' elsewhere.

Again I apologise for myself. I'll carry on poking about.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Di Feb 26, 2013 09:24 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
GLScene may be worth looking into. It all depends on what you really want. Things like GLScene could speed up development and make it easier but at the same time you have less control. They also may not offer you the same rendering speed as they may use older methods (Like glBegin and glEnd).

Zitat:
It looks like if I were to go 'raw' OGL I would have to make 'calls' elsewhere.

When it comes to embedding OpenGL in a form/panel i generally just use a timer to handle the rendering (You just set the interval to 1. It should give at least 60 FPS). The main problem is how do you embed it into the application in Linux(Well convert the TForm.Handle into a PDisplay). By the looks of it if you wanted to make a full screen application (Well creating a window from scratch which has nothing to do with a Lazarus form) it wouldn't be hard to create the window and initialize OpenGL.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Di Feb 26, 2013 18:11 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
I kind of hear what you are saying. I'll have to [should] look inside LazOpenGLContext for some hints.

In order to go off the not so beaten track and be annoying then based on,

viewtopic.php?f=19&t=8746

I tried.. 'vertex arrays' in a new project.

Code:
  1. unit Unit1;
  2.  
  3. {$mode Delphi}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  9.   LCLType, LCLIntf, OpenGLContext, gl, glu;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormResize(Sender: TObject);
  17.   private
  18.     { private declarations }
  19.   public
  20.     { public declarations }
  21.   end;
  22.  
  23.   { TOGLControl }
  24.   TOGLControl = class(TOpenGLControl)
  25.   private
  26.     { private declarations }
  27.   public
  28.     { public declarations }
  29.     procedure Idle(Sender:TObject; var Done:boolean);
  30.   end;
  31.  
  32. var
  33.   Form1:       TForm1;
  34.   OGLControl:  TOGLControl;        //The OpenGL surface to be rendered to
  35.  
  36.   GridBufferX: Array of Gluint;    //Array for X Gridlines
  37.   GridBufferY: Array of Gluint;    //Array for Y Gridlines
  38.  
  39. implementation
  40.  
  41. { TForm1 }
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.   OGLControl := TOGLControl.Create(Self); //Create the OpenGL surface
  46.   With OGLControl do
  47.   begin
  48.     Parent             := Form1;    //Make Form1 the Parent
  49.     Align              := alClient; //Align to the Parent
  50.     Application.OnIdle := Idle;     //Redraw when nothing else is happening
  51.     AutoResizeViewport := true;     //Resize to Parent when Parent Resizes?
  52.   end;
  53. end;
  54.  
  55. procedure TForm1.FormResize(Sender: TObject); //Redo Grids when Form Resizes
  56. var
  57. ArrayLength: Integer;
  58. begin
  59.   ArrayLength := 1;
  60.   While ArrayLength*20 < OGLControl.Width do //Whilst we haven't dropped off
  61.   begin
  62.     SetLength(GridBufferX, ArrayLength*4); //Add another Four Gluints
  63.     GridBufferX[ArrayLength*4 - 4] := ArrayLength*20;    //X0:ArrayLengthX
  64.     GridBufferX[ArrayLength*4 - 3] := 0;                 //Y0:ArrayLengthX
  65.     GridBufferX[ArrayLength*4 - 2] := ArrayLength*20;    //X1:ArrayLengthX
  66.     GridBufferX[ArrayLength*4 - 1] := OGLControl.Height; //Y1:ArrayLengthX
  67.     INC(ArrayLength);
  68.   end;
  69.   ArrayLength := 1;
  70.   While ArrayLength*20 < OGLControl.Height do //Whilst we haven't dropped off
  71.   begin
  72.     SetLength(GridBufferY, ArrayLength*4); //Add another Four Gluints
  73.     GridBufferY[ArrayLength*4 - 4] := 0;                 //X0:ArrayLengthY
  74.     GridBufferY[ArrayLength*4 - 3] := ArrayLength*20;    //Y0:ArrayLengthY
  75.     GridBufferY[ArrayLength*4 - 2] := OGLControl.Width;  //X1:ArrayLengthY
  76.     GridBufferY[ArrayLength*4 - 1] := ArrayLength*20;    //Y1:ArrayLengthY
  77.     INC(ArrayLength);
  78.   end;
  79. end;
  80.  
  81. procedure TOGLControl.Idle(Sender:TObject; var Done:boolean);
  82. begin
  83.   {Some initialisation I do not 'fully' Understand}
  84.   glClearColor(1, 1, 1, 1);
  85.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  86.   glMatrixMode(GL_PROJECTION);
  87.   glLoadIdentity();
  88.   glOrtho(0, OGLControl.Width, OGLControl.Height, 0, 0, 1);
  89.   glDisable(GL_DEPTH_TEST);
  90.   glMatrixMode(GL_MODELVIEW);
  91.   glLoadIdentity();
  92.   {End of the initialisation}
  93.   glColor3f(0.5, 0.5, 0.5); //Set Colour for the following to Grey
  94.   glEnableClientState(GL_VERTEX_ARRAY);         //Set up to draw from Array[s]
  95.   glVertexPointer(4, GL_INT, 0, @GridBufferX);  //Point to GridX Array
  96.   glDrawArrays(GL_LINES, 0, High(GridBufferX)); //Draw from GridX Array
  97.   glVertexPointer(4, GL_INT, 0, @GridBufferY);  //Point to GridY Array
  98.   glDrawArrays(GL_LINES, 0, High(GridBufferY)); //Draw from GridY Array
  99.   glDisableClientState(GL_VERTEX_ARRAY);        //Turn off drawing from Array[s]
  100.   OGLControl.SwapBuffers;                       //Display the result
  101.   Done := True;
  102. end;
  103.  
  104. initialization
  105.   {$I unit1.lrs}
  106.  
  107. end.


Unfortunately I had to bend things from GL_LINE_STRIP to GL_LINES and have, naturally, broken things in the process..

Bild

:-(


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Di Feb 26, 2013 21:06 
Offline
Compliance Officer
Benutzeravatar

Registriert: So Aug 08, 2010 08:37
Beiträge: 460
Programmiersprache: C / C++ / Lua
sry if i see this false, but you put into one array the X-Coords and into the second the y-Coords?

You should save everything into one array:

X,Y,Z
X,Y,Z
X,Y,Z
...

_________________
offizieller DGL Compliance Beauftragter
Never run a changing system! (oder so)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Di Feb 26, 2013 23:23 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
Hi again..

What I am attempting to do is draw a grid for a cad program. I may have got things the wrong way around but the grid will comprise vertical lines, GridX, and horizontal lines, GridY. This is 2D so I don't think I need Z, happy to be wrong though.

At the moment I calculate points across GridX, and GridY, with the required spacing storing them in an array of Records with other data and then I draw the GridX and GridY Lines using, in the case of GridX..

Code:
  1. While Count < High(GridArrayX) do
  2. begin
  3.     glBegin(GL_LINES);
  4.       glVertex2f(GridArrayX[Count].GPointX, RPointA.Y);
  5.       glVertex2f(GridArrayX[Count].GPointX, RPointB.Y);
  6.     glEnd;
  7.     Count := Count + 1;
  8. end;


The end result looks like this,

http://img94.imageshack.us/img94/6523/s ... ot238e.png

This is a 'coarse' grid. It is the case that the user could request a grid structure that exceeds the display pixel limit. Perhaps I should think harder and I am tempted. For the moment it is possible for them to ask for huge numbers of lines to be drawn and, apparently and I believe it is the case, the glBegin/glEnd overhead cripples 'speed'...

I should shut up and think about doing things a different way.

I suppose or am guessing the above, in the 'vertex array' for a single line, would be written as,

XA0,YA0,XA1,YA1

Then, as in the code from my last message I iterate to produce an array with,

XA0,YA0,XA1,YA1
XB0,YB0,XB1,YB1
XC0,YC0,XC1,YC1
XD0,YD0,XD1,YD1
-
-
And so on and I do similar for GridY

I expect, but it does not happen because I am once again guessing incorrectly, that...

Code:
  1. glVertexPointer(4, GL_INT, 0, @GridBufferX);
  2. glDrawArrays(GL_LINES, 0, High(GridBufferX));


..should set up the vertexpointer to 'step' through the array 4 values at a time, for a start X,Y and end X,Y.. treating the data as GL_INT, not sure about 0 and @GridBufferX is the pointer to the beginning of the array. Then it draws the lines, GL_LINES, from the beginning of the array, 0, to the end of the array, High(GridBufferX).

I know I am wrong because it does not work. :o
I'm good that way. :D


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Di Feb 26, 2013 23:50 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
You should use a texture for the basic grids. Basically create a texture that can be repeated. Then draw a quad with that image (But with texture coordinates which make the image repeat).

A single Quad is far faster than using multiple lines. It however can only do the basic grid bits, not any additional lines.

P.S You will still need to supply the Z coords as OpenGL renders in 3D even when your doing 2D (Technically speaking it doesn't support 2D. Its just that you position the "Camera" so that it looks like its 2D)

Edit: Gluint is an Unsigned Integer. You should use a Signed Integer for the Grid Arrays.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 20 Beiträge ]  Gehe zu Seite 1, 2  Nächste
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.013s | 15 Queries | GZIP : On ]