Project Frontier fixes

I've worked a bit on Shamus Young's project Frontier, fixed a few things, and someone in the comments asked what I did exactly. After writing it up, I decided it's too long for a comment, so I made a post from it. So, lets go one by one:

The grass flickering was from these lines in the grass vertex shader:

float move;
if (IN.uv.y > 0.5)
  move = min (IN.uv.y, 0.75);
else if (IN.uv.y < 0.5)
  move = IN.uv.y * 2.0f;

Which left move uninitialized if IN.uv.y == 0.5. (And I guess on some Cg compilers it defaults to 0, which is why they didn't have the problem.)

I solved it by separating the grass and brush shaders, because I don't like 'if's in Cg code anyway.

The tree problem was more complicated. The textures used for the trees were made by "rendering" them with OpenGL, then loading the rendered image from the video card. Then, they were uploaded to the video card again as a texture.

But rendering happens to an image called "framebuffer", and it seems on my computer and some others, the default framebuffer doesn't have an alpha channel. (Which normally makes sense, since you'd never "see through" your final rendered images when rendering the game anyway.) Because of this, the tree textures didn't get transparent parts, and the parts that should've been transparent were in the "background color" that was set, which happened to be purple.

So, my solution was to use another OpenGL extension, which allowed me to render directly into the texture (which does have an alpha channel), instead of the default framebuffer. This also has the nice side effect that I don't need to download the texture from the video card, than upload it again.

Once I fixed this, the stars had tree bark textures. (I didn't take a screenshot, but it was quite a sight :) ). That was because the stars2.bmp texture was loaded, then later purged, and the reference wasn't updated after the purge. I fixed that by just removing the texture purge, because I felt it was unnecessary anyway.

2 thoughts on “Project Frontier fixes

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>