palette based animation / colour cycling?

Started by
4 comments, last by Daft_ Panzer 17 years, 1 month ago
This was a common trick in old-school games for rainbow effects etc. I was wondering if something like this is possible in OpenGL? IE can you edit a texture's palette 'on the fly' between screen updates? Currently im not sure that its possible, doing anything with texture palettes seems very complicated. Thanks for any help...
Advertisement
There was/is a paletted textures extension, but it's being phased out unfortunately. You can emulate certain effects with multitexturing and by scrolling your palletted texture across another using the texture matrix, but it's not as flexible.

Otherwise you can use a fragment shader to lookup from your base texture into a 1d palette texture which would behave the same way. Of course the comes with the cost of having to use fragment shaders and an extra texture read.
Thanks, I will look into fragment shaders, I don’t know anything about that. Seems like multitexturing could be the way to go, if I can get the alpha from one texture to another.

I guess you might be wondering why I wanted to do this anyway?

Basically what I want is something like an animated ‘rainbow text’ effect. I know it sounds silly and pointless, but I really want to be able to do this, to get that retro feel :) And its annoying the hell out of me knowing that I cant do this!



What I *can* do is make a texture with a rainbow pattern on it. And I can make a function to draw a rectangle with the texture coordinates moving, so the ‘rainbow’ seems to be animated…

I can also make text appear on screen. I have my own custom function for drawing my own text characters as textured rectangles. The PNG importer I use can set pure black as invisible, to get the masked effect. Or I can use two textures blended over each other (one with the masked area in white, one in black), and get masking that way.

*However*, I don’t know how to combine these two. Say I want the moving ‘rainbow’ texture to appear over the text, keeping the areas outside the text characters as transparent, not black, not white, and not ‘rainbow’. There doesn’t seem to be any combination of blending I can use to achieve this. Since the ‘rainbow’ texture is going to be sliding around over the image, I can’t put black areas on it to achieve masking.

Is there a way of copying the alpha values from a PNG image, and temporarily pasting that into another texture? Or somehow using it to determine which parts of the ‘rainbow’ texture should be transparent?

Basically I want to get any kind of abstract masking over full-square textures, without having to edit those textures to have black patches in the right areas etc. Come to think of it, this would be very useful for all kinds of stuff.

Sorry if this seems pointless or doesn’t make sense :(

Id be *very* grateful for any help :)
Standard multi-texturing should work here - you define your characters with an alpha channel (probably RGBA or LUMINENCE textures) and use the alpha to define the shape of the text. Then you set your multitexturing up to multiply/modulate one texture with another (this is the default state IIRC), and draw using your text texture and rainbow texture at the same time.
just make your rainbow texture seamless and scroll the texture coordinates.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Well it works great :D I’ve finally got textures moving over a masked object (for both the two-texture method and alpha imported with a PNG texture)



Getting multitexturing working was easy with help from NeHe, the hardest part was cleaning up afterwards. I had some weird issues where it seemed to keep the last pixel used in multitexturing, and then shaded everything with that pixel during the next screen update??? EG with the rainbow texture, the whole screen was cycling through going different colours :) I learnt that I have to be very careful to call ‘glActiveTextureARB(GL_TEXTURE1_ARB)’ (IE the second texture) and then ‘glDisable(GL_TEXTURE_2D)’ after using the multitexturing, to stop weirdness happening.

This topic is closed to new replies.

Advertisement