sunnuntai 2. elokuuta 2015

Wonder how that was done...


Like so many in my generation I was drawn to programming by games. No surprise there, really, since this was back at the dawn of home computers when Commodore 64, Sinclair Spectrum, MSX and others ruled the market (and later Amiga and Atari ST, and even later PCs). Despite being so simple these simple computers could produce wonderful graphics and sound (well, most of them at least...), so no wonder that many curious minds were drawn to them. They were all so simple to start with since they all came with some kind of Basic interpreter, yet so difficult to master since that would require delving into depths of assembly and mysteries of their respective chipsets.

But the games... While I had some attempts earlier, I think first game I really wanted to imitate was Ultima V (PC version) that I borrowed from a friend (and then immediately had to crack myself since I had to return the original disks quite soon - another introduction there...). At this point I already had only very rudimentary undertanding of basic of programming (with GW-Basic) and of the mysteries of graphics hardware but I tried. Somehow I still managed to get rid of the disk-based copy protection and finish the game, yet I didn't get very far making a copy of the game itself.

Attempts in creating something like Ultima still were my first real steps into world of programming, despite eventual failure. It didn't take long to grow out of basic and move on to Turbo Pascal (I did eventually release some simple games made with it too). And then later C/C++.

At some point (during Pascal years) I saw Second Reality. Back then I didn't have sufficient knowledge to understand how effects were made, but that didn't stop me from trying (and failing miserably of course, but that's how you learn --  "Damn, another way how you don't  do that...")

I really started learning C++ when I took my first real programming job, after first year in university. As so often happens, being full-time programmer tends to make hobby programming less fun so all side projects (including games) were kinda pushed aside for time being. And there they were for a long time. Never completely forgotten, though, I always had ideas. Like playing World of Warcraft made me wonder how to build server infrastructure for such a game (client? bah, not that interesting (to me), really). I have long documents on ideas and infrastructure needed. All unproven of course, without client there really is no point (and of course more important than the client would be interesting world to see via said client! Not that I don't have ideas, it's the creation of that world that is the problem -- lore, places, people and so on... Enormous amount of work.)

Not that I had to abandon all game-related ideas I had. Many of those ideas were built as minor parts of some work project or other (like some simple spheres that rotate and fade away while doing firmware upgrade on one product - one colleague told me that they had some fun watching it the first time, guessing how much work I put into them. I didn't have heart to tell them that it took maybe 30 minutes total, and it was mostly kind of side effect when first experimenting with the display module used on that product), but games they weren't.

But 3D, that has been an interest of mine for along time. Before entering workforce I did some experimental projects with DirectX 7 (that ought to tell you how old these projects were) and OpenGL (1.1 or so). Only now I have picked up enough interest again, and since I have -- shall we say -- philosophical objection on unportability of DirectX the OpenGL was quite natual choice.

At this point OpenGL was already on version 4 and I had absolutely no idea how the current graphics hardware worked -- all I knew was old fixed-function pipeline. I was used to throwing glBegins, glTriangles and all those around so I wasn't willing to let go of them -- mostly because I had so much already built on those, so I jumped on to OpenGL 2 that allowed some kind of hybrid approach - both data buffers drawn by hardware and old fixed function pipeline drawing on same frame buffer.

I admit now that this was a mistake that cost me a lot of wasted time, I should've jumped straight to modern OpenGL (3.3+), but ... well, you know how it is. You have something ready and aren't willing to give up and rewrite everything that easily.

It didn't take me long to run into a wall that way - I wanted to do something that the API just couldn't do, not with GL2. So after some more research I found out that OpenGL 3 supports what I need. Great. Except none of the old, so familiar, so easy fixed-function pipeline stuff would no longer work at all. Less great, as much of my editors were build on ability to control everything triangle by triangle and line by line; you know, hide something, highlight something and so on. 

So what can I do but bite the bullet. Rewrite everything. That part was not fun and took a lot of effort, but now I have everything up and running on OpenGL 3.3. (and no, I'm not too happy about different manufacturers GLSL compilers, but I did choose my poison...)

So back to the Second Reality I mentioned earlier. Looking at it now the effects there are (with perspective given by my current knowledge) fairly simple. Granted, doing all that with old hardware would take a lot of effort and micro-optimization, but still the principles are clear.

And the same curiosity that drove me back then still is there. As I am now a bit more familar with modern graphics hardware and many of the effects are done I find myself often wondering on the details when playing. How did they do this or that, or managed to do that effect there, or how to make that effect the fast enough.

Does this take away enjoyment? No. But it still is kinda funny to find myself trying to figure out how they did nice appreance of Geralt's armor or peasant's tunic during some of the long conversations.
  
Then I catch myself and smile. And think that might be something I'd like to use in my next project - which I am actually actively (well, kinda, hour a day or so) working on now.


Ei kommentteja:

Lähetä kommentti