Advertisement

How to make a simple software sprite renderer?

Started by July 21, 2019 05:04 PM
3 comments, last by babaliaris 5 years, 4 months ago

Hello!

I know how to make renderers using hardware acceleration using OpenGL.

Right now I'm creating a super-light 2D game engine in order even really old computers will be able to run it. I want to create my engine automatically detect if a computer supports hardware acceleration and use the appropriate renderer, if not it will use a software renderer.

I already have the hardware acceleration renderer and already know how to detect and choose which renderer to use, the problem is that I don't know how to draw graphics without using OpenGL. Probably is hard to create your own API that will implement a virtual graphics card and use it to draw graphics. Is there any software that does only that? Not things like SDL, I want something that only lets you do some basics graphics drawing without the need for hardware acceleration.

The renderer needs to be able to draw rectangles with textures and nothing more.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

As you don't want to use SDL or so for some strange reason (that is, why do you use OpenGL then?), you'll basically have to rebuild something like SDL from scratch. I would say there is nothing wrong with having a look at it, to see what it all contains and how they do things.

Eventually, you just write pixel data in video memory (that part of memory which is sent to the video card and displayed at the screen), literally an RGB triplet for a single pixel, where not always you had 24 bits of space for a pixel.  If you're really lucky, you have only 256 indexed colours, which means there is one array of 256 entries with RGB values, and video memory uses 1 byte (the index in that array) for a pixel.

For more details: https://en.wikipedia.org/wiki/Framebuffer

 

If your source image is equally large as the number of pixels in video memory where it should be put (and the order of bytes match as well), painting an image on the screen are just plain copy calls (usually with a stride to skip the parts of the screen that you don't want to colour). Otherwise, you have to resize the image, and/or write the data in non-sequential order.

 

Advertisement

Thanks a lot. It was a problem for me too.

Thanks.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

This topic is closed to new replies.

Advertisement