Bugfixes

2012-07-01 20.00.05

That’s my cat. She’s a princess.

You’ve all had those “I’m an idiot” moments. Well, I had a couple of them. The two issues I was having involved the alpha blending (making the box cover fade into view upon loading the program) and I was having some trouble dragging the camera around. I could make the camera zoom in and out on the image, but not drag the image around on the screen.

Okay, so the alpha blending involved actually knowing that something called alpha blending exists. Silly me. Two lines of code:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Done. My transparency code works perfectly now. Hell’s bells. It just seemed to me that something as fundamentally useful as transparency or interpreting alpha values might be enabled by, you know, default. Silly me.

The other thing involved the fact that I could zoom in but not drag the camera about. Consider that I had the camera’s position stored in a vector called “cameraPos” containing three floating point values, x, y, and z.

I had a little function to detect any changes in the mouse wheel state (for zooming) and a little bit of code to detect whether the mouse button was clicked or dragged around and to record any changes in the position of the mouse and feed them into my camera, which would then be fed into this little “if” statement:

if(wheelDelta != 0){
cameraPos.translate(xDelta, yDelta, .01f * (float)wheelDelta);
}

And I kept wondering why it would always detect and register a change in the mouse wheel, but never a change in x and y values. When you see it….

It really does feel good when you figure something like this out, though. All sorts of good chemicals in my brain right now.

C’est la vie.

Singing the fragment shader blues

dominantSpecies

I’m making a PC version of Dominant Species. There, I said it.

I don’t think I have to tell you that Chad Jenson is a genius or that this board game is one of the best piles of wood and cardboard ever to grace my table. You know perfectly well how excellent Dominant Species is.

It is also easier in concept than a full-fledged video game. I can make this into a video game, theoretically putting out a working hotseat-style game within the next couple months and integrating internet play without too much more difficulty later. Possibly even building an applet version that can be based online.

All of this is almost certain to land me a job with GMT games. And I will be rich beyond my wildest dreams. I think.

Anyway: fragment shaders can lick my balls.

Every fragment color that goes through there (using a four byte RGBA format), no matter which of the 17 million possible floating point values between 0 and 1, will always be output as if it had an alpha value of 1. Which means that transparency is impossible. No fancy fade ins or fade outs or just fucking transparent objects. It’s driving me batty.

If any of you fine, gentle readers know of a way to fix this problem, I will put you in the credits for the first full-fledged game I create.

Meine Realität ist fragmentiert.

Backing up a bit.

tokens

The holidays were busy. I accomplished exactly nothing. Well, except for one important thing. My original project is being put on hold for a while. I realized something very important, and if you are a programmer (and happen to be following this…the odds of which are slim, I know), then you have been expecting this: I have absolutely no idea what I’m doing.

That said, I’m going to tackle something a little simpler. I’m going to port a board game into Java. It’s going to be a board game where you don’t need a sophisticated interface or hidden information (no hidden hand cards yet…I’ll wait to program network play until I can get hotseat down). It will be, in short, a dry run. Something simple so I can practice my programming ability without needing to know as much about graphics.

It will still use OpenGL, specifically LWJGL. So, I’m working toward that ultimate goal. It’s just something a little more attainable. We’ll see how it goes.

Above is a scan of some tokens from the game. Do you know what it is?

Menschen sind nicht die dominante Spezies.

Life in the Shade

Okay.  An update.  Yeah.  I haven’t been working as diligently on this project in the last week or so.  Life, as they say, intervened.  Indeed, this past weekend, I was involved in a 24 hour play production.  Five writers, five directors, 15-18 actors, 24 hours.  As a writer, I was tasked with drawing an object, a location, and a first line from three hats and then writing a fifteen-ish minute play between 8pm and 7am.  The next morning, the casts and directors took my script and made art out of it.  It was all immensely gratifying and fun.  Indeed, it was the first time I’d ever seen anything I’ve written performed by actual human beings.  I have performed sketches that I’ve written, but never watched it from the audience.  So it was fun.  Jolly, great fun.  Perhaps I’ll post the script to the play here at some point in the future.

