3D Graphics

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
JamesCFraser
Posts: 32
Joined: Wed Nov 14, 2007 9:47 pm UTC

3D Graphics

Postby JamesCFraser » Sun Mar 30, 2008 11:51 pm UTC

I have a three month period in which I won't be doing anything, so what I want to do is to write my own 3D graphics engine (and an operating system (very stripped down, of course!) for an old computer, but that's beside the point).

Fortunately, I have recently done well in a contest and gained a budget of eighty pounds for up to a maximum of two books.

So, my question to you is which two books would be my best guide to writing a real-time engine which utilises my graphics card? I'm fairly good at maths, so I don't require a text which will guide me through the maths slowly, but I am not familiar with how to program for the hardware, or where to start really. Also, I don't know the algorithms required to run quickly enough.

What would people recommend?

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: 3D Graphics

Postby Sc4Freak » Mon Mar 31, 2008 1:55 am UTC

You don't need to know the nitty gritty details of 3D algorithms - that's all abstracted away for you nowadays.

Today, we use APIs such as OpenGL and DirectX, which provide an interface to perform hardware-accelerated graphics processing. The first thing you need to do is choose your language and API.

For an absolute beginner, it's not recommended to start with C++. C++ is an advanced language, and if you're a novice to programming I'd recommend a language like C#. You can utilise DirectX with C# using either MDX (the official Managed DirectX library) or SlimDX.

If you're using C++, I'd still recommend DirectX. In my opinion, DirectX is a much cleaner and easier-to-use API. It's also got some of the best support around - it's backed my Microsoft and there's a butt ton of resources for it.

But really, it's your choice. If you go the DirectX/C++ route, I recommend the book "3D Game Programming With DirectX 9.0c: A Shader Approach" by Frank D. Luna. It provides an excellent introduction into the 3D graphics pipeline, and teaches the basics of DirectX. If you get adventurous, it also covers more advanced topics such as lighting and shader effects using HLSL.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: 3D Graphics

Postby EvanED » Mon Mar 31, 2008 2:09 am UTC

You don't need to know the nitty gritty details of 3D algorithms - that's all abstracted away for you nowadays.
There is still a ton of math, especially linear algebra.

Sc4Freak wrote:For an absolute beginner, it's not recommended to start with C++. C++ is an advanced language, and if you're a novice to programming I'd recommend a language like C#. You can utilise DirectX with C# using either MDX (the official Managed DirectX library) or SlimDX.
There is also XNA, which I know little about, but at seems like it can be described as a .Net wrapper for DirectX, and the examples I've seen have had used C#.

If you're using C++, I'd still recommend DirectX. In my opinion, DirectX is a much cleaner and easier-to-use API. It's also got some of the best support around - it's backed my Microsoft and there's a butt ton of resources for it.
OpenGL is definitely worth considering too. OpenGL 3.0 is going to be released Any Time Now (TM) and sounds like it makes substantial, backwards-incompatible changes. (The old API will still be provided, but new features will use the new APIs introduced in 3.0. So saying that it's backwards-incompatible isn't completely true.)

There are a "butt ton" of resources on it as well, though perhaps not as much as DirectX. My not-well-informed impression is that it's simpler than DirectX is. (While there are aspects of HLSL I like, I *definitely* think that GLSL is simpler than HLSL. These are OpenGL's and Direct3D's shader languages.) You get the benefit that programs that use OpenGL can be ported to other systems without any more trouble than any other program, while if you use DirectX, you will be doing a "butt ton" of work to do the port, or you have to hope that it works under Wine. So if portability to non-Windows platforms is important to you, OpenGL is probably the right route. OTOH, DirectX is better supported on Windows.

The OpenGL Programming Guide (current is 6th edition, covers OpenGL 2.1, the latest) is pretty well-written and seems to be the de-facto book on it.

There is also Java3D, but I don't really know much about it.

User avatar
Gatesunder
Posts: 120
Joined: Sat Feb 09, 2008 11:24 pm UTC
Location: KSU

Re: 3D Graphics

Postby Gatesunder » Mon Mar 31, 2008 3:18 am UTC

A book I have found quite helpful for OpenGL is the OpenGL SuperBible fourth edition: Comprehensive tutorial and referance by Richard S. Wright, Jr. - Benjamin Lipchak - and Nicholas Haemel. It starts you off with the basics and goes deep into everything you need to know later on.
I'm wrong 99% of the time, but some day that 1% will be better than the rest ...

