Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: PixelWindow - a very simple framework for direct pixel rendering  (Read 4276 times)

0 Members and 1 Guest are viewing this topic.

Jallen

  • Newbie
  • *
  • Posts: 40
    • View Profile
I've recently started working on a raycaster, and I needed a way to draw direct pixel graphics to the screen. Given I've used and enjoyed using SFML before, it was the natural choice for me. I'm using the .net binding in C# via the nuget package. This isn't anything special compared to some of the awesome games and apps people have made on here, but in the off chance anyone wants to do some direct pixel work, feel free to fork my repo and use it however you like.

https://github.com/Jallenbah/pixelwindow

What it is: A simple framework for drawing realtime direct per-pixel graphics in C# for applications such as raycasters, raytracers, and retro games. This uses the .Net binding of SFML for rendering, which allows for easy use of its additional functionality such as image loading, audio, and input.

This framework allows you to render at magnified pixel sizes, for example, the following example program will create a window of size 1024x576, with pixels 8x screen pixel size, resulting in a 128x72 drawing area.

new PixelWindow(1024, 576, 8, "Big pixels", ...



When you create the window, you give an instance of a class overriding a simple interface (IPixelWindowAppManager.cs) with functions for the following -
  • An onload function which gives you the SFML window so you can use it for input etc.
  • An update function which runs every frame
  • An update function which runs once per fixed timestep increment
  • A render function which runs every frame and gives you access to set direct pixel data

A basic setup can be seen in Program.cs, which renders randomly coloured pixels at as high a framerate as it can up to the specified framerate limit. As seen in the window title (showing a total render time of 0.5ms), this is able to render at a couple of thousand frames per second, so the performance of the framework shouldn't hold back the performance of your rendering code on modern hardware.

Cheers
« Last Edit: August 22, 2022, 06:58:05 pm by Jallen »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: PixelWindow - a very simple framework for direct pixel rendering
« Reply #1 on: August 22, 2022, 03:16:43 am »
Looks neat! :)

Kind of wonder though, if the design of a single frame draw callback function is good enough for more complex things.
I feel like calling a function on the PixelWindow and passing in the pixel data, would feel more natural, but you'd then of course have to move the main loop outside of the PixelWindow.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jallen

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: PixelWindow - a very simple framework for direct pixel rendering
« Reply #2 on: August 22, 2022, 06:11:24 pm »
Looks neat! :)

Kind of wonder though, if the design of a single frame draw callback function is good enough for more complex things.

I feel like calling a function on the PixelWindow and passing in the pixel data, would feel more natural, but you'd then of course have to move the main loop outside of the PixelWindow.

Thanks, you're right - it doesn't give you the complete flexibility of controlling the loop, but through constraining the way you use it and forcing you to work within those 4 functions to control the application, it gives you a kind of "work with what you're given" simplicity, where you don't really (and can't, without modifying it) need to think about how the loop is structured or anything like that, which is why I went down this route. I guess it's somewhat inspired by the update functions you can override on Unity entities.

I think within the render function, you could go to town if you wanted to and fire off multiple threads, break it down into several other methods etc. and build up a pretty complex pipeline, especially if you created a class which had public methods of the types the constructor takes, you could do something like

var app = new Application();
var window = new PixelWindow.PixelWindow(1024, 576, 8, "Big pixels",
    app.OnLoad,
    app.Update,
    app.FixedUpdate,
    app.Render);
window.Run();
 

Actually I think I will make a commit to make doing that simpler, if I create an IPixelWindowAppManager interface which contains a contract for those 4 methods which people can then implement, I can also create an alternative constructor which takes an instance of that interface. That way you can just do

class MyPixelWindowAppManager : IPixelWindowAppManager {
    // implement onload, update, fixedupdate, and render from interface
}

var appManager = new MyPixelWindowAppManager();
var window = new PixelWindow.PixelWindow(1024, 576, 8, "Big pixels", appManager);
window.Run();
 

Thanks for the feedback 👍



EDIT - I've now made the changes to the way you set this up so you pass in an implementation of a provided interface instead of willy-nilly callbacks (see https://github.com/Jallenbah/pixelwindow/blob/master/src/App/Program.cs). Hopefully you think this is better rather than worse. I am more happy with it following these changes. Thanks again for your feedback eXpl0it3r
« Last Edit: August 22, 2022, 06:55:55 pm by Jallen »

Jallen

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: PixelWindow - a very simple framework for direct pixel rendering
« Reply #3 on: August 27, 2022, 05:50:18 pm »
Just implemented Conway's game of life with this https://github.com/Jallenbah/simple-game-of-life

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: PixelWindow - a very simple framework for direct pixel rendering
« Reply #4 on: August 27, 2022, 06:02:28 pm »
I think the new API is more intuitive to use and easier to capsule. :)

Also cool how little code you need for the Game of Life when you don't have to think about the rendering as much
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything