Indiepath's TexturedPoly and color/alpha?

BlitzMax Forums/BlitzMax Programming/Indiepath's TexturedPoly and color/alpha?

Raph(Posted 2006) [#1]
I posted about this over on his support forums, but I figured I'd ask here too, since it looked likely that was I missing something obvious about texture formats.

I am getting behavior I don't understand when using this module (which works beautifully otherwise, btw, so many thanks!).


Import indiepath.texturedpoly
SetGraphicsDriver GLMax2DDriver()
graphics 640, 480, 0
Cls

img = LoadImage("testtext.jpg")

c1# = Float($88888888)
Local xyuv:Float[] = [ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, c1, 0.0, 0.0, ..
                     128.0, 0.0, 0.0, 0.0, 0.0, 1.0, c1, 1.0, 0.0, ..
                      128.0,128.0, 0.0, 0.0, 0.0, 1.0, c1, 1.0, 1.0, ..
                      0.0,128.0, 0.0, 0.0, 0.0, 1.0, c1, 0.0, 1.0 ]

c2# = Float($FFFFFFFF)
Local xyuv2:Float[] = [ 128.0, 0.0, 0.0, 0.0, 0.0, 1.0, c2, 0.0, 0.0, ..
                     256.0, 0.0, 0.0, 0.0, 0.0, 1.0, c2, 1.0, 0.0, ..
                      256.0,128.0, 0.0, 0.0, 0.0, 1.0, c2, 1.0, 1.0, ..
                      128.0,128.0, 0.0, 0.0, 0.0, 1.0, c2, 0.0, 1.0 ]

c3# = Float($333333FF)
Local xyuv3:Float[] = [ 256.0, 0.0, 0.0, 0.0, 0.0, 1.0, c3, 0.0, 0.0, ..
                     384.0, 0.0, 0.0, 0.0, 0.0, 1.0, c3, 1.0, 0.0, ..
                      384.0,128.0, 0.0, 0.0, 0.0, 1.0, c3, 1.0, 1.0, ..
                      256.0,128.0, 0.0, 0.0, 0.0, 1.0, c3, 0.0, 1.0 ]

c4# = Float($88888844)
Local xyuv4:Float[] = [ 384.0, 0.0, 0.0, 0.0, 0.0, 1.0, c4, 0.0, 0.0, ..
                     512.0, 0.0, 0.0, 0.0, 0.0, 1.0, c4, 1.0, 0.0, ..
                      512.0,128.0, 0.0, 0.0, 0.0, 1.0, c4, 1.0, 1.0, ..
                      384.0,128.0, 0.0, 0.0, 0.0, 1.0, c4, 0.0, 1.0 ]                     
                     
TPoly.Initialise()

TPoly._Begin
TPoly.Draw(img, 0, xyuv)
TPoly._End

TPoly._Begin
TPoly.Draw(img, 0, xyuv2)
TPoly._End

TPoly._Begin
TPoly.Draw(img, 0, xyuv3)
TPoly._End

TPoly._Begin
TPoly.Draw(img, 0, xyuv4)
TPoly._End

SetColor 255, 255, 255
DrawText "$88888888", 0, 0 ' why is this full bright?
DrawText "$FFFFFFFF", 128, 0 ' why is this red?
DrawText "$333333FF", 256, 0 ' why is this missing?
DrawText "$88888844", 384, 0 ' why isn't this alpha?

Flip

While not KeyHit(KEY_ESCAPE)
   
Wend

End


I expected $FFFFFFFF to give me the normal image, not $88888888. Instead, it's brick red. And the alpha bits seem to just not work.

Am I clueless or missing something?


Space_guy(Posted 2006) [#2]
try to lower the alpha value to just under FF like FE for example. i think that did the trick for me.


Raph(Posted 2006) [#3]
$FFFFFFFE results in no image at all -- as if it were full alpha.


Raph(Posted 2006) [#4]
Anyone got any more insight on this?


skidracer(Posted 2006) [#5]
Instead of Float(color) try the following FloatInt(color) which uses bitbanging (my word) instead of type conversion:

Function FloatInt#(i32)
	Return Float Ptr (Varptr i32)[0]
End Function



Hotcakes(Posted 2006) [#6]
That's a nice manly word. =]


skidracer(Posted 2006) [#7]
Hmmm, according to Google it's not my word after all.


Raph(Posted 2006) [#8]
Thanks, skid, that does in fact seem to have done the trick. :)


Raph(Posted 2006) [#9]
Actually, it didn't quite do the trick after all.

To be specific, the alpha works now. (Though it's in AARRGGBB format, not RRGGBBAA format as Indiepath had indicated?)

But I cannot get smooth tinting down the scale from full color image to black. e.g. $FFFFFFFF gets me the normal image, and $FF000000 gets me a black image... but check out this little app -- ranges from 128, 128, 128 to 192, 192 , 192 are tinted reddish-brown. 127, 127, 127 is correct, and 192-255 also seem to be correct.

I'm baffled again.

Import indiepath.texturedpoly
SetGraphicsDriver GLMax2DDriver()
Graphics 640, 480, 0

SetBlend ALPHABLEND
TPoly.Initialise()

a = 255
r = 255
g = 255
b = 255

img = LoadImage("grass11.png")

While Not KeyHit(key_escape)

	Cls
	
	graylevel = 0
	For y = 0 To 2
		For x = 0 To 4
	
			xpos# = x * 128
			ypos# = y * 128
			c1# = floatint((255 Shl 24) | (graylevel Shl 16) | (graylevel Shl 8) | (graylevel Shl 0))
			Local xyuv:Float[] = [ xpos, ypos, 0.0, 0.0, 0.0, 1.0, c1, 0.0, 0.0, ..
		    	      			  xpos+128.0, ypos, 0.0, 0.0, 0.0, 1.0, c1, 1.0, 0.0, ..
		        	              xpos+128.0,ypos+128.0, 0.0, 0.0, 0.0, 1.0, c1, 1.0, 1.0, ..
		            	          xpos,ypos+128.0, 0.0, 0.0, 0.0, 1.0, c1, 0.0, 1.0 ]
		                  
			TPoly._Begin
			TPoly.Draw(img, 0, xyuv)
			TPoly._End
			SetColor 255, 255, 255
		
			DrawText graylevel+","+graylevel+","+graylevel, xpos, ypos
			graylevel:+16
			If graylevel > 255 Then graylevel = 255
		Next
		graylevel:+16
	Next
	
	c5# = floatint((r Shl 24) | (g Shl 16) | (b Shl 8) | (a Shl 0))
	
	Local xyuv5:Float[] = [ 0.0, 384.0, 0.0, 0.0, 0.0, 1.0, c5, 0.0, 0.0, ..
	          			  0.0, 512.0, 0.0, 0.0, 0.0, 1.0, c5, 1.0, 0.0, ..
	                      128.0,512.0, 0.0, 0.0, 0.0, 1.0, c5, 1.0, 1.0, ..
	                      128.0,384.0, 0.0, 0.0, 0.0, 1.0, c5, 0.0, 1.0 ] 
	             
	TPoly._Begin
	TPoly.Draw(img, 0, xyuv5)
	TPoly._End
	
	SetColor g, b, a
	DrawText r + " " + g + " " + b + " " + a, 0, 400
	DrawText "Up and down arrows to adjust the gray level.", 128, 440
	DrawText "128-192 will be reddish.", 128, 460
	
	If KeyDown(key_up)
		a:+1
		g:+1
		b:+1
	EndIf
	
	If KeyDown(key_down)
		a:-1
		g:-1
		b:-1
	EndIf
	
	
	Flip

Wend

End

Function FloatInt#(i32)
	Return Float Ptr (Varptr i32)[0]
End Function



TartanTangerine (was Indiepath)(Posted 2006) [#10]
I see my docs are wrong, thanks for emailing me and letting me know.


Raph(Posted 2006) [#11]
I don't know your email address, else I would have -- it's not in your profile or in the license doc for the module...? I posted to your support forum with the original problem as well, actually, but the forums went away the next day. :( I've been checking them almost every day hoping they were back up.

For a while, I couldn't find you on the forums here either, because your handle changed. In any case, I do find the modules excellent -- I use the projmatrix in everything now. This particular thing is still baffling me, though.


Space_guy(Posted 2006) [#12]
aah. i remeber that. it was also an alpha thing. when alpha was set to 1 the gradients were very weird and as soon as i lowered the alpha to just below 1 it all worked.


Raph(Posted 2006) [#13]
Thanks, Space_guy! The #FE did indeed work now that the FloatInt() function is there. :)


Space_guy(Posted 2006) [#14]
:) great