Anyway.  I’ve had a bit of a breakthrough.  I have been wracking my brain to come up with ways to get more than 30 frames per second.  I have a really nice computer; this is no reason that I should be getting any less than 60 frames per second on a rendered 2D world.  Well, it turns out that the Lightweight Java Games Library (LWJGL) is a pretty curious and odd API and not only was I using only the tiniest fraction of its functionality, I was using literally the oldest commands OpenGL had to offer.  I have found a far more efficient way of rendering the map.  The problem is, I have to rewrite the whole thing.  This is fine, of course.  The first test program was just a way of seeing whether the heightmap software worked and whether I could make a map that I could scroll through.  That worked, so, great.  But then I hit the wall.

I have a spritesheet for an avatar (I’ll probably have a post about overcoming the fact that I’m not a pixel artist, or indeed, any artist), but I had no idea how to make it render and animate properly.  Well, yesterday I learned about Vertex Buffer Objects and Vertex Object Arrays.  And my entire life changed.  instead of using just the OpenGL 1.1 commands, I’ve expanded far further, well into OpenGL 3.0.  It has been terrifying.  I had not realized just how much I have to learn yet.  Shaders are a pretty key concept.  If I’m going to be shoving this stuff off to the graphics card to process, I have to use OpenGL shaders.  If I’m going to use OpenGL shaders, I have to learn about…OpenGL shaders.  And so I’m learning GLSL.  And it’s utterly confusing.  But I’m making progress and that’s good and my current goal is to have a world with an avatar by the end of November.  Fingers crossed.

Cirque du fouture de merde.

A New Project

Above is the results of several weeks of work. It has one fatal flaw, however. Allow me to explain.

I am a gamer.  I play video games, board games, role-playing games, and some sports.  My taste in games is very eclectic, but also somewhat mercurial.  I will love a game–obsess even–for a week or two, and then move on to something else.  I have always had a problem with attention span when it comes to games.  I do not believe this is a character defect.  There are simply some absolutely brilliant games that have managed to suck me in for more than 40-60 hours (the flexible benchmark in my mind for a brilliant game), and some that don’t.

The upshot of this is that I have played many, many games.  My Steam library is only about three years old, and yet it’s about 130 games long (some of which I’ve never played, of course).  Through it all, there has always been this little thing in the back of my mind.  This notion that if I had been working on this game, I might have considered doing something differently.  I do not have the slightest notion how difficult it is to make a game.  I can only understand intellectually, by watching the credits roll by at the end of a game, how many people and how much time is involved.  I understand that a big budget game takes many people many, many, many person-hours over several years to complete.  But I don’t actually understand this any more than I understand that the sun is 98 million miles away.

And so, it is with a sort of naive enthusiasm and confidence that I embark on a new personal project.  I have been calling it my “self-education project” with my wife and friends.  For the past month, I have been reading, in true obsessive fashion, everything I can find on Java programming (more on my choice of Java in a moment).  I have been reading articles on game design, AI, terrain generation, pathfinding, data structures, isometric perspectives, sprites, and more.  I’ve written stupid little programs in Java and OpenGL. A blackjack game, a little-ship-that-shoots-at-aliens game, and a few others.

Let me back up. I quit my job last spring. I was teaching at a community college in rural North Dakota. Both my wife and I did. The reason for this is convoluted. The job was fun and rewarding. But the pay was pretty abysmal and we had few friends there and no family. Not to mention, there is nothing to do out there. In the end, the reason we took the chance and quit was simply the fact that the thought of staying for another year (after two years already) was a deeply depressing thought. So we quit.

And we didn’t manage to find brilliant replacement jobs before our summertime paychecks ran out.

This means that I’m back to substitute teaching and my wife (who is far more aggressive than I at job searching) is back to bartending. This is fine for now. However, I need something to work on. And one day, two months ago maybe, I was reading a book in a hammock (this was my indolent summer after quitting a teaching job which pro-rated paychecks throughout the summer–yay!), I got an idea. It was nebulous then, and it continues to be nebulous, but it is an idea.

