rlsw – Raylib software OpenGL renderer in less than 5k LOC

162 pointsposted 10 hours ago
by fschuett

41 Comments

ciroduran

8 hours ago

Raylib's author was very happy to announce that you can compile an entire raylib program with no dependencies other than, say, being a win32 app https://x.com/raysan5/status/1980322289527976202

flohofwoe

7 minutes ago

OTH there's not much of a difference between a plain Win32 app and a D3D app, the D3D headers and DLL stubs are part of the Windows SDK (and even the mingw2 headers), and the required DLLs are guaranteed to exist just like kernel32.dll etc... e.g. being able to build and run a Win32 app also implies being able to build and run a D3D app.

smlacy

6 hours ago

but ... why?

zamadatix

6 hours ago

The mantra for the library is "raylib is a simple and easy-to-use library to enjoy videogames programming." It's for hobbyist, learners, tinkerers, or just those that want to enjoy minimalistic graphics programming without having to deal with interfacing with modern machines yourself.

The default Windows installer bundles the compiler and a text editor to make poking at C to get graphics on the screen (accelerated or not) a 1 step process. Raylib is also extremely cross platform, has bindings in about every language, and has extra (also header only, 0 dependency) optional libraries for many adjacent things like audio or text rendering.

When I first started to learn C/C++ in the 2000s I spent more time fighting the IDE/Windows/GCC or getting SDL/SFML to compile than I did actually playing with code - and then it all fell apart when I tried to get it working on both Linux and Windows so I said fuck it and ignored that kind of programming for many years. Raylib is about going the opposite direction - start poking at C code (or whatever binding) and having it break and worry about the environment later when you're ready for something else.

pjmlp

11 minutes ago

I never ever bothered to compile SDL/SFML from source, what is so hard dumping the binaries into a folder, set the include paths for the compiler and linker?

Although I may imagine newbies may face some challenges dealing with compiler flags.

stodor89

28 minutes ago

Because GPU APIs are a nightmare clustertruck.

foota

6 hours ago

As someone who was once a child trying to figure out how to compile and link things to use SDL, I think there's some educational value in letting people make games without having to dive deep into how to use C++ toolchains.

SJC_Hacker

6 hours ago

If you want to do that, skip C++ entirely and just use Javascript or Python. You can get shiny things really quickly.

irilesscent

5 hours ago

I think there's still value in learning the C++ language and making a game or a demo is quite rewarding although raylib does have bindings for basically every conceivable language.

pjmlp

10 minutes ago

Agreed, especially since it is the main language in the games industry, however that doesn't mean it should be the very first experience.

rererereferred

an hour ago

Why not? The original Doom didn't use a GPU renderer. It should be possible to do simple 3d stuff in today's computers without it.

abnercoimbre

5 hours ago

I mean this with all the appropriate venom we can muster: this attitude is why software quality is nonexistent.

az09mugen

2 hours ago

Curious to hear the take Tsoding has on that news.

JoeDohn

29 minutes ago

he gonna drop it, since it's a main stream thing now and it did hit hn :D.

pbohun

4 hours ago

What's cool about this is that computers are so fast that you could probably make a decent 2D game using only this software-rendered OpenGL 1.1 library.

pjmlp

8 minutes ago

Software rendering is the future anyway, with the caveat that it is actually hardware accelerated, by making use of compute (GPGPU).

YesBox

4 hours ago

Edit: I missed this was software rendered. I’m one gen-iteration ahead. Prob would still be possible to render my game cpu side provided I use the most efficient sprite depth ordering algorithm possible (my game is isometric pixel art like rollercoaster tycoon)

Ha! That’s what I’m stuck with for Metropolis 1998. I have to use the ancient OpenGL fixed function pipeline (thankfully I discovered an AB extension function in the gl.h file that allows addition fields to be passed to the GPU).

I’m using SFML for the graphics framework which I think is OpenGL 1.x

