Josef “Jeff” Sipek

Gaming The Unix Way

So, few weeks ago, after playing Quake4, I’ve been thinking a bit. Large portion of Quake4 can be scripted in their own scripting language. Most of Unreal Tournament 2004 (and possibly previous versions) are scripted - I know most of the networking stack is.

Now, it is time for a screenshot:

The Pentagon!

What is that you ask? Simple, it is a simple OpenGL driven program that displays a rotating (counter-clockwise) pentagon, and draws some text. As far as I know, everyone has to do something similar in a college graphics course. So, what’s so special about this one? I’m glad you’ve asked; the answer is - the programming language. Yes, I have written this in a very unusual programming language, I have used Bash.

Since there are no native OpenGL bindings for Bash, I had to create several small C programs, a renderer, vector transformer (new vector = matrix times old vector), rotator (outputs a matrix for the vector transformer), and some others. With these, I simply draw N-sided polygons, draw text anywhere on the screen, read keyboard input, and some other things.

What else have I made with this? I am working on a simple "room" where you will we able to run around. Currently, I have…

  • …the room
  • …the keyboard keypress code
  • …debug "world info" data (x, y, z, and the three angles) displayed on the screen

What doesn’t work? Well, for whatever reason, if I try to translate the camera position to the initial coordinates, all of the world (the 4 walls, ceiling and floor) completely disappears, leaving the debug text as the only thing there.

9 Comments »

  1. Ok, this is awesome :) Bash is rather unwieldy though, why not Python? :)

    Comment by [unknown] — January 1, 1970 @ 00:00

  2. Simple, Python has a way to talking to OpenGL already (SDL), and although Python is the best scripting language, Bash has something interesting at its core - you use small programs that can be used for anything you want; even things that the original author didn't intend them for; for example, the author(s) of sh (and indirectly bash) probably didn't think that what they were writing would be one day used to draw a 3D scene. As a matter of fact, I doubt that the author(s) of sh even thought of the posibility of it running on a college student's portable computer (read: laptop), and that it would enable him to write anything that would be displayed on a 1680x1050 pixel display. Another utility that I use is awk; I use it to grab the components of a vector for futher processing using bc - I'm pretty sure the authors of the two programs (the original once, not the GNU clones I provide links to) did not think of it as something useful for 3D game - vector manipulation and calculation. So, besides the rather understandable, I did it in bash because I could, I have to say, I did it in bash, because it made sense.

    Comment by [unknown] — January 1, 1970 @ 00:00

  3. Woah. You've turned opengl things into.... unix objects. Wasn't Microsoft going to come up with something like this? I say my dear fellow, you've just kicked Microsoft in the monads.

    Comment by [unknown] — January 1, 1970 @ 00:00

  4. I spent about 12 hours on this project so far, and right now it consits of: 485 lines of C 22 lines in a Makefile 25 lines of Bash for the pentagon program 133 lines of Bash for the "game" program 6 lines of text defining the world (6 walls :-) ) for the "game" 19 lines of Bash for a rotating triangle program (much simpler than the pentagon, but it was the first one I made) So, in total, 690 lines of code.

    Comment by [unknown] — January 1, 1970 @ 00:00

  5. Oh my, that's very cool =) Got a link? I'd like to see the renderer (i'm an opengl newb)

    Comment by [unknown] — January 1, 1970 @ 00:00

  6. I want to clean up the code some more, but here's a link to my repository's version of render.c. The program has one major issue, it doesn't cache the last scene. That creates a problem if you move the window off the screen or behind another window. Once you bring the renderer window back, it doesn't refresh the scene, until it gets a new scene to render. The naive way of fixing it would be to create some abstract syntax and cache the scene myself, but I think that there is a way to do it in opengl using display lists (the scene is actually cached in the graphics card itself.) Of course, the code is GPL.

    Comment by [unknown] — January 1, 1970 @ 00:00

  7. To fully exploit the power of these tools, I suggest you use them to develop a fully three-dimensional version of Greed!

    Comment by [unknown] — January 1, 1970 @ 00:00

  8. First of all, for those of you who don't know, Greed is a game now maintained by the famous (infamous?) Eric Raymond. That's a very interesting idea. The real challenge would be presenting the "grid" to the user in such a way that it is absolutely clear how far away a square is from you. I guess, the "proper" way would be to employ stereo-vision; that is either opening up two renderers (this would require some changes to allow the user to specify the location to put the pipes), or the other just dedicate left/right halfs of one window to the two views. Each view should be offset to create the same parallax as if one was using two eyes. Then you'd just stare at the screen, making sure your eyes are looking straight ahead, instead of the usual meeting at a distance. Overall, it is completely doable, and even a small grid of 7x7x7 would provide wonderful 343 cubes (they can't really be called squares anymore). Maybe the size would be configurable as it is in Minesweeper, where the harder mode has a gigantic board. Mwhahahaha! Chances are, that I will not write this, but if anyone feels like experimenting, feel free to ask questions. :-)

    Comment by [unknown] — January 1, 1970 @ 00:00

  9. Few comments from IRC:
    <jeffpc> do you feel like calling me crazy? https://josefsipek.net/blog/?p=118 :)
    <conman> no you just need a woman
    
    <velco> jeffpc: you're weird
    <velco> ;P
    <jeffpc> thank you :-)
    <velco> I mean, this beats everything ... even some don Quixote projects of mine ...
    <jeffpc> such as?
    <velco> well ... dont't tell anybody ... a real-time kernel and a C compiler ... shhhh!
    * velco looks around
    
    <ijuz_> jeffpclaptop: this BSD zealots would love a bash binding for opengl!
    <ijuz_> so better don't release it or take care that it isn't protable
    <jeffpc> you need a C binding/Glut first :-)
    <jeffpc> and X
    <ijuz_> oh yes
    <ijuz_> so no problem ;)
    <ijuz_> of course real BSD zelotnics are using csh anyway :)
    

    Comment by [unknown] — January 1, 1970 @ 00:00

Atom feed for comments on this post.

Leave a comment

Powered by blahgd