I haven’t been able to write fiction all summer. There has just been a part of me that refused to do it. This is purely my own lack of self-control, but it is also the fact that I simply do not have a good idea to run with (excuses, excuses). I now have an idea that I want to run with. However, I do not know much about computer programming (or at least I didn’t). I took a few computer science classes in college and learned some basic C++ and even a little Lisp, but that’s it. I knew some syntax, but I did not know “how to program.”

And so I got it in my head that I wanted to do a feasibility study. I wanted to discover just how difficult it would be for an expert-level user (someone who understands at an intuitive level the current conventions about how to use a computer, and currently operates his own, self-constructed Windows box) with almost no real knowledge of actual computer programming to make a video game of real quality. How long would such a project take? What language should I learn? What books/articles should I read? Will I, as I often do, get bored and give up?

So that’s the experiment, and so far so good. It has been two months, give or take, and from here on out, I will make an attempt to regularly post about it here on the Spin.

And so I’ll share a few of my thoughts here. First: Java.

I chose Java because it’s portable. There is some concern that it’s not as fast a language as it could be. This is true. The JRE, from what I understand, makes it a very high level language. Not as high as, say, a scripting language, but certainly not as close to the machine as C++. But machines are faster and stronger these days. Some very sophisticated software is programmed in Java, especially in gaming. Minecraft, for instance, is programmed in Java using the Lightweight Java Games Library (LWJGL), an OpenGL interface for graphics acceleration. I’m not looking to make Minecraft or even come close to its success (Marcus Persson was a professional programmer before he made Minecraft), but I’m interested in using some of the same technology. Knowing how robust and tight Minecraft is, gives me hope that a simple 2D isolinear game will also run well using the same language.

So I started reading a text on Java. This one, to be exact. And it’s…just truly marvelous. And I had some great success with it. I did get impatient before finishing the text (c’est la vie), but I got through the essential stuff. I have a good idea of how to navigate the Java API, I understand variables and pointers, I have a working understanding of how Java handles exceptions, I think I know enough about data structures, recursion, searching, sorting, and all that other good stuff, that I just started looking up some stuff that would be useful for my project.

I’m starting with something really hard. Perlin noise. I want to make a heightmap so I can generate the terrain of an alien world so that everyone who plays the game will play on a different world. This has been a nightmare. I’ve read many articles about Perlin noise and I’ve read lots of forum posts by people who are doing or have done exactly what I am trying to do. People who are all like, “I be learning how 2 program for 2 weeks now, and I ned a good tut on perlin noise.” And that was me, too. I wanted a good tut. I needed it. In my brain. But there isn’t one. At least, not one for someone with my incomplete knowledge base.

Oh sure, there’s a lot of truly great literature. This is something I have struggled with all my career when it comes to mathematics. I was able to construct a pretty solid intuitive understanding of how the math works, but there was a barrier between that intuitive understanding of what it was and how to actually…just…do maths. Same here. I get how Perlin noise works, I just don’t understand how to implement it in java and just make it fucking happen on my monitor.

What I ended up doing was reading every article I could and realizing that, as a math enthusiast, but not a math expert, I was never going to completely understand the algorithms involved in generating any kind of coherent noise. But I persevered. I looked for algorithms Read some pseudocode, found it very difficult to translate to Java, gave up, looked for something else, finally found complete source code in C# for a Perlin noise algorithm with lots of options. This was last night. I stayed up way too late. I am so tired today at work. But I am satisfied that I have finally found it. I generated my first, very rough heightmap last night. And boy…did it feel good. I even managed to write some of the code myself.

And so, the image at the top of the post is the first output that my algorithm pumped out. But what in the hell is up with that slash through it? I have no idea what in the code caused it and I can see the next few weeks will be spent trying to figure out how to get rid of it. Wish me luck.

Ciao.