More advanced graphics commands for max2d?

BlitzMax Forums/OpenGL Module/More advanced graphics commands for max2d?

Steffenk(Posted 2007) [#1]
Greetings,
during the last time i've repeatedly felt a need for some more advanced graphics command than those that are packed with BlitzMax (max2d).

The first one was quite easy to solve by myself; I made a command in OpenGL that draws a rectangle with individual colors for each edge which fade into each other. People who've seen the menus of the "Final Fantasy"-series (e.g. FF7) probably know what i mean.

My current problem is more difficult. I want to take the shapes (i.e. the alpha-mask) from sprites and use them with different colors. The practical use would be to make the player blink periodically by drawing a white area in its shape onto it. Currently i have no idea how to implement this (in a fast enough way).

I suspect that i'm not the only person who wrote such small extensions for max2d, so my suggestion would be to collect all those functions, possibly into a new module. The higher availability of those functions could somewhat increase the power of BlitzMax for the creation of graphically impressive games; at least i hope so.

The reason i wrote this into the OpenGL forums is that dx sucks in my opinion and so those new commands will most likely have to be done in OpenGL.


Steffenk(Posted 2007) [#2]
I tried to solve the second problem by modifying the sprites' pixmap on-the-fly now. ~100 fps VS ~800 fps before.
I guess that rules out this solution.

My multi-colored rectangle command also turned out to be quite slow, but only if used with SetAlpha <> 1.0 which I don't understand at all...


ImaginaryHuman(Posted 2007) [#3]
If you're going to do it in OpenGL, which is a good thing, then there are probably several ways you can do this.

One is to have a GL_ALPHA texture containing the alpha channel from the item you want to appear to be white, and then set the source blend operation to GL_SRC_ALPHA_SATURATE and the dest to GL_NONE or something else, switch on blending, and then draw a quad with the GL_ALPHA texture. It will take whatever value is in the alpha channel of the source texture and copy it to all three color components like grayscale, allowing you to draw the mask in white. Then in addition, by setting the colors for each vertex of the quad you can choose what color the mask will be drawn in, which can be different colors for each corner when you enable GL_SMOOTH as the shading method.

There are probably other ways to do it, but an alpha-only texture not only consumes 25% the amount of videoram as a RGBA texture, but it may also be faster to draw than drawing a whole texture with white pixels.

Another way is to use the stencil buffer - cut an area out of a stencil in the shape of the RGB image of the shape you're drawing, and then draw a white quad over the masked area with stencilling on so that it only draws in the shape of the object.