lubos's picture

2D Graphics Engine

Hello, so I'm slowly progressing with my OpenTK, OpenGL and whole C# adventure. I'm taking opportunity to start development diary so here I am :) I have started writing a small engine with OpenTK, that handles ONLY 2D rendering, but completely removes need to use any OpenGL function, while cooperating with other parts of OpenTK. I haven't decided for the name yet but that's not important I think.

The goal is to build a small, easy to use engine capable of building small 2D games together with OpenTK.

Engine doesn't use any scene-graph, you must draw each image every frame manually. I think this way it's cleaner and faster when working with 2D graphics. However, Gui uses a GuiManager which will draw all widgets at once.
To use engine, engine code is linked directly with game code. If you don't need some parts of engine you just don't link them.

The colors are passed as unsigned bytes (0-255).
The positions and sizes are passed as integers, meaning the x and y position of pixel on screen, where 0,0 is in the top left part of the screen.

Features implemented:
- Images loading/drawing (rotating, scaling, blending, drawing part of image)
- Animations(Sprite) (frames rendered from one texture, same options as image)
- Particle systems (uses single VBO, Point sprites)
- Custom VBOs

Features planned:
- Basic Gui(first widgets done)
- Complete documentation/examples(some examples done)
- Shaders

Free Image Hosting at www.ImageShack.usFree Image Hosting at www.ImageShack.usFree Image Hosting at www.ImageShack.usFree Image Hosting at www.ImageShack.usFree Image Hosting at

Mines.zip464.13 KB
PointSprites.zip467.25 KB
Game.zip476.52 KB
Engine.zip23.6 KB


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
objarni's picture

Lubos: try running dxdiag from Start->Run.. to see what drivers you have.

lubos's picture

Ah yes, there was drivers from year 2006 :) Now it runs perfectly.

the Fiddler's picture

Good to know :)

lubos's picture

Small update :)
I have started implementing point sprites based on this example I have found: . The old, classic particle system will still remain. I have created a base class which both particle systems inherit.
I also made some progress with GUI "module". There will be class "GuiManager" that will draw and update all widgets added to it.
And finally, I have started creating a small game to present engine in action.

lubos's picture

An update once again after a long time :) I have implemented simple buttons and labels. Added a screenshot. The button graphics can be any image, even animated.
What I wonder, is there a way to get a size of rendered string so I can center button text?

the Fiddler's picture

There is a method that measures strings. Try TextureFont.MeasureString or TextPrinter.MeasureString - I don't remember the name off-hand :)

lubos's picture

I coded a small game with engine today, a classic windows mines clone :) Added it to main post, the source of game is also included.
Let me know if you can run it fine please!

Inertia's picture

Runs flawless, nice work for a single day :)

the Fiddler's picture

There's some strange stuff going on on Linux - it looks like the screen isn't redrawn unless you resize it or move it. Looks like an OpenTK bug, but haven't found the time to investigate further.

lubos's picture

That's strange..I don't have linux anymoore after a small incident. The game is compiled against .Net Framework 3.5, could that be a problem? Also, I just updated to openTK 0.9.1 and drawing seems to be totally screwed up, seems like I'm doing something wrong there. Could there be a reason why graphical output changes between 0.9.0 and 0.9.1?