Naive question on simple graphics lazarus / 61-Beginners ---------------------------------------------------------------------- Gravitas · 2025-01-05 18:02 Hello to all,  -- I wish you a Happy, Prosperous New Year, in good health (both physically and mentally). I have a naive question. In a Linux system (Void Linux, glibc edition), I am trying to get my feet wet with Pascal. I am using Tom Swan's old book on Turbo Pascal 4.0 and thus far is a smooth sailing. Thus far, basic programs run OK. So, the code snippet I have tried 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 program Test; uses CThreads, Crt, PtcGraph; var GD, GM : integer; begin      InitGraph(GD,GM, '..\BGI');        circle(100,100,50);        readln;        CloseGraph;end.  It compiles (i.e., there are no errors) without any warnings. Nevertheless, when I am trying to run the executable a get a blank window. Any help? Thank you in advance. PS #1. If it matters, due to ... nvidia GPU, I am using the old KDE on X11 rather than Wayland. PS #2. I have installed FPC through the official website, because the version of the package in the distribution is quite old. ---------------------------------------------------------------------- TRon · 2025-01-05 19:06 Are you sure there is only a blank window ? For me there is a very dark blue circle being displayed. There are some drivers (libraries that are usually available by default) required in order to run ptcgraph but if they are not loaded then an explicit error message will appear. ---------------------------------------------------------------------- Gravitas · 2025-01-05 19:16 Quote from: TRon on January 05, 2025, 08:06:35 pmAre you sure there is only a blank window ? For me there is a very dark blue circle being displayed. There are some drivers (libraries that are usually available by default) required in order to run ptcgraph but if they are not loaded then an explicit error message will appear. Hello! Yes, I am pretty sure... All the examples, I have found here and there on the Internet, and I tried give that black window. Do you know which libraries might be needed? Thank you. P.S. #1 I compile it by issuing: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ fpc blah.pas Is it correct? P.S. #2 At least, I have libXxf86vm and libXxf86vm-devel. ---------------------------------------------------------------------- TRon · 2025-01-05 20:01 Quote from: Gravitas on January 05, 2025, 08:16:34 pmYes, I am pretty sure... All the examples, I have found here and there on the Internet, and I tried give that black window. Do you know which libraries might be needed? As said, if not available then running the code form a console will inform which ones those are (you also already seem to have found them  ). QuoteP.S. #1 I compile it by issuing: Is it correct? Yes, that  should be ok. Though having said that you might perhaps want to switch to mode objfpc (either commandline or program header). try this: 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 program info; uses  cthreads,  ptcgraph, ptccrt;var  m: PModeInfo;  gd, gm: Integer;begin  Writeln('List of all modes:');  m := QueryAdapterInfo;  while m <> nil do  begin    Writeln(m^.MaxX+1, ' x ', m^.MaxY+1, ' x ', m^.MaxColor);    m := m^.next;  end;   Writeln('Now let''s find 1920x1080 with 16-bit colour...');  m := QueryAdapterInfo;  while m <> nil do  begin    if (m^.MaxX = (1920-1)) and (m^.MaxY = (1080-1)) and (m^.MaxColor = 65536) then    begin      InitGraph(m^.DriverNumber, m^.ModeNumber, '');      SetColor($FFFF);      OutTextXY(0, 0, 'Hurrah! Full HD 1920x1080 mode is available!');      ReadKey;      CloseGraph;      Halt;    end;    m := m^.next;  end;   Writeln('Mode not found in list!');end. And see what graphic modes are available (post output in case unsure). It might very well be that your system uses 24 or 32 bit graphics by default and as such does not have the colours initialized as expected. ---------------------------------------------------------------------- Gravitas · 2025-01-05 20:46 Quote from: TRon on January 05, 2025, 09:01:34 pmQuote from: Gravitas on January 05, 2025, 08:16:34 pmYes, I am pretty sure... All the examples, I have found here and there on the Internet, and I tried give that black window. Do you know which libraries might be needed? As said, if not available then running the code form a console will inform which ones those are (you also already seem to have found them  ). QuoteP.S. #1 I compile it by issuing: Is it correct? Yes, that  should be ok. Though having said that you might perhaps want to switch to mode objfpc (either commandline or program header). try this: 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 program info; uses  cthreads,  ptcgraph, ptccrt;var  m: PModeInfo;  gd, gm: Integer;begin  Writeln('List of all modes:');  m := QueryAdapterInfo;  while m <> nil do  begin    Writeln(m^.MaxX+1, ' x ', m^.MaxY+1, ' x ', m^.MaxColor);    m := m^.next;  end;   Writeln('Now let''s find 1920x1080 with 16-bit colour...');  m := QueryAdapterInfo;  while m <> nil do  begin    if (m^.MaxX = (1920-1)) and (m^.MaxY = (1080-1)) and (m^.MaxColor = 65536) then    begin      InitGraph(m^.DriverNumber, m^.ModeNumber, '');      SetColor($FFFF);      OutTextXY(0, 0, 'Hurrah! Full HD 1920x1080 mode is available!');      ReadKey;      CloseGraph;      Halt;    end;    m := m^.next;  end;   Writeln('Mode not found in list!');end. And see what graphic modes are available (post output in case unsure). It might very well be that your system uses 24 or 32 bit graphics by default and as such does not have the colours initialized as expected. I did what you mentioned with the console, and I get just a plain black window! Regarding your code (and I thank you very much for the trouble) it run OK ---see the attachments (although the font in the phrase seems tiny). I am extremely puzzled --I do not get anything! ---------------------------------------------------------------------- cdbc · 2025-01-05 21:07 Hi Try this: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 program Test; uses CThreads, ptcCrt, PtcGraph; var GD, GM : integer; ch: char; begin  GD:= VESA; GM:= 258;  InitGraph(GD,GM, 'BGI');  circle(100,100,50);  repeat    if keypressed then ch:= readkey;  until ch = 'q';  CloseGraph;end. Regards Benny edit: Might be more to learn in this thread. ---------------------------------------------------------------------- TRon · 2025-01-05 21:16 Quote from: Gravitas on January 05, 2025, 09:46:23 pmI did what you mentioned with the console, and I get just a plain black window! You are going too fast  QuoteRegarding your code (and I thank you very much for the trouble) it run OK ---see the attachments (although the font in the phrase seems tiny). Which means that ptcgraph works for you. It only seem to use another default graphics mode then I (or others) have. QuoteI am extremely puzzled --I do not get anything! As explained earlier when your system uses (read:favours) a graphics mode with more than 256 colours then the there is not an actual colour table and you need to manually provide colours. so in your example code ptc probably opens a 32 bit colour window and also probably using a black pen to draw the circle (hence invisible or black). I needed to know that first before suggesting something else (cdbc is getting ahead of me  ) Try this: 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 program test; uses  cthreads,  ptccrt,  ptcgraph; var  GD, GM : smallint;begin  GD := D8bit;  GM := m1280x1024;  InitGraph(GD,GM, '');   SetBkColor(white);  ClearViewPort;   setColor(cyan);  circle(100,100,50);  readln;  CloseGraph;end. That mode seem supported on your system and should display a 1280 by 1024 white window with a cyan circle. ---------------------------------------------------------------------- Gravitas · 2025-01-06 13:02 Quote from: TRon on January 05, 2025, 10:16:29 pmQuote from: Gravitas on January 05, 2025, 09:46:23 pmI did what you mentioned with the console, and I get just a plain black window! You are going too fast  QuoteRegarding your code (and I thank you very much for the trouble) it run OK ---see the attachments (although the font in the phrase seems tiny). Which means that ptcgraph works for you. It only seem to use another default graphics mode then I (or others) have. QuoteI am extremely puzzled --I do not get anything! As explained earlier when your system uses (read:favours) a graphics mode with more than 256 colours then the there is not an actual colour table and you need to manually provide colours. so in your example code ptc probably opens a 32 bit colour window and also probably using a black pen to draw the circle (hence invisible or black). I needed to know that first before suggesting something else (cdbc is getting ahead of me  ) Try this: 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 program test; uses  cthreads,  ptccrt,  ptcgraph; var  GD, GM : smallint;begin  GD := D8bit;  GM := m1280x1024;  InitGraph(GD,GM, '');   SetBkColor(white);  ClearViewPort;   setColor(cyan);  circle(100,100,50);  readln;  CloseGraph;end. That mode seem supported on your system and should display a 1280 by 1024 white window with a cyan circle. Hello dear friend! Yes, it shows a white background and a cyan (? the analysis and the general quality is bad...but I think is cyan). The thing is twofold: a) why the initial program does work to you and others but not me. The answer here (IF I understood it correctly) is that I am using the wrong display/graph mode (but, again, why?) b) what should I do next? Follow up questions: will be able to use things like Allegro/Raylib (without Lazarus, just plain Pascal)? Thanks ---------------------------------------------------------------------- TRon · 2025-01-06 13:39 Quote from: Gravitas on January 06, 2025, 02:02:30 pmThe thing is twofold: a) why the initial program does work to you and others but not me. The answer here (IF I understood it correctly) is that I am using the wrong display/graph mode (but, again, why?) Not a wrong display/graph mode but different. By not specifying a specific graphics mode PTC will default to your systems default graphics mode. This mode can be different for every individual system. By not knowing/inspecting the default graphics mode before drawing there is no way of knowing f.e. what the bitdepth of the graphics mode is (and with that how to specify a (default) pen colour). Because setting a pen colour was omitted in your example code this can default to any colour (including black or black enough to not being able to distinguish that colour when drawing with that pen on a black background). Quoteb) what should I do next? That completely depends on what you wish to accomplish with using PTCGraph. You should determine which graphics mode is required for your project needs. Does it require 24 bit or 32 bitr graphics or is 16 colours enough ? What dimensions should your graphical canvas have (or need) ? etc. etc. QuoteFollow up questions: will be able to use things like Allegro/Raylib (without Lazarus, just plain Pascal)? Yes for both. Also SDL/GL (note that PTC also supports GL) and probably many others. If your aim is to write a game and do not wish to meddle with graphical internal details then I would probably discourage using PTC. While possible to use PTC to create games it can be a bit daunting as it requires a lot of technical knowledge about graphics (such as bit- depths, pixel masking and shifting etc). Engines such as SDL or raylib comes accompanied with more higher level constructs that is able to make life much easier. They are especially targeted for writing games/animations etc or offer 3th party library that are able to aid in that process. ---------------------------------------------------------------------- Thaddy · 2025-01-06 14:10 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 uses{$ifdef unix}  cthreads,{$endif}  ptccrt,  ptcgraph;If you happen to be on Windows. ---------------------------------------------------------------------- TRon · 2025-01-06 14:14 You are absolutely right Thaddy. Thank you for the correction 👍 ---------------------------------------------------------------------- Gravitas · 2025-01-06 17:03 Quote from: TRon on January 06, 2025, 03:14:20 pmYou are absolutely right Thaddy. Thank you for the correction 👍 OK I see. Well, to answer your question: I am learning Pascal (the "original" --without OO stuff, hence the old book by Tom Swan, etc). My purpose is (well, IF I am able to complete the journey) to do some simple visualizations (not games) --mostly related to Mathematics and Physics (simulations, math graphs, etc). So I thought that the default Graphics Unit could be a good start. So, (perhaps to conclude) what do you propose (given, of course, that I will be continuing learning Pascal ! ) a) try to first learn the stuff like PtcGraph OR b) pass directly to Allegro/Raylib? In case a), is there any pedagogical documentation? I am asking this not because of laziness, but because what I found is very outdated  (e.g., mentions to Units which are not in use anymore). Thank very much for your kind and detailed answers. ---------------------------------------------------------------------- Thaddy · 2025-01-06 17:36 If I understand you correctly, you are famliar with crt, graph and the likes. Then there is no difference but the unit names! Same API. I guess it is more like catching up with the things you once knew. I suffer from the same sometimes. What is important, though, that if you use the ptc units instead of the olden names, your programs become cross platform! For free! ptc is just a prefix to unit names  you are already familiar with. (wel, not quite, but most of your old code will work by simply renaming the units in the uses clause to their ptc equivalents) ---------------------------------------------------------------------- Gravitas · 2025-01-06 18:35 Quote from: Thaddy on January 06, 2025, 06:36:44 pmIf I understand you correctly, you are famliar with crt, graph and the likes. Then there is no difference but the unit names! Same API. I guess it is more like catching up with the things you once knew. I suffer from the same sometimes. What is important, though, that if you use the ptc units instead of the olden names, your programs become cross platform! For free! ptc is just a prefix to unit names  you are already familiar with. (wel, not quite, but most of your old code will work by simply renaming the units in the uses clause to their ptc equivalents) Well, you are very optimistic I have learnt Pascal way.... to many years back, as a student. Now, I am trying to start over (just for fun). Essentially I am at the beginning of Swan's book (5th Chapter) -but I just wanted to try out a few simple graph stuff (for fun) --hence the thread. I have a long way yet. ---------------------------------------------------------------------- TRon · 2025-01-07 12:55 Quote from: Gravitas on January 06, 2025, 06:03:39 pmWell, to answer your question: I am learning Pascal (the "original" --without OO stuff, hence the old book by Tom Swan, etc). I was hinting more at what the graphical requirements are for the examples in your book  It does not really matter if you want to use OOP or not (PTCGraph can be used both methods, in fact PTC itself is written using OOP) QuoteMy purpose is (well, IF I am able to complete the journey) to do some simple visualizations (not games) --mostly related to Mathematics and Physics (simulations, math graphs, etc). So I thought that the default Graphics Unit could be a good start. If it is only a visual reprentation of data then your are probably fine using whatever graphical library. Going by the age of that book (Turbo Pascal 4) the graphical requirements are probably pretty low as in resolutions of 320x200 or 640x480 with a maximum of 256 colours (8 bit depth). QuoteSo, (perhaps to conclude) what do you propose (given, of course, that I will be continuing learning Pascal ! ) a) try to first learn the stuff like PtcGraph OR b) pass directly to Allegro/Raylib? In case learning Pascal and stick as close to the examples from the book I would probably suggest to use PTCGraph. PTCGraph is a good showcase of a introduction to graphics in general but unfortunately at the same time it is dated. The things that can be learned from it will be beneficial in the end because it allows for some fundamental basics to be learned. That knowledge is able to help you when using whatever other more modern graphical library. In case already being familiar with graphical engines/design/use then PTCGraph (or actually unit graph) can be a bit of a time waster as techniques and implementations have progressed over the years. Especially when considering a graphical interface such as LCL. QuoteIn case a), is there any pedagogical documentation? I am asking this not because of laziness, but because what I found is very outdated  (e.g., mentions to Units which are not in use anymore). The information your are able to find is outdated because the unit graph is outdated. As mentioned earlier things have progressed in all these years. I am not aware of the availability of modern documentation with regards to unit graph/crt. PTC in general is fairly undocumented (though the PTC units are compatible with their old turbo pascal counterparts for as much as possible) I am aware this comes across as discouraging the use of PTC (which it probably is) but in fact PTC a very cool library if you dive deeper into it mechanics/implementation. For example there is no need whatsoever to use things like SDL or BGRABitmap when PTC is able to produce the same graphical output just doing it in another way. It forces you to have a better understanding of graphical techniques and implementations and lacks all fancy features (that you would have to write yourself). As an old school programmer I am very appreciative that PTC exist. Sorry not being able to provide you with more information/documentation wrt unit graph. ---------------------------------------------------------------------- Gravitas · 2025-01-07 15:44 Quote from: TRon on January 07, 2025, 01:55:49 pm... Thank you very much for your answers -in total. 1. Well the book is old. I have not get in the point where it discusses graphics --the initial example is taken from another (short) book. 2. I agree, regarding the value of PtcGraph, yet, the quality is very bad (to my taste) --especially for simulations and math representations. In due course, I will try either Allegro or SDL2, or Raylib (I think, in all of them there are Pascal bindings). I just wanted to get my feet wet, for a while, and (above all) to check that my FPC installation works as expected. Again, thank you all for your kind replies! ---------------------------------------------------------------------- Thaddy · 2025-01-07 16:25 Can you elaborate on 2), because you are very wrong in my opinion: it is of the highest quality: - it supports 35+ year old TP style pascal and all those old units like crt,graph etc. - it is cross-platform - the sourcecode is professionally written and very clear - to summarize: if you don't like it, then in my opinion you do not know what you are doing. My own serious experience with Pascal dates from 1980 at University. Two years later I taught it to my fellow students in an educator role (payed by the University). To summarize: the ptc units are the new 40 year old code, no changes in use, no changes in syntax. If you could use it 40 years ago, you can use it now. And you can use the olden documentation too for 80% or more. ---------------------------------------------------------------------- Gravitas · 2025-01-08 08:21 Quote from: Thaddy on January 07, 2025, 05:25:24 pmCan you elaborate on 2), because you are very wrong in my opinion: it is of the highest quality: ... Hello. I would not disagree with you about the quality of the work -besides, I do not have neither your knowledge, nor your expertise. What I said is just a matter of aesthetics and personal preference regarding the output -as compared to things I have seen e.g., in C and Raylib. On the other hand, as TRon has indicated, I am lacking the fundamentals of the system --something which could, perhaps, explain the bad result (i.e., I might be misusing the unit). Again, thank you all. ---------------------------------------------------------------------- TRon · 2025-01-08 11:44 As a sidenote: The code that I suggested to use/test was only meant for the purpose of testing (in order to check whether or not PTCGraph worked for that system). The code was not meant to be used as a showcase for PTCGraph (other than showing what basics steps needs to be done in order to produce some graphical output). Because the mention of a book aimed at turbo pascal 4 you should also not expect high standard graphics from the examples listed in that book. Books addressed at earlier versions of Turbo pascal probably even only showed examples using only black and white graphics. I/we cannot read your mind, do not know your time-schedule or know anything about your enthusiasm and/or persistence. Let alone know anything about future plans. If your have done the research on the different available graphical frameworks/libraries and have more or less have developed a preference for a particular library then by all means invest your time in/for that library. Do note that most libraries such as castle, raylib, sdl etc. are more aimed at developing games. As such these are most probably not specifically aimed at f.e. displaying  statistics, 3d-models, technical data etc while other libraries (not specifically aimed at games) might have specific provisions for such things. Having said that and as long as the library (any which one) is able to draw a pixel on some sort of canvas and you have the knowledge then everything you are able to come up with is possible to represent in graphics with such library. ---------------------------------------------------------------------- Gravitas · 2025-01-08 12:43 Quote from: TRon on January 08, 2025, 12:44:24 pmAs a sidenote: ... Hello, I totally agree with you. As I have said, I am learning (because the student years, in which I learnt Pascal, seem now extremely vague) (again) Pascal -in my spare time. I am not into CS studies/prof -it is just a hobby. Of course I am open to try well established things -instead of going to new ones. But, if not mistaken, you said that you were not aware of any contemporary reference on PtcGraph. Also, I was not able to find anything (but this does not mean something, since I am an amateur). The only reason I mentioned Allegro (with I know that it is used e.g., in FreeOberon) and Raylib, is because (I think that) I can find references. Perhaps I could get the same visually appealing result in PtcGraph, but I do not know where to find references ;-) P.S. Swan's book is used just to learn Pascal (without OO) in general -it has nothing to do with graphics and animations/simulations (besides it is around 800 pages, so no space for such a thing). ---------------------------------------------------------------------- TRon · 2025-01-08 12:58 Quote from: Gravitas on January 08, 2025, 01:43:36 pmBut, if not mistaken, you said that you were not aware of any contemporary reference on PtcGraph. Also, I was not able to find anything (but this does not mean something, since I am an amateur). I mentioned in specific PTC (The underlying framework that is used to build PTCGraph/PTCCrt/PTCPas/etc). Because they are compatible (at least as compatible as possible) PTCGraph -> unit graph PTCCrt -> unit crt And ofc. about any tutorial you are able to find (online) that uses unit Graph and unit CRT Homepage of PTCPas Raylib for lazarus, Raylib (references in c but should be 1:1 compatible). The Pascal developers of Raylib are fairly active on this forum. Allegro wikientry wiki game-engines QuoteP.S. Swan's book is used just to learn Pascal (without OO) in general -it has nothing to do with graphics and animations/simulations (besides it is around 800 pages, so no space for such a thing). Aha, ok. Thank you for mentioning that because I was not aware (I am not familiar with the contents of that book). ---------------------------------------------------------------------- Gravitas · 2025-01-08 13:40 Quote from: TRon on January 08, 2025, 01:58:08 pm Aha, ok. Thank you for mentioning that because I was not aware (I am not familiar with the contents of that book). Many thanks for the references. Swan's book is very nice. Ditto for "Oh! Pascal" by D. Cooper and M. Clancy. On a more advanced level (I do not think to be able to get there), "on Pascal Compilers" by B. Hansen.