Replacement Laptop, and Framebuffers

Hey Folks! Hope everyone had a good weekend. Friday's laptop failure caused a bit of stress in mine, but I think I've found a replacement laptop that'll do the trick. Should be here soon!

Getting back to the prototype, my first task today was to sort out the render-order of the sprites in the ship editor. Normally, OpenGL has a thing called "depth sorting," to help it decide which models are in front of others to reduce overdraw. However, no matter how much I tried, I couldn't get it to work. I could get variations of missing OpenGL renders and missing everything renders, but no sorted sprites. In the end, I just hacked a 2D array to store each group of sprites based on their layer info from the JSON data. Good enough for now.

Once that was done, I was still faced with another issue: shadow-casting. The old tilemap prototype used a special line-of-sight algorithm to cast shadows. This worked well for game mechanics, but didn't look so hot when it came to objects that spanned multiple tiles.

So one thing I'm trying to figure out is if I can do that fancy shadow-casting you see in some games. Combined with the normal mapped lighting I already have, I think it could really improve the visuals.

To this end, I decided to start looking into framebuffer objects (FBOs). OpenGL allows you to not only render a scene to the screen, but also render a scene to a texture, do some operation on that texture, or render additional textures, and run shaders and other operations on them as a group.

A popular use of this is to render all the normal maps to a single texture so that lighting need only be done once per pixel, instead of once per model per pixel. (I.e. better performance) It can also be used to do various things like shadows, so I want to see how hard it is to figure out.

So far, the concept seems easy enough. Just setup some extra FBOs, tell OpenGL where to find them, and when it comes time to render, switch the render target from the screen to an FBO (or multiple FBOs, if there are different layers to combine). And when done, switch the target back to the screen and have shaders combine them appropriately.

Except, I can't figure out how OpenFL tells OpenGL to do this. I've seen a few examples out there, but I haven't been able to get them to work. Either the code relies on custom libraries I don't want to use, or it uses outdated OpenFL code.

In theory, I should be able to piece together working modern OpenFL code from these examples. But no dice yet. I've only spent a few hours on that so far, though, so maybe a fresh brain will help tomorrow. For now, have a good night, all!