Game to show what’s possible: https://store.steampowered.com/app/2287430/Metropolis_1998/

dandersch

2 minutes ago

> I have to use the ancient OpenGL fixed function pipeline

Why do you have to and do you also use parts of the old immediate-mode API?

Archit3ch

7 hours ago

> OpenGL 1.1-style implementation on software

How many lines to implement OpenGL 2.0 (non ES) ?

Pannoniae

7 hours ago

An order of magnitude more ;) You need to implement user-programmable shaders, both ARB assembly and GLSL. That needs a GLSL parser, a shader interpreter (talking about compiling it to machine code would add another magnitude of complexity).

You also need to implement multitexturing (probably the easy part) but also all the texture combiner stuff too. This one is not hard but also a good chunk of code...

All in all, at least 40K if you ask me, but that's a very lowball estimate.

Of course if you don't care about implementing the full spec, you can get away with a lot less.

bsder

7 hours ago

Fabrice Bellard also wrote an OpenGL thing: https://bellard.org/TinyGL/

WanderPanda

14 minutes ago

Amazing:

(Mar 5 2022) TinyGL 0.4.1 is out (Changelog)

(Mar 17 2002) TinyGL 0.4 is out (Changelog)

"our plans are measured in centuries"

bigfishrunning

5 hours ago

What an aspirational figure, that guy does it all!

brcmthrowaway

7 hours ago

Does this support CUDA?

Pannoniae

7 hours ago

No, this is CPU rendering only! Not even SIMD, just straightforward integer (and float) code.

bee_rider

3 hours ago

It would be kind of neat to have OpenGL running on AVX-512, just for fun…

SJC_Hacker

5 hours ago

If its OpenGL why is it CPU only ?

bitwize

5 hours ago

OpenGL is an API. Software renderers for it—like the one that originally came with Windows NT, or even early versions of Mesa—have been out for a long time.

SJC_Hacker

5 hours ago

I haven't messed with it for a while, but last I checked it really wasn't that much code to make it run on the GPU. Maybe an extra 100 lines or so. Although you couldn't use windowed mode, had to be fullscreen.

apgwoz

2 hours ago

Haven’t messed with what?

This is an implementation of the OpenGL API interface. It is not OpenGL. It does not support GPU acceleration. It does math with floating point on the CPU. It then draws points and lines on a 2D surface provided by raylib.

Could this be adapted to use SIMD, or a GPU? Sure. That is not what this is today.

brcmthrowaway

7 hours ago

Now make it fixed point

avadodin

2 hours ago

Fixed point would be hell trying to keep track of the ranges. Maybe Posits or LNSs.

nnevatie

9 hours ago

*OpenGL-style.

Pannoniae

8 hours ago

Congrats for only reading the header ;) It's actually a pretty decent OpenGL 1.1 software implementation, obviously not complete and spec-correct though. It's more like those MiniGL drivers back in the day, implementing just enough of the spec so the game can run ;)

In a similar way, this implements just enough so Raylib's OpenGL backend can run! It was done so you can use the library without external graphics dependencies if you really want to.

furyofantares

7 hours ago

That's an extremely snarky reply given the post is just a direct link to the header.

Pannoniae

7 hours ago

No, the doc-header of the header! Apologies if I wasn't clear. I just thought the GP zoomed in on the word "-style" in the first line without reading more (it's probably since it's not a full 1.1 implementation, just something which can do enough to shim a good chunk of 1.1 functions so the RL GL1.1 backend can run)

furyofantares

7 hours ago

Still, if you post a link to a roughly 5k line raw source file, rather than like, some post about it, roughly nobody is gonna read much of the file before commenting.

edit: I stand corrected by the downmods!

mouse_

8 hours ago

This will be perfect for Nintendo 3DS!

JoeyJoJoJr

4 hours ago

Interesting. Does this mean it could be used for creating games for NES, SNES, Genesis, etc?