DreemKiller
Posts: 2
Joined: Fri Feb 08, 2008 2:03 am UTC

Re: 3D Graphics

Postby DreemKiller » Mon Mar 31, 2008 3:20 am UTC

I don't think that's what he's asking: since he mentioned writing an OS, I think he means he wants to develop his own graphics system, from scratch. That's a herculean task that would probably take most programmers well over 3 months to do, but if he can get it done (or even well on it's way), more power to him.
For a fairly thorough description of the graphics algorithms you'll need, take a look at "Computer Graphics: Principles and Practice", by Foley, Van Dam, Feiner and Hughes. It's quite old (last updated in 1996), but the basic algorithms, such as rasterization, clipping, rotation, etc. haven't changed (although there may be better optimized algorithms now). It's got a couple of chapters on defunct graphics APIs that should be ignored. Despite it's age and it's flaws, most of the low-level graphics developers I know swear by the book. You can get it used on Amazon for a not terribly unreasonable price.
When it comes to learning how to interface with your graphics card (again, I presume you want to develop your own system), it depends on the vendor of your graphics card. Nvidia and ATI are fairly close-lipped about their specific hardware (register addresses, command format, etc). Intel is fairly open (they have open-source drivers available for Linux), but also notoriously __not good__. If you've got an Intel graphics adapter (not really a card since it's integrated in the chipset), you could get some cues about how to do things by looking at the open-source driver. As far as I am aware, Intel does not publish it's B-spec (programming specification).

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: 3D Graphics

Postby EvanED » Mon Mar 31, 2008 3:38 am UTC

