Monday, September 12, 2005

Learning GLSLang...

Well, today, I haven't really had much time to do graphics programming due to the immense load of homework I currently have to endure, but I learned how to implement a quick GLSL shader interface with my engine, so I hope to be doing some pretty interesting things as I learn more and more about shader programming, advanced lighting models (I'm mainly concerned with Phong shading, since that's a nice per-pixel approximation). I may even try a cel-shading fragment program.

It's nice now, knowing that my engine is going to have a far more flexible shader interface than Doom 3 (considering it supports only one interaction shader...) :-)

Ashraf Eassa

Saturday, September 10, 2005

Graphics Programming with OpenGL

Well, I've been spending the last few days really seriously learning the OpenGL API and learning some graphics theory, and I must say that this is truly the most interesting and enjoyable thing to do on the planet. I can't possibly imagine myself now doing anything other than programming, it's great!

So, I learned about setting up a Win32 window that can be used by OpenGL to display the output, and despite the relative tedious nature of this sort of work, I still found it quite interesting to learn how it works, and how to set it up with GL and how to make it modular.

After a while doing and learning that, I learned about the OpenGL primitive types and how to use them within an OpenGL program (I admit, from tinkering I'd already had a good idea of how they worked, but I still learned quite a bit). At this point I'd been easily able render triangles, lines, points(pixel), and polygons with an arbitrary number of verticies. I also learned how to assign colors to the polygons on a per-vertex level. With my knowledge of basic GL primitives, I also learned about how OpenGL handles culling, basically, even though polygons are infinitely thin, both sides are treated seperately in the case of culling, so, I can see how this could be used to selectively set attributes to either face of a polygon or act as a performance optimization by doing culling dynamically with geometry of higher complexity.

I'm extremely tired right now, so I'll halt my OpenGL learning (and my current research engine, where I am implementing what I learn, called the Vortex Engine) for today, but I can't wait to start learning about transformations, GL matricies, fog, lighting and texture mapping. I hope by the end of this month, I will be learning the OpenGL shading language, in order to do truly sophisticated rendering on a per-pixel level, through arbitrary surface programs. I'm excited at the possibility of implementing per-material, per-pixel specular and normal mapped lighting, all being performed completely by the GPU.

That's all for now, I definitely need some sleep...

Ashraf Eassa

Tuesday, July 26, 2005

Programming advice from John Carmack

I emailed John Carmack (technical director/co-owner of Id software) and asked him for some advice for a beginner programmer (read: me), and he gave a very thorough, thoughtful and helpful response, and I feel that other people should hear what he has to say.

So, without further ado, the email from JC;

When I started, computers couldn't do much more than simple arithmetic and if statements -- my first computer had 4k of memory. How I learned probably isn't very relevant, because there are so much better resources available today.

Don't expect it to be easy, you will have to work at it. Get a few more books from the library that cover beginning programming to go with the ones you have -- sometimes a different author explaining the same thing will help a concept click. Go through all of them at least twice. Try to do every problem and exercise, don't just read them and think you get it. Lots of people that want to program will talk a lot about programming, but not actually write that many programs. You should write hundreds of programs

If you want to get good at something you need to focus on it, which means choosing to exclude some other things from your life. Keep a little journal of what you are working on each day, you may find that you aren't applying yourself all that hard. Learn something new every single day.

Avoid "cookbook programming", where you copy and paste bits of code that you have found to make something work. Make sure you fully understand what everything it actually doing, and that you are comfortable applying the techniques in other situations.

It isn't a bad idea to start in an environment that give you more exciting feedback, like visual basic, flash, or javascript, but you should try and "find the excitement" in even the most simple data processing tasks. There are layers and layers of things going on in just compiling and running the simplest program that are worth investigating.

Pay attention in school to the math classes. It is more important to be able to do basic algebra and trigonometry extremely well than to sort of get by in higher math classes. You should be able to ace all the tests and teach other people if you truly have a complete understanding of the subjects.

John Carmack

Thursday, July 21, 2005

Welcome all to my new blog, I'm using this mainly as a way to output my thoughts about various topics, and to document success, frustration and topics of the like. If you'd like to reach me, you can email me at or catch me on AIM with the screenname of voodoochile920.

C++ Thoughts
When I first started learning programming three weeks ago, beginning with the standard "Hello World" program (basically, outputting a static string or 'string literal' to the screen using the cout function of the namespace of the standard library) I was quite discouraged, thinking that I would be stuck doing trivial programs for a long time. Yes, outputting "Hello World" to the screen doesn't seem like much, but what I failed to realize when I wrote the program, is that even the simplest programs have so many things worth investigating. For example, you might not think a "Guess my number" game would be terribly complex to do, seeing as how all games of any significance are 3D based or simulating a 3D world (hell, even the original Doom gave the illusion of 3D, while being 2.5D) , and it isn't. However, simple the code itself is, it's not really the important part of writing a game like that. The important part of the development is trying to get the program to run, work in all cases (requiring some time experimenting with error handling) and not take a significant amount of time to program, and also understand what is happening. Sure anybody can go google for the game, retype it in the IDE and compile it and say "gee look, I made a game", but what have you learned? Researching how to do it, understanding every line of code and being able to use the techniques learned in other situations is the important part .

Another thing I failed to realize was that all these trivial tasks and aspects of C++ were cumulative to bigger, more useful parts of C++ and then eventually you get to the real important stuff. I've learned that starting simple and moving upward from there, can be somewhat discouraging and also frustrating for some (I know how badly I wanted --- and to a degree still want to just open a D3D9 book and start learning), but C++ and programming in general take years and years to learn and become skilled in, and a lifetime to master. I'm quite glad that I have chosen to start doing C++ programming, because I'll be able to eventually go to graphics programming, or if not, I can go into other areas like AI, Sound, Physics, Networking, and even do general Win32 API programming. I know full well it'll take time, but I'm determined and patient enough to try to go one step at a time :-)

Okay, now for recent developments on what programming projects I've been working on. Lately I've just been spending time doing simple programs that test a specific new feature that I've learned to use, but I recently wrote a "Coke Machine" program which basically simulates a real-world coke machine. The first version was quite interesting to develop. My skill at the time were much more constricted than they are now (not implying my skills are even noteworthy at the present), but it was neat. I used the limited knowledge I had, with spaghetti coding practices (I'd not learned about functions, classes , objects etc.) and I had made a fully operational coke machine, that worked great and handled errors quite nicely. Unfortunately the code was extremely messy, and it wasn't easily modifyable. So after my friend Robert nagged me to go do a function-'ized' one, I went and did it, and it turned out great as now I have a great grasp on the concept of functions and passing parameters.

