OneLoneCoder / olcPixelGameEngine

The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects
Other
3.83k stars 915 forks source link

Support request: how can i port this library to embedded systems? #376

Open XanCraft21 opened 2 months ago

XanCraft21 commented 2 months ago

Hello, i was wondering if it would be possible to port this library to embedded systems like microcontrollers, with software like Arduino. I am aware that most microcontrollers will NOT be able to run this, but i would like to try it anyway on a more powerful microcontroller.

I know that such devices have no operating system, but i can provide my own display so long as i have access to the frame buffer.

The reason why I am posting this is because i am having trouble finding or making a 3D renderer for these small devices. I found one that i managed to get working, but the project seems abandoned and i cannot get much help with using the renderer to its fullest potential.

This idea may be impossible and a waste of time, but i feel like trying something new at a smaller scale just for fun.

If anyone can help me achieve my goal i will gladly appreciate it. Thank you for your help and for taking the time to read this.

Moros1138 commented 2 months ago

i was wondering if it would be possible to port this library to embedded systems like microcontrollers

the short answer, yes... but...

PGE uses the C++ STL extensively and whatever development platform you use would need to support them as well, this might be a show stopper in and of itself.

Beyond that, it would require implementations being written for the platform (arduino in your case) and the renderer (in your example the frame buffer to your display). I don't wanna say it would be easy to do, but it should be possible.

XanCraft21 commented 2 months ago

Thank you. If possible could you give me an example of how i can modify the code to work for my platform? I’m not the best at porting libraries.

a few questions: How would i swap out STL for my preferred graphics library, since i cannot find an STL port for Arduino? What parts should be changed or removed (keyboard and mouse controls, window applications, ect.)?

I hope i’m not asking for too much, sorry if i sound like i am.

Moros1138 commented 2 months ago

How would i swap out STL for my preferred graphics library, since i cannot find an STL port for Arduino?

STL isn't a graphics library it's the C++ Standard Template Library ... PGE is written in C++ using C++ STL features, so if your platform doesn't support them, then porting PGE to your arduino is gonna involve rewriting the whole thing from scratch.

Given you have to write it from scratch you get to choose what parts makes sense for your port and which parts don't.

I'm not an expert in writing arduino code so I can't be more help to you.

XanCraft21 commented 2 months ago

If STL is basically the c++ Standard library or stdlib then my platform supports that on most higher end devices.

I can make my own input replacement for keyboard and mouse, i’m just not sure how the library will handle platforms without system specific features. Will i get tons of errors first try or will i be mostly set to go?

Moros1138 commented 2 months ago

I can say, with certainty, that if you try to use PGE on an embedded system that lacks any of a number of features it relies on then you will indeed be presented with loads and loads of errors.

You are wanting to use PGE on a platform it hasn't been ported to which means you're gonna have to implement the bits that will make it work on your platform.

PGE is abstracted such that you can implement your own Platform

https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/olcPixelGameEngine.h#L959

For example, this is how Windows Platform has been implemented https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/olcPixelGameEngine.h#L5639

and your own Renderer

https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/olcPixelGameEngine.h#L937

For example, this is how OpenGL 1.1 Renderer has been implemented https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/olcPixelGameEngine.h#L937

once you've implemented your Platform and Renderer, you tie them into PGE, in this section https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/olcPixelGameEngine.h#L5639

XanCraft21 commented 2 months ago

Thank you. I had trouble finding those.

Another question i have, how do i make this work without using OpenGL? I have a software only port i’m trying to implement, but i might need to figure out something else.

Moros1138 commented 2 months ago

No problem. I don't have a good answer to this. I've never ported it to a platform that didn't have opengl, so i never had to consider any other means of rendering. i would start by looking at the way the renderer is abstracted and figure out how those parts work with a software renderer.

XanCraft21 commented 2 months ago

Ok. Hmm, this might be very hard to figure out. Thank you for the help. I might need to come back to this later.