int main(void)
{

My Blog

Posted 02/15/12 @ 5:13pm - By Ross

Dashed Lines!

So I recently have been playing around with shaders on my Android project and with the removal of stippling from the OpenGL I thought that I had found the perfect opportunity to use a shader. With some thoughts in mind I decided to search the interwebs to see if I was thinking along the right lines. Unfortunately there isn’t much out there on OpenGL ES 2.0 yet. So it fell to me to come up with something that would work, and work it does!

The basic premise was pretty simple. Find out the world coordinates of each fragment and then, using that, determine it’s length from the line origin. Then plug that into a cosine function and alternate drawing it based off if the value returned is negative or positive.

The key to the whole thing is sourcePoint being passed in as the origin of the line. It’s also worth noting that I pass in the modelview matrix and multiply it with the vertex to determine where it is in world space. The use of position as a varying variable is also important since it is interpolated based off all the vertices that affect it. This allows for the position variable in the fragment shader to be the actual position of the fragment in world space.

With all this, I determine the distance between those two points and then use the cosine function (modified based off how I want the dashes to look) to decide to draw it or not.

So without further ado, here is my vertex shader:

1
2
3
4
5
6
7
8
9
10
11
12
uniform mat4 u_modelViewProjectionMatrix;
uniform mat4 mv;
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
varying vec4 position;

void main() {
  gl_Position = u_modelViewProjectionMatrix * a_position;
  position = mv * a_position;
  v_color = a_color;
}

and the fragment shader:

1
2
3
4
5
6
7
8
9
10
11
12
precision mediump float;
uniform vec2 sourcePoint;
varying vec4 v_color;
varying vec4 position;

void main() {
  if (cos(0.1*abs(distance(sourcePoint.xy, position.xy))) + 0.5 > 0.0) {
    gl_FragColor = vec4(0,0,0,0);
  } else {
    gl_FragColor = v_color;
  }
}
Posted 02/08/12 @ 3:31pm - By Ross

GLES2 conversion

The game I’m developing for Android utilizes an open source OpenGL library called AndEngine. I’ve been experimenting with it for about a year now and finally feel as though I’ve got a solid handle on it. But about a month ago I got thrown a curve ball. The core got a huge update as they converted it to support OpenGL ES 2.0. While this is great as it increases it’s functionality, there is a whole new slew of relearning I had to do.

So what changed? First off, the use of a VertexBuffer manager that is now referenced on all drawn objects. This obviously follows from the other big benefit of going to ES 2.0, programmable shaders! I haven’t yet played around with writing my own GLSL programs as I’ve been updating my code to work with the new update, but it’s high on my list to see what it can do. Another nice change is the division of extensions out of the main library. The library itself was starting to get bloated with the inclusion of things like the tmx file format and box2d physics.

The best thing about the conversion is I got a HUGE performance increase after the upgrade. Previously, zooming out all the way on the tmx map would drop frame rates down to the teens. Now it rarely dips below 50. This is credited to big improvements with tmx handling and the A* path generation along with better hardware use.

Another nice side effect is I’ve been going through and rewriting a lot of my code to clean it up. This project started during my junior year in college and there were many mistakes to be found. Not to say it’s now perfect, but it is much better than what it was.

Posted 10/18/11 @ 11:21pm - By Ross

Wanted: More Time

Unfortunately I may be getting a cold…not happy! With Minecraft and MLG vying for my attention from projects that are piling up I haven’t gotten much done with Right to Rule. Hopefully I’ll be getting some time in the coming days to start actually implementing the menu system for castles but Blizzcon and the GSL finals are this weekend so…yea.

Either way, I’ve at least started mocking up what I want the layout to be in photoshop. I may post a picture once I finish the mock-up and then start implementing it. It’s always entertaining to look back on mock-ups I’ve made of websites and how they differ from the final versions. I’m hoping to get the same nostalgia kick from this once a few years go by.

Posted 10/06/11 @ 9:19pm - By Ross

RoadBuilder Done!

That was a lot of work…far more than I expected but it’s finished. And this pretty much sums up how I feel.

I’ll have to do a post breaking down the logic of the entire thing, but suffice to say that it’s a bit messy having to account for all the special cases that arise from having a graph and parsing each 3×3 quadrant. But it’s done and looks pretty good. Take a look at what it looks like:

Procedural generation ftw!

return 0;

}