hhvn.uk

Website, gopher, etc
git clone https://hhvn.uk/hhvn.uk
git clone git://hhvn.uk/hhvn.uk
Log | Files | Refs | Submodules

raylib.txt (4635B)


      1 Title: Mini-rant on raylib
      2 Date: 2022-11-26
      3 Tags: raylib rant cepheid
      4 
      5 This is copied from the README of git://hhvn.uk/cepheid (a new-ish project of
      6 mine).
      7 
      8 ---
      9 
     10 I selected raylib as I was hoping it would be a good enough abstraction layer
     11 between X11/opengl/etc and "draw a line here". My opinion so far is that it's
     12 alright.
     13 
     14 I can definitely say it's easy to use when you're using it as intended, as
     15 raylib handles most data structures itself, and doesn't require any allocation
     16 of data. There's no raylib_ctx_init(), and passing the same struct to every
     17 single function (when functions need to be aware of some context there is
     18 usually a BeginSomething() function that will tell raylib to be aware of that
     19 until the EndSomething() later on, which is a pretty sweet way of handling
     20 things).
     21 
     22 raygui, however, is an absolute piece of shit, IMO. I find the whole
     23 "modulization" thing pretty dumb: all components of raylib have the same
     24 dependencies - you save practically nothing from splitting it up into multiple
     25 parts. The .a/.so and .h model works fine for raylib itself, so why does raygui
     26 have to be implemented in a header when it could all be present in raylib.so? As
     27 far as I can tell, the only way to style the gui (that won't cause you to rip
     28 your hair out) is to use a styling program written by the author. As of the
     29 start of this project I couldn't find the source code anywhere, and the only
     30 place that it could be run was online. I'm sure I could've asked somewhere, but
     31 at that point I couldn't be bothered trying to deal with raygui and decided to
     32 implement my own.
     33 
     34 Honestly, I'm kind of happy that I didn't go with raygui, as writing my own gui
     35 has been fun.
     36 
     37 raylib has other issues though. I said earlier that it's good if you "use it as
     38 intended". That's because there are plenty of small features that could be very
     39 handy but the author decided shouldn't exist.
     40 
     41 One example of this is support for multiple windows, this is a feature that has
     42 been created (https://github.com/raysan5/raylib/wiki/Use-multiple-windows)
     43 before. I understand why this hasn't been merged with raylib itself - it
     44 wouldn't work with the web as a target - but still, I don't care about the web,
     45 and I don't care to maintain a fork of raylib for this project, why can't it
     46 just be there for the targets that do support it? The only visible change to
     47 anyone using raylib would be to BeginDrawing(), but there could instead be a
     48 BeginDrawingWindow() function that takes a context id, and produce a warning if
     49 both BeginDrawingWindow() and BeginDrawing() are used in the same program.
     50 
     51 Another issue is the handling of keyboard input. In order to get text input, the
     52 GetCharPressed() function exists, which returns a wchar_t. Great, right? No.
     53 Because it doesn't return backspaces. Even though they are ASCII characters.
     54 Okay, so I can just use IsKeyPressed() right? Nope, because that won't deal with
     55 they key being held down. So instead I have to implement a function that counts
     56 frames and every n frames says it's pressed. So I just have to find the delay
     57 that X11 uses between emitting key presses when a keys is held and hardcode
     58 that, right? Nope. Nope. Nope. Because X11 has settings which allow you to
     59 change that, and since raylib is meant to be dealing with X11 I can't query
     60 that, so what should be a setting that applies globally to all X11 applications
     61 doesn't apply to cepheid because I can't make it.
     62 
     63 raylib also isn't very good at drawing big shapes. For example, the orbits of
     64 planets. By default raylib only draws rings with 36 segments, which really isn't
     65 enough when less than 1° is shown on screen (ie, zoomed into a planet). Cranking
     66 up this number indiscriminately isn't a very good idea either, as the
     67 performance goes bye bye. So yet again, I'm having to fight with raylib to try
     68 to get it to work somewhat well. The solution at the time of writing (701a5de)
     69 is a function that calculates the number of segments to draw based on the
     70 radius, and estimates at what degrees the ring should start and end at (see
     71 ui_draw_ring). Along with that, draw_orbit() does various checks to prevent
     72 unecessary drawing in the first place. With this I'm able to get 60fps on a
     73 "Intel i5 M 520 (4) @ 2.400GHz"'s integrated GPU displaying all the planets in
     74 the solar system, but turn it on for all the dwarf planets and asteroids...
     75 
     76 I would have hoped that raylib with deal with this for me.
     77 
     78 After seeing this blog post,
     79 https://www.bit-101.com/blog/2022/11/coding-curves-03-arcs-circles-ellipses/
     80 I'm considering writing my own function for drawing orbits, but this will depend
     81 on the performance of drawing a lot of lines.