(Oh and if anyone wants the source code or executable then shoot me a mail and I'll send it to you!)

Something that's very interesting to note, I don't know if it's just me, but I tend to learn better, quicker and more effectively if I try applying concepts and tinkering around until they work, rather than spending an excessive amount of time just trying to follow what a book or video is showing. Don't be afraid to experiment, because from my (limited) experience, It's always best to fully understand the limitations of what you can do.

Finally, the most important thing is to have a guide, someone who is experienced and is willing to help you out when you don't understand something. Heh, if I didn't have anyone to talk to, I'd be progressing much slower, so I find it quite beneficial.


Lately, I've gotten the urge to just push my rigt to the max. Sure a P4 2.4 is quite good and provides plenty of processing power, but it's not really more performance I'm after, rather I'm looking to see how much I can get out of the hardware, and that, in itself is the most fun and rewarding part.

Interestingly, I have my P4 2.4 running at 2.8GHz quite reliably with a 944MHz bus. Now, one might think I used a 5:4 ratio divider in order to get my ram to run at 472MHz ( dual channel), but the amazing part is, that my ram is running 70MHz overclocked with a 1:1 memory/bus ratio! Also, I don't even have any ramsinks on the sticks either!

So I'm very happy indeed that I could squeeze a little more life from an aging PC. I don't suspect I'll have to upgrade for about a year, if not, more.

Ashraf Eassa