Making something flash white

Monkey Forums/Monkey Programming/Making something flash white

Grey Alien(Posted 2013) [#1]
Hi all, I want to make an alien that is hit flash pure white.

Currently I draw a second image over the top with additive blend set to 1. This makes it brighter but not pure white.

A dev friend who uses openGL says he does this:

"I used GL_EXT_secondary_colour for that, and set it to add 255,255,255,0 thus turning every pixel white but leaving alpha alone"

Does anyone know if it's possible to do that in Monkey without a module tweak? Or do you have an alternative method (I'd rather not a create a pure white image duplicate of every game graphic)? Or have you made a decent module modification to handle that?

Many thanks in advance!


Gerry Quinn(Posted 2013) [#2]
I don't believe it is possible in Monkey. It seems like something that would be system dependent.


therevills(Posted 2013) [#3]
Could you create the white images on the fly using ReadPixels/WritePixels?


SLotman(Posted 2013) [#4]
As the prefix says, GL_EXT_secondary_colour is a OpenGL extension, so I doubt it will work on things like HTML5/Flash. iOS/Android/GLFW probably, with tweaks on mojo, or calling opengl directly on your program.

As any OpenGL extension, you first would have to enumerate all extensions, check if it is available, before using it. If some ugly hardware doesn't support it, then you're out of luck. To see how this is done, you could check miniB3D on BlitzMax, it does extensions enumeration on initialization.


Capn Lee(Posted 2013) [#5]
I had a try at doing this but the problem with using readpixels is you can't read from an image, only from the buffer. InvaderJim made a module that could do this here so it would be pretty simple to do using the module, but it's quite old now and there's always the chance it no longer works.


I don't know if it will work with what you're doing, but you can set color higher than 255, that would white out a lot of the texture but still nothing that is pure black. maybe SetColor(1000,1000,1000) and make all pure blacks dark grey?


Gerry Quinn(Posted 2013) [#6]
You can draw the image you want to flash in the buffer and read it from there.

Of course that's not really much different from creating a set of white images.


Capn Lee(Posted 2013) [#7]
wouldn't that run you in to a problem if the image had any transparencies? it would be fine for pixel art but surely you could only get away with it otherwise by removing all red, green or blue from the image, right?


Gerry Quinn(Posted 2013) [#8]
Yeah, you'd need some way to determine transparency. I guess a set of white images is probably the best approach.


Grey Alien(Posted 2013) [#9]
Thanks all! It's actually for an iOS game that I test on PC, so both are using OpenGL. So in theory a mod tweak would be nice and safe if the target was checked first.

Set of white sprites is a pretty massive pain to make and doubles memory use unless I find a better texture format on iOS (and that's another hassle in itself).

I certainly could try using high values for SetColor but I'm not sure if that would work as I assumed that somewhere in the graphics pipeline it would get truncated to 255.


Gerry Quinn(Posted 2013) [#10]
I would think a set of white sprites would be relatively easy, so long as they are in decent size sheets. In Paint Shop Pro I would just make a completely white image, then copy the sprite-sheet alphas to it.

[Of course I don't use a texture packer, so maybe that is an issue for you.]


Nobuyuki(Posted 2013) [#11]
I haven't messed around with gles11 much yet, but if it can interact with mojo you can draw the sprite to the stencil buffer and blit a white rect along the sprite's bounding box.

I also wrote a module to handle this called nDrawExts but it's only been tested on glfw. It might work on iOS but it won't work on anything else right now (and I don't plan on updating it - though it may be rewritten from scratch in purer monkey later on with gles11...)


Shinkiro1(Posted 2013) [#12]
With shaders that would be really easy as you would just set every pixel to white.
Except we don't know how long before they get implemented.


Grey Alien(Posted 2013) [#13]
Shaders+1


muddy_shoes(Posted 2013) [#14]
Just curious, if this is from the TA port, isn't that written via an OpenGL layer? How it is done in the original code should be applicable in Monkey.


Grey Alien(Posted 2013) [#15]
Yep it's for the TA port. I have the original code but I don't want to modify modules ideally. Was just wondering if people had found a cool way to do it in Monkey yet but the answer seems to be no.


Nobuyuki(Posted 2013) [#16]
>Was just wondering if people had found a cool way to do it in Monkey yet but the answer seems to be no.



merry xmas :P

Edit: Works on OpenGL targets only obviously


Grey Alien(Posted 2013) [#17]
Wow awesome thanks! Will try it out. iOS is OpenGL but I wonder which version of Flush it needs. Probably the cpp one.

Do you know if it's fast or slow btw?


Nobuyuki(Posted 2013) [#18]
No idea of the speed on mobile. Only ever tried it on GLFW. Tried it on Android the other day, seemed fast enough although tbqh I didn't measure it.


Grey Alien(Posted 2013) [#19]
Ok thx! Well hopefully I'll find out soon.


Nobuyuki(Posted 2013) [#20]
let me know if it's a good speed. On my Nexus S, changing blend modes seemed to create slowdown after blitting about 30 times a renderloop. Perhaps alpha testing on the stencil buffer is faster.