Skip to content

About

A very simple C# pixel rendering library

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fergo Pixel Engine

This is a very basic implementation of a 32-bit pixel rendering platform in C#. It currently supports basic functions like DrawPixel, DrawLine, DrawRectangle, and DrawCircle. I tried to make its usage as simple as possible, as described below.

The engine is not supposed to be fast. My main intention with it is to mimic olcConsoleGameEngine from javidx9, but using a Windows Form instead of the console for output. I also want to keep it independent of external rendering libraries such as OpenGL and DirectX, so I'm sticking to the regular .NET drawing classes.

Usage

  1. Add FergoPixelEngine.cs to your project.
  2. Create a class derived from FergoPixelEngine and override the Update() method. All game logic and rendering should be done inside this method, which is called every frame in the game loop.
class MyEngine : FergoPixelEngine {
	protected override void Update() {
		Clear(0xff000000);

		DrawRectangle(100, 100, 10, 10, 0xffff0000);
		DrawCircle(150, 150, 25, 0xffff00ff);
		DrawLine(150, 10, 100, 50, 0xffffff00);
	}
}
  1. Create an instance of your new class, set the window parameters, and call the Run() method. Currently, this should be done inside a form, as the class expects a Windows Form as the render target. The main loop runs in a separate thread, so it won't lock the window UI.
private void frmMain_Load(object sender, EventArgs e) {
	MyEngine my = new MyEngine();

	my.Create(this, 320, 240, 2);
	my.Run();
}

Documentation

Create(Form RenderTarget, int Width, int Height, int PixelSize)

This method is responsible for setting the rendering target, screen dimensions, and pixel size.

Currently, the engine only supports a Windows Form as its rendering target. The pixel size is used to emulate larger pixels on the screen for a more old-school look, if desired. At the moment, I'm using some DPI tricks to get this done, but I plan on improving the drawing routines to get better performance, and this will probably change in the future.

Run()

This simply starts the main game loop. It runs in a separate thread.

Update()

This is an abstract method that must be overridden by the derived class. This method is called by the engine every frame, so this is where you are supposed to add all the game logic and rendering routines.

Drawing methods

Clear(uint Color)

Clears the screen with the specified color. Color must be a 32-bit integer in ARGB format.

DrawPixel(int x, int y, uint Color)

Plots a single pixel on the screen at coordinates (x, y) with the specified color. The (0, 0) coordinate is the top-left corner of the window.

DrawLine(int X0, int Y0, int X1, int Y1, uint Color)

Draws a line from (x0, y0) to (x1, y1) using Bresenham's line algorithm.

DrawRectangle(int TopLeftX, int TopLeftY, int BotRightX, int BotRightY, uint Color)

Draws a rectangle outline from a top-left to a bottom-right coordinate.

DrawCircle(int X0, int Y0, int Radius, uint Color)

Draws a circle outline using the midpoint circle algorithm.

FillRectangle(int TopLeftX, int TopLeftY, int BotRightX, int BotRightY, uint Color)

Fills a rectangle with the specified color.

About

A very simple C# pixel rendering library

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages