Tuesday, October 17, 2006


Direct3D tutorials

I'm beginning to the get the hang of C++ now, and have been messing about with 3D graphics. I had to do quite a bit of work with Direct3D for my PhD, but of course I did it all in C# and Managed Direct3D. Now I've started using 'proper' Direct3D and found an excellent series of tutorials here http://www.two-kings.de/.

Furthermore, the first tutorial actually gives a pretty good intro to Win32 programming, certainly the best that I've seen, so it's doubly worth checking out.

My plan in the next few months is write a little game that I can put up on my website, along with my PhD stuff, as an example of my work. I've noticed that many jobs in computer programming (especially in graphics, which is where I'm thinking of moving towards) require samples of your work to be submitted with any application, so it will be good to have some well-written software ready for such an eventuality.

My current plan for the game is a hovercraft racing game, which might include some weapons that you can pick up, WipeOut style, around the track. Okay it might not sound like your first choice of genre when perusing for a new game down the high street, but I'm doing it really to show off my madskillz, and realistic hovercraft and weapon physics would be a good way of doing this. First things first though, I have to get my terrain rendered and a proper camera moving around. I'll let you know how it goes.

Thursday, September 28, 2006


C# to C++ - learning C++ with wxWidgets

The invention of C# was a really clever move by Microsoft. It is similar enough in syntax to appeal to Java users, just as easy to use as VB, and only a fraction (5% IIRC) slower than C++. I started using it because I was taught Java, but wanted something that was faster and easy to use with regards to Windows programming, and C# is that. The bottom line is that for Windows programming, C# is by far and away the easiest language to use, unless you really need that extra 5%. This is borne out by the amount of C# software that is being written these days. Many companies don't advertise for MFC developers anymore, they want C# developers, and even ATI write their GUI for controlling their graphics drivers in .NET. And thanks to the efforts of the mono-project (which I've yet to try but apparently works quite well) C# programs can now be compiled and run on linux.

Yet there is no getting away from the fact that, sticking with our example of ATI, the graphics drivers themselves are almost certainly not written in C#. C# and .NET neatly hide away a lot of under-the-hood information about how software interacts with hardware, and how a program actually works. This is fine, but out in the wide-world I feel it's probably a good thing to get a broader view, and so I've finally taken the plunge and make the effort to start learning C++.

So, from my experiences in the last week or so, here are few bullet points with advce for those people who want to transfer their C# to C++:

Those are your first steps, in my recommendation. Over the next few weeks I'll be posting up little articles on my progress, as much to clarify my thoughts and learning experiences as anything else, but also hopefully to help anybody whose googling has found this blog!

Thursday, August 17, 2006


C# - Recording audio to a Wave file using DirectSound

In my work recently I used Microsoft's DirectShow API to create a video frame grabber from any Windows video input. in C++, DirectShow is a bit of a pain, but with the Managed wrapper classes from http://directshownet.sourceforge.net/, it's actually very pleasant to work with, and I've rather got the hang of it. So I was a little disappointed to find out it's not the best method of messing about with audio files - you can do it, if you find and install the WavDest filter, but naturally this hasn't been wrapped by the DirectShowNet chaps yet, and I couldn't be arsed to wrap it up myself. Anyway, it turns out that the recommended way of saving audio is to use another MS API, DirectSound.

All this meant that I was going to have to learn another API, doh, still I guess it keeps my brains working.

Anyway to get DirectSound you have to download the DirectX SDK, which fortunately contains a sample for capturing audio from any audio device recognised by Windows, to a file. Unfortunately, it's pretty complex
(grumble it was bloody simple in DirectShow grumble, if only I had the filter grumble). There some more info on what the sample is doing here, right at the bottom.

I'll be honest, I started going through the sample line by line and copying the relevant bits but, in the end, I realised I couldn't be arsed. So I ripped the GUI out, and with a bit of tweaking I was left with a fairly functional wave file recorder object. The only real thinking required is to hard-code which audio input device is required (just a matter of setting an int), and also code the details of DirectShow WaveFormat structure to 'default' wave information. This replaces the two 'intro' forms in the sample and lets you use the code as an object in your own program.

Why do I need to record wave files, I hear you cry? (tumbleweed...) Watch this space for information of my fully fledged chat bot - that actually lets you chat, rather than type!

Thursday, August 03, 2006


C# - Formatting text in a RichTextBox by parsing the Rich Text Format (RTF)

I've written a short article on this subject for The Code Project. Read it here!

Wednesday, July 26, 2006


C# - Redirecting output and input from a Process

So one of things I'm currently working on is running a separate, command line process from within my main C# program, interacting with it completely. There are loads of potential uses to this, but I'm using it effectively for reading and writing to a Linux CLI running on Cygwin, which means I can control a Linux program from a Windows Form.

It uses System.Diagnostics.Process, which is quite well represented in the MSDN library.

The key things to use, for a Process called myProcess are:

// first two hide myProcess' window
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
//Redirect input and output to parent program
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardInput = true;

Inputting data to the process is easy - to write to the input stream we just use myProcess.StandardInput.WriteLine() after calling myProcess.Start() - but grabbing the output is not so simple. If we wait for myProcess to terminate before we carry on running our main program, we can use
myProcess.StandardOutput.ReadToEnd()or similar. However, if we want to continuously read from the Output stream, we need to create a new thread for it, and that means using: mProcess.BeginOutputReadLine() instead - and to use this, we need to have defined:

myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);

myProcess_OutputDataReceived contains some code (such as Console.WriteLine(e.Data); that deals with the output data.

Writing to the console is thread safe, but writing to a Windows Form control (e.g. a RichTextBox) is not thread safe. The work-around for that is a little tricky but fortunately it's covered in detail

This page is powered by Blogger. Isn't yours?