Sunday, November 29, 2009

Busy little bee

So sorry I haven't been updating! In between keeping up with school work and projects and Red Orchestra I just haven't had even thought about updating! My bad.

Basically I've just been catching up in schoolwork, lazing around for my little Thanksgiving break (way needed it!), and coding on my lil SFML thingy. I am not sure what it's going to be yet, possibly just a template codebase. I got an undo/redo system in and working for the most part - but wanna fine tune it and improve controls for the editor - otherwise the basics are almost all done! I tried implementing CEGUI, which I have done before, but I am thinking in one of the newer versions they changed a fundamental usage of it so I ran into some dumb issues when trying to integrate it with SFML - will have to return to that later..

There needs to be more US-based Red Orchestra servers, and more people need to play on them. I do fine with my pings as it is, but always playing with French/German/Russians get old - wish I was at least picking up on their languages better than I seem to be.. If you play let me know, it's such a fun game! Especially when there are lots of people in the server, it really gives a sensation unique to those sectors of World War II.

Wednesday, November 18, 2009


Sorry for not posting in so long. Went through a super heavy week, then schoolwork catchup, then reading. Anyway, I have returned to SFML and been doodling a little bit in various small projects I'm piecing together. I decided I should kill two birds with one stone and clear out more of my fixfox tabs (down to 71!) AND make a tech demo/proof of concept for myself on splines.

A while back I was reading up on them heavily, I didn't want to use a formula I didn't truly understand. I got them down great, and realized how awesome of an exercise they actually were in matrix maths!

That aside, I never actually DID anything with them. So I just whipped this up in about an hour and a half. It mainly took so long because I was trying different things with SFML's Shape system. I think in the end it came out pretty nice though! It currently supports Hermite, Cubic bezier, and Catmull-Rom splines. I would like to make it more interactive, so that one can simply drag the points around rather than just generating a new one and sliding about it. Probably should eat some supper now though, mmmmm. Beef stew to the rescue!

Tuesday, November 3, 2009


Spent a large portion of my afternoon today reading over OpenMP and then BSGP, which stands for Bulk-Synchronous GPU Programming. Essentially it is attempting to do something similar to what OpenMP attempts to do for concurrency to the GPU arena. By this, I mean it is for general purpose programming on GPUs, and it attempts to also be quasi-cross-compatible across different manufacturer's cards. As it is CUDA et al. is fine, but they are all limited to their respective manufacturer's cards only. BSGP takes a similar-to-C-syntax blurb as a kernel function for a large number of stream based processors to run in parallel (way more than just 2 or 4 cores - but they are only good at certain things as compared to a CPU).

Pretty interesting stuff, I hope to apply OpenMP to my projects in the future especially! Beware jumping straight into it though - I think the guide that I have linked to does a fairly good job of catching you up on it but ANY multi-threaded programming will benefit from a thorough understanding of the intricacies and difficulties-by-nature of concurrency/parallelization.

Monday, November 2, 2009

Fast PictureBox/Graphics Context Drawing (Manual Backbuffering) in C#

While I was working on my Lissajous Curves application, I ran into the issue of re-draw. I was using Visual Studio 2008, .NET 3.5, and everything was going fine except for the refresh rate on the picturebox. It was rather unacceptable. Keep in mind that my very first step had already been to check the Backbuffered property on the Form to true. One would think that it would show similar gains as any traditional backbuffering implementation would, but on the contrary I found no real benefit to the flag. It ended up that manually backbuffering was faster, so I present my implementation.

There are probably other ways to go about this, but this is the fastest I have come across so far. It's rather simple and is just the backbuffering process word for word basically. Instead of drawing straight to our target, we will have two targets, and one we show while we draw on the other. When we finish drawing, we switch out the targets and begin drawing on the one they WERE seeing, and repeat.

If you are doing any serious kind of computer graphics work then you should probably already be familiar with this concept, so I will stop elaborating on it. On to the important bits!

First, I presume you use CreateGraphics(), probably on the component you wish to issue draw commands to. You then use your received context's DrawEllipse() or what have you to draw on it.

All we do differently now, is we are going hold two graphical contexts and one bitmap.

In your declaration, or in the function, or whatever you are currently using, you probably have something as described above, like:
Graphics pictureboxContext;

We will be replacing this, as described above, with:
Bitmap backbuffer;
Graphics backbufferContext;
Graphics pictureboxContext;

Now, in your form's _Load() function, where you should have something along the lines of:
pictureboxContext = picturebox1.CreateGraphics();

We will now add to this and expand it to: (note pictureboxContext remains, so of course match the names to fit - just incase you're not paying attention ;P)
backbuffer = new Bitmap(pictureBox1.Width, pictureBox1.Height);
backbufferContext = Graphics.FromImage(backbuffer);
pictureboxContext = pictureBox1.CreateGraphics();

Now, instead of drawing to our picturebox's Context, we will be drawing to the backbuffer's. When we are finished drawing onto the backbufferContext ( e.g. backbufferContext.DrawEllipse(...) ) and want to display our new buffer, we will need to blit it out to the picturebox's context. We can easily do this using the Graphic's class's DrawImage function:
pictureboxContext.DrawImage(backbuffer, 0, 0);

There is nothing special about this, and I honestly feel that this is what the Backbuffered flag should have been doing behind the scenes all along, but oh well. I found this useful enough of a discovery to back-propogate it to my internship's C# terrain editor's display. So I hope someone else out there finds it useful :o)