Thursday, March 22, 2007

Well not much happened today. I was able to implement a triangle filling routine and read a bit on .NET remoting. I thought about how to implement a Z-Buffer for my small system and thought about homogenous clipping as well.

The problems I have right now are:
  1. I want to implement basic triangle 2D screen-space clipping. Which itself is not a big deal but I do not want to implement a polygon filling scan-line algorithm. A polygon may be the outcome of a triangle clipped against a rectangular clip window. So what is there to do ? Either clip a triangle which produces a polygon and implement a "simple" scanline algorithm to fill that polygon. The other option is of course to split the triangle into a series of triangles. Either way has its intricacies.
  2. As mentioned in yesterday's I want to implement homogenous clipping for triangles. Which makes things even more complicated then a simple 2D clipper. The reason is that not only a triangle can be split into a series of triangles during the clipping process but also extra state is necessary. Remember, we do not only clip the triangle and generate new triangles that form the clipped triangle but we have to generate appropriate values for associated color, texture and normal data.
  3. I want the filling of the z-buffer and the filling of the framebuffer to be separate. Although expensive, I want to maintain this separation for flexibility.
With these "basic" things I should be busy for some days :D ...

For all the people who want to do some graphics stuff I recommend the following books. At least they served my understanding quite well.
  1. Practical Linear Algebra: A Geometry Toolbox
  2. Computer Graphics: Principles and Practise
  3. Real-time Rendering
  4. Math for 3D Game Programming & Computer Graphics
a web reference on the topic
  1. 3D Graphic Engine Essentials
  2. Software Rendering School
Happy reading

Wednesday, March 21, 2007

In reference to yesterday's post I continued a bit and implemented the following
  1. Line drawing via DDA and Bresenham
  2. Basic Cohen-Southerland Clipping in 2D
These routines may not be the fastet but this actually not the point since the code is written in managed C# and makes no use of any optimizations. It's sole purpose is learning. The next things that need to be done are
  • drawing of triangles (including basic fill)
  • a Z-Buffer (at least I have already set up the basics)
  • clipping in homogenous clip space
  • simple scene-graph
If anyone is interested in some sources - I can either post them here or put them online on my website. I also thought about making the whole engine a bit more flexible. So I thought I could
divide all the pipeline elements into pipeline stages. Each stage has access to some renderstate and does only execute on some defined input. As a consequence one would get something similar to vertex and fragment programs and a non-fixed function pipeline. But of course this is only some thinking and I should better get things set up before reasoning about making it most flexible.

Tuesday, March 20, 2007

I have been quite busy these days writing my own small 3d engine. I did some small stuff with OpenGL in the past and to understand at least a bit better what is going on behind the scenes, I decided to do my own small renderer. I know, why write another software renderer if there is so much available. But at least for me I can say, that what I implement I do understand a little better.

Of course, it takes some time to get the basics running. Until know it does only little (only perspective projection is covered), such as the transformation from an object's local space to actual screen space. But many things are left to do such as homogenous clipping, 2D clipping, painting ...

The things I want to implement as a next step are
  • rasterization (lines via bresenham, basic filling - flat shading)
  • homogenous clipping
  • 2d clipping
  • a primitive scene graph
Since basic rasterization often produces flicker, I looked for a basic method to do double-buffering with windows forms and .NET and these are some of my findings:

  1. Enable double buffering for a control (e.g., Form) via setting a control's property DoubleBuffered = true
  2. Set a control's style via calling Control.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
This gives you basic double-buffering in an instant. But sometimes one wants to have a bit more control over the actual double-buffering process and therefore, the .NET framework provides several new classes in the System.Drawing namespace, such as:
  • BufferedGraphics
  • BufferedGraphicsContext
  • BufferedGraphicsManager
You can obtain an AppDomain's main BufferedGraphicsContext by using the Current property of the BufferedGraphicsManager or you may create your own BufferedGraphicsContext. A BufferedGraphicsContext can be used to create a BufferedGraphics object (the Off-screen buffer you want to use for drawing) and associate this object to an output device (e.g. display).
Use a BufferedGraphicsContext.Allocate method to create a BufferedGraphics object and to render the contents of such a BufferedGraphics object to an output device use the BufferedGraphics.Render method, which allows you to set the desired output device or use the one supplied to the BufferedGraphics.Allocate method. Drawing to such an off-screen buffer is easily done via a BufferedGraphics.Graphics property.

Of course, if this is not what you want you may still use a Bitmap object to do all off-screen drawing and draw that bitmap to the display.

Sunday, March 11, 2007

Back again :D

A long time ago ... in this galaxy :D ...

Well, it has been a while since I wrote the last post. But since I was finally able to conclude my studies this thursday, the 8th of march, I hope to be around more often. I will probably start my first work on april the 2nd. My new employer will be Avanade Deutschland GmbH (german office of Avanade Inc.). And I am quite happy about that since I expect a great learning experience - well but let's see ...

Since I am not too busy these days I will try to have a look onto several things such as SQL Server 2005 and maybe I get my hands dirty with Phoenix again.

Best regards

Christian