DreemKiller wrote:I don't think that's what he's asking: since he mentioned writing an OS, I think he means he wants to develop his own graphics system, from scratch. That's a herculean task that would probably take most programmers well over 3 months to do, but if he can get it done (or even well on it's way), more power to him.

I interpreted it as the OS was a separate project, and he would want to write something like Ogre3D that would sit on top of the DirectX and/or OpenGL API and provide a higher-level interface.

For a fairly thorough description of the graphics algorithms you'll need, take a look at "Computer Graphics: Principles and Practice", by Foley, Van Dam, Feiner and Hughes. It's quite old (last updated in 1996), but the basic algorithms, such as rasterization, clipping, rotation, etc. haven't changed (although there may be better optimized algorithms now). It's got a couple of chapters on defunct graphics APIs that should be ignored.

Just be careful about what you pull out of there. For instance, 1996 is, I think, before you really had hardware z-buffers for instance, so you had to do layering by using the painter's algorithm or implement a software z-buffer. Nowadays you're almost always better served by not doing a whole lot of occlusion culling or back-to-front sorting and letting the z-buffer do almost everything. (Transparent objects are a little different.)

It was also long before programmable shaders arrived on the scene, and they make possible a whole host of other techniques. (Okay, many of which you could do with multiple render passes or multitextures.)

TraumaPony
Posts: 5
Joined: Tue Jan 15, 2008 9:44 am UTC
Location: QUT, Brisbane.
Contact:

Re: 3D Graphics

Postby TraumaPony » Mon Mar 31, 2008 7:18 am UTC

In my opinion, the bible on this is "Tricks of the 3D Game Programming Gurus", by Andre Lamothe. It's a 1700-page book, in which he starts from having the address of the video buffer, and builds a complete (~2001-era) software rendering engine. There is also a couple of chapters on non-3D stuff, like optimisation, physics, etc.

He goes through all of the theory, heaps of diagrams, and lots of code samples. If you want to learn everything about 3D rendering, read this book.

</fawning>

User avatar
JamesCFraser
Posts: 32
Joined: Wed Nov 14, 2007 9:47 pm UTC

Re: 3D Graphics

Postby JamesCFraser » Mon Mar 31, 2008 11:46 am UTC

DreemKiller wrote:I don't think that's what he's asking: since he mentioned writing an OS, I think he means he wants to develop his own graphics system, from scratch. That's a herculean task that would probably take most programmers well over 3 months to do, but if he can get it done (or even well on it's way), more power to him.


This is what I meant. Perhaps I should have made it more clear. Anyway, like the OS task, it will, obviously, have very stripped down functionality. The object of both exercises is to see how the concepts can come into practice (I have already read a couple of books on OSs, but don't know where to start with implementing one, for instance).

DreemKiller wrote:For a fairly thorough description of the graphics algorithms you'll need, take a look at "Computer Graphics: Principles and Practice", by Foley, Van Dam, Feiner and Hughes. It's quite old (last updated in 1996), but the basic algorithms, such as rasterization, clipping, rotation, etc. haven't changed (although there may be better optimized algorithms now). It's got a couple of chapters on defunct graphics APIs that should be ignored. Despite it's age and it's flaws, most of the low-level graphics developers I know swear by the book. You can get it used on Amazon for a not terribly unreasonable price.


This was one book I was considering. It made it to my top 3 based on reviews and descriptions of the content of the book. However, if you would recommend it over Fundamentals of Computer Graphics or Real-time Rendering, or would recommend it would be my best bet to get it as a third book, then I'll reconsider getting it.

DreemKiller wrote:When it comes to learning how to interface with your graphics card (again, I presume you want to develop your own system), it depends on the vendor of your graphics card. Nvidia and ATI are fairly close-lipped about their specific hardware (register addresses, command format, etc). Intel is fairly open (they have open-source drivers available for Linux), but also notoriously __not good__. If you've got an Intel graphics adapter (not really a card since it's integrated in the chipset), you could get some cues about how to do things by looking at the open-source driver. As far as I am aware, Intel does not publish it's B-spec (programming specification).


This is the bit I was most worried about. However, I may be coming into some money at some point (enough to buy a basic -ish machine), and am strongly considering purchasing a machine with well documented hardware. The graphics card on my current machine is an Nvidia GeForce 7600 GT. Realistically, I was never intending to develop for it.

Thanks for all of your advice, but using an API like DirectX or OpenGL would be somewhat pointless considering the purpose of writing this for me. I don't want to create any fancy demos, I just want to become very fluent with how 3D graphics operate at the lowest level to help me when I get to 3D graphics in university.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: 3D Graphics

Postby EvanED » Mon Mar 31, 2008 3:08 pm UTC

JamesCFraser wrote:This was one book I was considering. It made it to my top 3 based on reviews and descriptions of the content of the book. However, if you would recommend it over Fundamentals of Computer Graphics or Real-time Rendering, or would recommend it would be my best bet to get it as a third book, then I'll reconsider getting it.

RTR is a good book, but (1) it is probably not a good first book, (2) may be too high a level, and (3) has a 3rd edition that should be released fairly soon. (I think this year.)

User avatar
Gatesunder
Posts: 120
Joined: Sat Feb 09, 2008 11:24 pm UTC
Location: KSU

Re: 3D Graphics

Postby Gatesunder » Mon Mar 31, 2008 4:50 pm UTC

As far as the OS goes, the kernel is the first place you want to start. This takes care of distributing system resources and whatnot, making sure one process doesn't hog up the whole system. You might want to check out the source for the linux kernel. I never have so I have no clue what kind of effort it would take reading and understanding the code, but it's the only kernel I personally know about with open source code. Another good thing to check out would be the podcasts over at UC Berkley. They have a machine structures podcast and an OS podcast which I would think should help a good bit. What language are you going to write this in just out of curiosity?
I'm wrong 99% of the time, but some day that 1% will be better than the rest ...

User avatar
psykx
Posts: 408
Joined: Sat Feb 23, 2008 11:24 pm UTC
Location: England
Contact:

Re: 3D Graphics

Postby psykx » Mon Mar 31, 2008 11:03 pm UTC

The GNU people have been writing the HURD kernel for at least 10 years and AFSIK are nowhere near a release version. An OS is probably to much for three months unless you mean creating your own Linux distribution.
Berengal wrote:Only if they're killer robots. Legos are happy robots. Besides, even if they were killer robots it wouldn't stop me. You can't stop science and all that.

User avatar
taby
Posts: 154
Joined: Thu Nov 01, 2007 8:39 pm UTC
Location: Canada

Re: 3D Graphics

Postby taby » Mon Mar 31, 2008 11:33 pm UTC

If you want to start from scratch-ish, you should try your hand at writing a simple raytracer/rasterizer in GLSL (OpenGL) or HLSL (Direct3D). You still have to do all the camera-related projection work, etc. The only thing the API will really do for you is handle memory transfer from the CPU to GPU (and back again if you are doing GPGPU). That should take you from start to finish quite nicely. If you wish, you can also implement your own linear algebra routines (ex: matrix multiplication).

A good start would be Keenan Crane's quaternion Julia set raytracer.

User avatar
Amnesiasoft
Posts: 2573
Joined: Tue May 15, 2007 4:28 am UTC
Location: Colorado
Contact:

Re: 3D Graphics

Postby Amnesiasoft » Tue Apr 01, 2008 3:03 am UTC

psykx wrote:An OS is probably too much for three months unless you mean creating your own Linux distribution.

A simple operating system could easily be done in that time.

Oh, and mandatory GRAMMAR NAZIED!

User avatar
JamesCFraser
Posts: 32
Joined: Wed Nov 14, 2007 9:47 pm UTC

Re: 3D Graphics

Postby JamesCFraser » Fri Apr 11, 2008 6:59 pm UTC

EvanED wrote:
JamesCFraser wrote:This was one book I was considering. It made it to my top 3 based on reviews and descriptions of the content of the book. However, if you would recommend it over Fundamentals of Computer Graphics or Real-time Rendering, or would recommend it would be my best bet to get it as a third book, then I'll reconsider getting it.

RTR is a good book, but (1) it is probably not a good first book, (2) may be too high a level, and (3) has a 3rd edition that should be released fairly soon. (I think this year.)


I've been reading RTR, and this is my favourite of the books (I got all three, as the organisers of the competition I made were very generous as they want to encourage learning about real-time rendering). It was nice to pick up the book, read it for twenty minutes, and then be happy that I could write a reasonable software 3D engine :P

Having read some of it, I think writing a purely software 3D graphics engine may be a better task, and I've decided to combine it with the OS task (removing the OS element, but writing directly for my hardware).

Someone recommended that I write a raytracer to begin with, but that seems like a fruitless task, to me. I was interested in algorithms which can operate in real-time. I wrote a raytracer when I was 16 using parametric equations (I only recently learnt about vectors and matrices in maths). The task was pretty trivial, I had something that would render spheres within a very short time (perhaps three to five hours), and couldn't see the point in adding triangles as a new primitive as it would be time consuming but wouldn't really teach me anything.

Thanks for all of your advice. If I could get further advice to aid me in purchasing a computer with well documented hardware that would be very useful.

User avatar
laranzu
Posts: 104
Joined: Fri Nov 30, 2007 4:21 pm UTC
Location: Physical: Canberra, Australia
Contact:

Re: 3D Graphics

Postby laranzu » Mon Apr 14, 2008 10:16 am UTC

JamesCFraser wrote:Having read some of it, I think writing a purely software 3D graphics engine may be a better task, and I've decided to combine it with the OS task (removing the OS element, but writing directly for my hardware).

Someone recommended that I write a raytracer to begin with, but that seems like a fruitless task, to me. I was interested in algorithms which can operate in real-time.


If you want to write your own 3D graphics engine for IBM PC-AT and VGA style hardware, find a copy of the Graphics Programming Black Book by Michael Abrash. (Out of print, but available online.) It goes into truly awesome detail about 3D graphics, right down to x86 assembly code optimizations. The guy worked for id Software for a while and John Carmack thinks he's great.

If you want an interesting hardware challenge, find an old Silicon Graphics Indy Workstation with the 8 bit graphics board. SGI have released the complete technical details for the whole machine, including all the opcodes and data formats for their graphics chip. Then get yourself a copy of the Mesa OpenGL implementation and port it.

Thinking about it, grab a copy of Mesa OpenGL anyway, you'll probably find it interesting.

Hope this helps.

Parsifal
Posts: 113
Joined: Thu Feb 28, 2008 1:35 am UTC

Re: 3D Graphics

Postby Parsifal » Fri Apr 25, 2008 3:27 am UTC

I second the suggestion of Abrash's Graphics Programming Black Book. The technology it teaches, if I recall x86 assembly-assisted VESA rasterization, is dated, but the principles and discussions of optimization are timeless.


Return to “Coding”

Who is online

Users browsing this forum: Steeler [Crawler] and 6 guests