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.
the Fiddler's picture

Nice! Did performance improve?

lubos's picture

Hm I didn't notice any performance gain. The thing is that all particles are still moving so I must rebuild VBO every time on update, is this correct?

the Fiddler's picture

Of course, as long as the CPU has to update all these particles, it will be the bottleneck. I wondered if there was any thing to be gained anyway (maybe the driver would be better able to optimize the data before sending it?), but it looks not :)

lubos's picture

I tried to run engine on other pc but the window just blinked for the second and then exited without any error message, do you have any idea why it crashes on other pc? It works here normal both in debug and release mode, I use VC# 2008 express

the Fiddler's picture

Ok, required info for the failing platform:

  1. Operating system and .Net version.
  2. Video card and version of the drivers.
  3. OpenTK version (0.9.0?)

Suggestions: invoke your program through the commandline. See if any exception is reported there.

It will also be very helpful to compile a debug version of OpenTK and run Examples.exe on that PC. Examples.exe generate a debug.log which will help pinpoint the problem.

To compile OpenTK, open a commandline window and head to opentk-0.9.0/Build. Then type:

build vs

Press finish to convert the project to VC# 2008 and press F6 to build. Zip up the bin/Debug/Exaples/ folder and try it on the problematic PC.

lubos's picture

1. Windows Vista, comes with .Net 3.0 I think
2. Same as here, nVidia GeForce7600gt,
3. 0.9.0

no messages from command line

When I run OpenTK examples they run fine, but when I run "First shader" example, it reports that I need atleast OpenGL 2.0, so it seems like opentk doesnt use hardware acceleration or what?

the Fiddler's picture

What does GL.GetString with the Vendor, Renderer and Version tokens return?

Mincus's picture

If I'm reading the nvidia driver version correctly there, you're running a pretty old driver.
Try updating that?

lubos's picture

renderer: GDI Generic
vendor: Microsoft Corporation
version: 1.1.0

the Fiddler's picture

Definitely software accelerated then. The string should read "Nvidia Corporation blah blah blah".

First step is to update the drivers for the video card - I'd give a 90% chance that this will fix the problem.

Second step is to set the monitor at 32bit color.

Is he able to run other *opengl* applications?