Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing pixels to screen, cross-platform

In short: all I want is to display pixel data on screen in the most fundamental way possible, without losing cross-platform compatibility.

I know similar questions have been asked before, but they didn't seem to go in the direction I'm looking.

Basically, I'm making my own little game library, which I intend to use for my own 2D pixel-art games. All pixel-handling I take care of by myself, and now I've been looking around for the absolute minimal solution to getting up a window, listening to its events (mouse, keyboard, window-events) and drawing my pixels to it. A bonus would be if the library could handle threads and/or audio.

I don't need any OpenGL support at this stage, and I'm not sure I ever will. I don't really need any features apart from those mentioned at all. Should I start digging in the Windows, X11 and OSX APIs by myself, or is there a truly minimalist framework out there somewhere? Is making my own platform independent minimalist framework actually hard work? If it's not a that big of a deal I might just look into that solution out of sheer curiosity.

If you have any insight on making my own vs. finding something useful, I'm all ears.

Thanks!

EDIT: In short...

like image 486
Emanuel Avatar asked Feb 22 '23 07:02

Emanuel


1 Answers

The most complete, yet simple library is SDL. It is cross platform across Windows, Mac, Linux and more. With it you can:

  • create your game window (or make your game full screen)
  • handle keyboard and mouse events
  • access individual pixels (add SDL_Draw for functions to draw pixels, lines, circles, etc.)
  • sound effect playback
  • background music playback
  • threading functions
  • OpenGL support, should you realize that you need it.

Note that your idea of handling the drawing your own way by addressing individual pixels may not give you good performance unless your game is very simple. I would keep the door open to OpenGL and the wonderful world of hardware acceleration.

like image 103
Miguel Avatar answered Mar 08 '23 10:03

Miguel