2d matrix of pixels to screen

I have a program (slime mold simulation) that generates a big 2d array of values. I want to draw this matrix to the screen as pixels in real time. I see a lot of solutions that can make a image from a 2d array, but those are not fast enough to get a reasonable fps at a HD resolution (1920x1080 for example).

At the moment I use Allegro 5, as that is the only visualization library that I know how to use (and the only one that I know of that is easily installed using Nuget). I often have a lot of problems getting c++ libraries to work because I always just use Nuget (all linking stuff is hard okay).

By drawing to a locked bitmap and skipping black pixels I can squeeze some performance out of that, but at a quarter of a million particles the draw time is from just as long as the (unoptimized) simulation time (63 ms) to 3 times as long, depending on the amount of black pixels.

At the moment I'm doing the preprocessing of the pixels (scaling, making pretty colors) by hand in in CUDA, which wasn't that hard because i'm doing the simulation using CUDA anyway.

Allegro has access to fragment shaders, but the documentation is difficult for me to understand as I don't know a lot of the stuff going on there. This means that if there is an easier option, I'd rather not mess with that.

I know there are a couple options for me out there, but before I go out of my way to learn a completely new library or something like that I would like to know the best library for this project, as I don't have that much free time to program.

Long story short, my question is: what is the quickest way to draw a 2D array to the screen in real time?

Example of output now (saved frames and stitched together for video): https://youtu.be/U1YVSvEcLZ4

Edit: My platform is Windows and I am programming in Visual Studio.
Last edited on
what OS?
modern graphics cards can draw 2d even high resolution at 60+ FPS with little trouble. Its likely able to draw faster than you can generate the pixels.
The answer is likely SFML, but lets get all the info first.
Last edited on
Hey jonnin, sorry about that, I added the information.
Last edited on
maybe take a look at the example here: http://www.rastertek.com/dx11tut11.html
take their example project and rewire it to just draw a RGB array that you provide as a function, then connect the two?

you can also try other libraries. directx is really meant for 3d, the 2d stuff is kind of left over from directdraw way back when, but its in there.
typically 2d just has 2 buffers. you draw one while the other is being updated, the reverse and draw the new one and fill in the old one, back and forth.

If this isnt a good example see if you can find a better one for 2d. It looks a little over-cooked, but typical with this kind of question, a simple 'me draw pixels' example is tough to run down, everyone wants to add a bunch of crap you don't need on top of that making it tough to get started with the basics.

dx12 is out but 11 has more examples. may not want to go bleeding edge? The older stuff may work fine in 12, or not. They tend to screw stuff up on major version updates.
Last edited on
Registered users can post here. Sign in or register to post.