An opengl canvas with signed distance fonts lazarus / 70-OpenGL ---------------------------------------------------------------------- marcov · 2015-11-28 17:01 In the past I've dropped hints that I was working on something OpenGL, well, here it is :-) It is a simple texture with a layered overlay of primitive types (text, rectangles, lines, circles) with pan and zoom, optimized for speed in camera/vision applications. One overlay overlays the picture, one functions as HUD. The font support is based on signed distance fonts. The test project is not multiplatform (so windows only, win64 should be ok), though many units are relatively platform independent. http://www.stack.nl/~marcov/standaloneglv3.zip (exe and source) Requires Delphi XE3+ or FPC 3.1.1+/Lazarus trunk.   FPC3.0 might work, but requires the only recently committed new records-with-methods versions of TPoint(f) and TRect(f), so won't work out of the box ---------------------------------------------------------------------- Ocye · 2015-11-30 12:29 Many thanks for sharing your code. But I wonder that yours as well as many other OpenGL toolkits is based on dglOpenGL instead of TOpenGLContext which is part of the FCL. It adds a lot of unnecessary dependency and incompatibility. For instance, if I want to adopt one your font classes I cannot just add it. I'd rather have to read and understand the code in order to replicate it for my project. And having a project that is "not multiplatform" contradicts the idea of Freepascal, IMHO. Please don't read the text as an insulting. To me it's a pity that a lot of work is done for nothing. ---------------------------------------------------------------------- marcov · 2015-11-30 13:33 Quote from: Ocye on November 30, 2015, 01:29:32 pmMany thanks for sharing your code. But I wonder that yours as well as many other OpenGL toolkits is based on dglOpenGL instead of TOpenGLContext which is part of the FCL. Afaik topenglcontrol is a separate component (in components/) and not part of the LCL, let alone the FCL) But that doesn't matter, the reason is very visible in the original post, it can be compiled with Delphi, so unnecessary Lazarus components are avoided (besides, the codebase is older than the topenglcontrol component) Quote adds a lot of unnecessary dependency and incompatibility. For instance, if I want to adopt one your font classes I cannot just add it. I'd rather have to read and understand the code in order to replicate it for my project. Well, if you think TOpenGLControl is great, port it to Delphi and have it added to dglopengl? If you want to make it universal, make sure it is available everywhere. QuoteAnd having a project that is "not multiplatform" contradicts the idea of Freepascal, IMHO. IMHO that is nonsense. The FPC packages and even RTL have many units that are only for one OS (-type). Yes, some common functionality is abstracted, but not all code (and even less, user's) should be multiplatform. We are not Java with a state-in-a-state abstraction. (though strictly speaking it quite portable, since many font solutions are based on ported X packages  and this one is not) QuotePlease don't read the text as an insulting. To me it's a pity that a lot of work is done for nothing. IMHO it is a redundant since the original post made the delphi and windows usage clear.  You can port it to openglcontrol and other OSes if you like/need that.  I might test multi-OS myself one day for fun, but it is not a priority.  I've no interest in openglcontrol, unless it is ported, I think the pascal opengl community is too small to fragment it unnecessarily over Delphi and FPC. ---------------------------------------------------------------------- Ocye · 2015-11-30 14:32 Okay, if you start from Delphi it makes sense. I didn't touch it after 2.0. Good point to understand why people do things differently. ---------------------------------------------------------------------- aradeonas · 2015-11-30 14:50 Interesting code marcov. I just talking about OpenGL GUI in MailList and I dont know your system can help it ot not. Can you explain more or maybe check MailList? ---------------------------------------------------------------------- marcov · 2015-11-30 15:22 Quote from: aradeonas on November 30, 2015, 03:50:39 pmInteresting code marcov. I just talking about OpenGL GUI in MailList and I dont know your system can help it ot not. Can you explain more or maybe check MailList? This is not an opengl gui or even going in that direction.  It is reasonably modern opengl use though, and if you would like an opengl GUI, you could maybe reuse code, specially the font support. But currently it doesn't even feature wrapping (because it is an "infinite" canvas) Moreover this demo requires quite modern GPU hardware (geometry shaders), only to accelerate uploading, and many older Socs don't do geometry shaders (or not efficiently) So probably only as an help to learn a bit more advanced (and that depends on viewpoint) OpenGL ---------------------------------------------------------------------- aradeonas · 2015-11-30 15:23 Thank you. ---------------------------------------------------------------------- marcov · 2016-03-17 09:45 I haven't done much on this the last two months, but in january I found that you can improve the look of the fonts significantly by playing with the discard cutoff in the newtextfrag shader source. Locally I changed it from .1 to .4 and that made the fonts more streamlined andbetter looking. ---------------------------------------------------------------------- PeterX · 2024-06-07 11:48 Quote from: marcov on November 28, 2015, 06:01:19 pmThe font support is based on signed distance fonts. The test project is not multiplatform (so windows only, win64 should be ok), though many units are relatively platform independent. http://www.stack.nl/~marcov/standaloneglv3.zip (exe and source) Hi marcov, this link is invalid now. Can I get it somewhere else ? Thanks, Peter ---------------------------------------------------------------------- marcov · 2024-06-07 13:29 Here it downloads, but I have to explicitely allow it, since it contains an EXE ---------------------------------------------------------------------- PeterX · 2024-06-07 17:27 Quote from: marcov on June 07, 2024, 03:29:44 pmHere it downloads, but I have to explicitely allow it, since it contains an EXE You're right, on the job the rules prevented the download.  Thanks ! ---------------------------------------------------------------------- PeterX · 2024-06-07 19:55 Okay .. show stopper now is 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   TBW8ImageOnSelect = function (sender:TObject;x,y:integer;Button: TMouseButton; Shift: TShiftState):integer of Object;  Tonloadoverlay = procedure (meta:TOverlaydata) of object;  TBW8ImageOnSelectCollection = TList;  => TList Projekt kompilieren, Modus: Release, Ziel: D:\Lazarus Projects\standaloneglv3\lib\i386-win32\standalonegltest.exe: Exit code 1, Fehler: 4, Warnungen: 12, Hinweise: 33 ... glblitter.pas(542,7) Note: Local variable "elementformat" not used glblitfrm.pas(32,56) Error: Identifier not found "TList$1" glblitfrm.pas(32,57) Error: Illegal expression glblitfrm.pas(86,22) Error: Illegal expression glblitfrm.pas(166,29) Error: Type "TBW8ImageOnSelectCollection" is not completely defined I probably should not try to compile it with Lazarus (3.2) ? ---------------------------------------------------------------------- PeterX · 2025-02-27 10:35 Hi Marcov,, what's up with this code piece ? I never saw '<' or '>' in Lazarus sourececode. Does this only work in Delphi ? 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 TBW8ImageOnSelectCollection = TList[b][/b]; Okay, problem seems to be that there's no '\x.bmp' 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   bw8image.LoadImage( GetExeDir +'\x.bmp', nil); ---------------------------------------------------------------------- TRon · 2025-02-27 10:43 Quote from: PeterX on February 27, 2025, 11:35:18 amI never saw '<' or '>' in Lazarus sourececode. Those are used when defining generics. QuoteDoes this only work in Delphi ? No, generics are also part of Free Pascal. Note that mode delphi and mode objfpc work slightly different wrt to generics. See also reference manual Chapter Generics. ---------------------------------------------------------------------- marcov · 2025-02-27 10:45 Nearly all my code is $mode delphi. But usually it is specified in the source. ---------------------------------------------------------------------- PeterX · 2025-02-27 10:55 Quote from: marcov on February 27, 2025, 11:45:35 amNearly all my code is $mode delphi. But usually it is specified in the source. Is the following link still valid ? Did You do any changes to the code since 07/2024 ? Quote from: marcov on November 28, 2015, 06:01:19 pmhttp://www.stack.nl/~marcov/standaloneglv3.zip (exe and source) ---------------------------------------------------------------------- marcov · 2025-02-27 12:56 The download works. There has been new development since then, but I don't have something I can package separately. ---------------------------------------------------------------------- PeterX · 2025-02-27 13:53 Quote from: marcov on February 27, 2025, 01:56:28 pmThe download works. There has been new development since then, but I don't have something I can package separately. Thanks !  I'm on the job and download ist blocked here. So I'll do the download this evening. ---------------------------------------------------------------------- TRon · 2025-02-27 14:00 fwiw: I had to remove some windows from unit clauses, then Code: [Select]Compile Project, Mode: Release, Target: /media/projects/fpc/standaloneglv3/standalonegltest: Exit code 1, Errors: 4 generics.defaults.pas(2786,31) Error: Generics without specialization cannot be used as a type for a variable generics.defaults.pas(2784,45) Error: function header doesn't match any method of this class "class Default(TExtendedHashFactoryClass):;" generics.defaults.pas(2779,45) Error: Found declaration: class Default :TExtendedEqualityComparer$1.IExtendedEqualityComparer$1; Static; generics.defaults.pas(810,20) Error: Found declaration: class Default( TExtendedHashFactoryClass):TExtendedEqualityComparer$1.IExtendedEquali tyComparer$1; Static; Does the project (still) requires trunk or should 3.2.2 be able to handle that (or perhaps downgrade from 3.2.2 to ...) ? PS: No importance for me as I just gave it a spin in order to see if and what kind of hurdles might be encountered. ---------------------------------------------------------------------- PeterX · 2025-02-27 15:26 Quote from: TRon on February 27, 2025, 03:00:06 pmCode: [Select]generics.defaults.pas This and other such files are already in folder C:\lazarus\fpc\3.2.2\source\packages\rtl-generics\src ---------------------------------------------------------------------- TRon · 2025-02-27 18:44 Quote from: PeterX on February 27, 2025, 04:26:16 pmThis and other such files are already in folder Ah yes, good hint. Thank you PeterX. That helped with getting through compiling all the generics related code. 25+ windows related snippets commented to finally end up with FPC in a nearly endless loop in an attempt to locate the dglopengl unit going back'n'forth between FPC packages directory and Lazarus components directory (not once it tried to locate the file in the current folder). Unless I overlooked some setting that forces this behaviour,  I have to give up (had to do that anyways because there is too many windows API calls to simply fix that on short notice). ---------------------------------------------------------------------- marcov · 2025-02-27 19:41 Afaik the creation of an opengl context is somewhat OS specific, and also some of the (non signed distance) WGL font routines are. ---------------------------------------------------------------------- PeterX · 2025-02-27 19:46 I just found something about Signed Distance Field Fonts https://www.redblobgames.com/x/2403-distance-field-fonts/ Unfortunately this one for Linux and Mac only: https://github.com/ShoYamanishi/SDFont ---------------------------------------------------------------------- PeterX · 2025-02-28 09:10 Quote from: TRon on February 27, 2025, 07:44:23 pmQuote from: PeterX on February 27, 2025, 04:26:16 pmThis and other such files are already in folder Ah yes, good hint. Thank you PeterX. That helped with getting through compiling all the generics related code. Example code that doesn't run with the actual Lazarus release version ( currently 3.8 ) is always difficult and mostly unusable for the average User. ---------------------------------------------------------------------- marcov · 2025-02-28 09:59 I think I originally generated my fontmaps with bmfont. At some point I also used Hiero, a Java thingy. ---------------------------------------------------------------------- JernejL · 2025-02-28 11:37 Awesome! good to see more people doing GPU stuff in lazarus / fpc. Next example: Animated & skinned meshes using assimp? ---------------------------------------------------------------------- marcov · 2025-02-28 11:49 I only do 2D things, it is for work.  This program was a kind of unit test that later became a benchmark of the second iteration of that functionality. The first generation was based on a demo made by Almindor in 2007-2008 timeframe. Since then I have added things like false color textures and I'm currently trying to fix signed fonts when the texture is shown 90 degrees rotated. The texture itself and the other overlay bits are ok, but signed distance fonts are garbled. ---------------------------------------------------------------------- PeterX · 2025-02-28 14:02 Quote from: marcov on February 28, 2025, 10:59:45 amI think I originally generated my fontmaps with bmfont. At some point I also used Hiero, a Java thingy. Thanks for this link, I'll try that. Maybe I can get these ä ö ü and other chars like '°' onto the OpenGL .. ---------------------------------------------------------------------- marcov · 2025-02-28 14:38 ChrisR (last name Rorden iirc), did some opengl on the Mac, including multi channel signed distance fonts. Searching on the forum for signed distance and look at the first few pages of results might yield some interesting threads. From my notes is that while I started with bmfont, I moved to sdfont later I think, because I couldn't get Hiero to work half of the time. E.g. https://forum.lazarus.freepascal.org/index.php/topic,37470.msg255 979.html#msg255979 ---------------------------------------------------------------------- PeterX · 2025-03-01 12:06 Quote from: PeterX on February 28, 2025, 03:02:01 pmQuote from: marcov on February 28, 2025, 10:59:45 amI think I originally generated my fontmaps with bmfont. At some point I also used Hiero, a Java thingy. Thanks for this link, I'll try that. I must say this page still exists but download is impossible. "Grab a binary version here:     distance_field.exe.7z" There's a working link on the WayBack Machine Quotehttps://web.archive.org/web/20140821105038/http://www.bitsquid.se /files/distance_field.exe.7z ---------------------------------------------------------------------- ChrisR · 2025-05-01 00:41 My cross platform Lazarus solution is here (project 5)   https://github.com/neurolabusc/OpenGLCoreTutorials You can see compiled open source applications that use these here   https://github.com/neurolabusc/surf-ice/releases and here   https://github.com/rordenlab/MRIcroGL/releases The previously listed redblobgames articles is a great introduction, and both that work and my own rely on this core font generator   https://github.com/Chlumsky/msdf-atlas-gen