lubos's picture

2D Graphics Engine

Overview
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

Screenshots:
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 www.ImageShack.us

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

Comments

Comment viewing options

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

How do you draw your particles? Blending? What graphics primitive is it? It looks quite nice :)

flopoloco's picture

Hi there and welcome, cool project you're working on :). There seem to exist lots of particles, are you getting decent FPS?

lubos's picture

@objarni: The particle system just stores reference to image and draws him for each partcile, no magic :) The image used for particle is from NeHe, just scaled down and blended directly with engine. Thx for comment ;)

@flopoloco: Thx, I didn't make any optimizations, the second one with 10k particles gets just around 13fps on my GeForce 7600 and dual core cpu. It seems that CPU is fully eated, I will look around if its possible to split it to two cores.

lubos's picture

I'm still improving engine, altought school takes much of my free time. I have posted two new screenies to the main post. I'm planning to release some kind of demo so if somebody could be that nice and test it so I know how it works on other PCs :) I will post the demo soon.

objarni's picture

Are you doing additive blending with saturation or multiplicative? That is, is your equation something like

final red = texture red * texture alpha * fragment red

or

final red = min (1, texture red * texture alpha + fragment red)

... if you know what I mean..?

lubos's picture

all I do so far is enabling gl blending with specified color

lubos's picture

Main post updated. Particles can be animated now!

Inertia's picture

nice project and progress, keep it up :)

How are you drawing the sprites? GL.DrawArrays and quads?

Regarding dual core CPUs, Fiddler mentioned the bold idea to use double buffering to avoid excessive locking and problems with thread safety. Basically you'd use 2 arrays of particles and anticipate the next frame in the backbuffer, while the frontbuffer is drawn, then flip pointers to the arrays. Hope this helps :)

hshutao's picture

nice project.how to get your sourcecode.

lubos's picture

-Inertia
Yes, drawing is done with vertex arrays using GL.DrawArrays, but its not any efficient currently since every image holds its own vertex array. Should I create one big array which will store all vertices? Or maybe one for particles, one for images etc

-hshutao
Thanks. I'm sorry but source is not yet avalaible. I don't think you would be any productive with it currently, still a lot of work needs to be done :)