Substitution for HDC and HGLRC in Linux lazarus / 61-Beginners ---------------------------------------------------------------------- jcaser1948 · 2018-03-11 15:32 I try to convert some programs from CorpsmanDE from Delphi to Lazarus in Linux Opensuse Linux 42.3 Lazarus 1.8.2 I have the following Code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Unit Unit1; {$MODE Delphi} Interface Uses  LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  ExtCtrls, dglopengl, Cubes, StdCtrls, GLU,GL; Type  TForm1 = Class(TForm)    Panel1: TPanel;    Timer1: TTimer;    Animate_timer: TTimer;    CheckBox1: TCheckBox;    Procedure FormCreate(Sender: TObject);    Procedure FormDestroy(Sender: TObject);    Procedure FormResize(Sender: TObject);    Procedure FormKeyDown(Sender: TObject; Var Key: Word;      Shift: TShiftState);    Procedure Timer1Timer(Sender: TObject);    Procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,      Y: Integer);    Procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    Procedure Animate_timerTimer(Sender: TObject);    Procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    Procedure CheckBox1Click(Sender: TObject);  private    { Private-Deklarationen }  public    { Public-Deklarationen }    // The Render Function    Procedure Render;  End; Var  ScreenWidth: integer = 640;  ScreenHeight: Integer = 480;   Form1: TForm1;  // OpenGL Handles  DC: HDC; //Handle auf Zeichenfläche  RC: HGLRC;  Initialized: Boolean = False;  // The Cube that should be rotated  blub: TBasicCube;  // save the old mouse coords  oox, ooy, ox, oy: Integer;  lb, lbo: Boolean;Implementation                     What can I use in Linux instead of HDC and HGLRC?. As far as I understand it, those handles exist only in Windows Thanks again ---------------------------------------------------------------------- Thaddy · 2018-03-11 16:23 For both you can use (system.)THandle. THandle is weakly typed. In trunk you can now use OpaquePointer, which is more correct. OpaquePointer is strongly typed.(And types that derive from it too) In this case it does not matter too much. Old code can still use system.THandle. ---------------------------------------------------------------------- jcaser1948 · 2018-03-11 16:42 Thanks,I will use it ---------------------------------------------------------------------- jcaser1948 · 2018-03-11 17:40 The substitution works,but I still have some questions Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure Tform1.Render;Begin  If Initialized Then Begin    // Clearscreen    glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);    glViewport(0, 0, panel1.width, panel1.height);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity;    gluLookAt(0, 0, -10, 0, 0, 0, 0, 1, 0);    // Render the Cube    blub.render;     SwapBuffers(dc);  End;End; Procedure TForm1.FormCreate(Sender: TObject);Const  Lambient: Array[0..3] Of Single = (0.75, 0.75, 0.75, 1);  Lpos: Array[0..3] Of Single = (1, 10, 0.5, 1);Begin  lb := false;  lbo := False;  // Setup OpenGL  DC := GetDC(panel1.Handle);  RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);  ActivateRenderingContext(DC, RC);  glEnable(GL_CULL_FACE);  glCullFace(GL_Back);  // Enable Depth Test  glEnable(GL_DEPTH_TEST);  // Set Detph Function  glDepthFunc(GL_LEQUAL);  // Set Clear Color = black  glClearColor(0, 0, 0, 0);  // Disable Rendering via VCL for Panel1  Panel1.FullRepaint := false;  // Set the OpenGLpanel to Full window size.  Panel1.Align := alClient;   // add some light  glLightfv(GL_LIGHT0, GL_AMBIENT, @Lambient);  glLightfv(GL_LIGHT0, GL_POSITION, @Lpos);  glEnable(GL_LIGHT0);  glEnable(gl_lighting);   blub := TBasicCube.create;  // Resize Window  OnResize(Nil);  // Set OpenGL initialized  Initialized := true;End; Procedure TForm1.FormDestroy(Sender: TObject);Begin  // Free OpenGL  Initialized := false;  blub.free;  DeactivateRenderingContext;  DestroyRenderingContext(RC);  ReleaseDC(panel1.Handle, DC);End; I reckon the followig procedures are connected to Open Gl commands SwapBuffers(dc);  RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);   ActivateRenderingContext(DC, RC);  DeactivateRenderingContext;   DestroyRenderingContext(RC);   ReleaseDC(panel1.Handle, DC);  Where can I find out what they do? What can I use in Linux to substitute them? Thanks again ---------------------------------------------------------------------- soerensen3 · 2018-03-11 23:18 I have no idea (I use SDL2 for a context and not the LCL), but please note the laz_opengl package which you can get for example through the online package manager. It contains the dglHeader and it has an OpenGL Panel. This could spare you some work or you could look how they did the context creation. As far as I know there is no cross platform way to get a context. You need to use ifdef's and treat each platform separately. This is why I would suggest using a ready lcl control. I have to add that I didn't test it myself, though. ---------------------------------------------------------------------- jcaser1948 · 2018-03-12 07:10 Thanks again ---------------------------------------------------------------------- Thaddy · 2018-03-12 09:48 Quote from: soerensen3 on March 12, 2018, 12:18:19 am As far as I know there is no cross platform way to get a context. That's not true. In trunk there is a cross platform way. I explained that before (as did Maciej a.k.a. HNB). The case is the driver has a record that it maintains by itself. For FPC it is sufficient to know that is it is a record being passed around. This was usually solved by using an untyped pointer (or type "pointer"). I fixed that to point to a structure, so the compiler knows it is a structure (record, class, object). Introduced is: OpaquePointer = type ^TEmptyRecord; TEmpyRecord = record end; Note the record is not really empty, it is opaque, because you do not access it directly. You pass it around. Hence you can now obtain a context in a cross-platform way. The context is solely handled by the underlying library, but by using OpaquePointer as pointer type it is now type safe. In C(++) this is resolved in a much less elegant way. using macro's. I can elaborate on this if you do not fully understand this. Basically OpaquePointer is a new root type (like untyped pointer, but now fully types) which you can use to create things like so: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  type TContext = type OpaquePointer; // compiler now knows....It is not just a raw pointer Which takes most difficulties out of making such a pointer to a structure cross-platform. After all: it is the library that needs the structure, not your own code.... Examples are still rare, but expect them to be multiple soon. E.g. upcoming new headers for OpenGL, EGL, OpenVG, loads of library interfaces. And mOrmOt uses it already! And the latest rtl-generics updates from this week. In the case of OpenGLES2, I could remove the current dependency on X in seconds..... And unify code for Unix and Windows platforms by removing a lot of ifdef's. ---------------------------------------------------------------------- jcaser1948 · 2018-03-14 07:27 A very interesting contribution.Thanks,Thaddy