Draw image without texture?

BlitzMax Forums/BlitzMax Programming/Draw image without texture?

Black:
I just tested your code. I don't know what you're doing there because I don't recognize those constants from the OGL 1.1 docs I was looking at, but your code doesn't work. If you set the color to 0, 255, 255, a red sphere will turn dark green, when it should turn bright cyan like the DirectX version above does.

But guess what? I just solved the problem myself!

These functions should work with all drivers on all platforms:

SetGraphicsDriver GLMax2DDriver()


Graphics 800,600


image:TImage=LoadImage("gfx\fruit1.png")
n:Float=0.4
    SetBlend ALPHABLEND

While Not KeyHit(key_escape)
  Cls
    	
	SetAlpha 1.0
	DrawImage image,100,100
	
	SolidColorOn(0, 0, 255)	
	SetAlpha n
	DrawImage image,100,100
	SolidColorOff()
	
    n:+0.01
    If n>1.0 n=0.1

  Flip
Wend


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function enables solid color rendering.
'
' When rendering with solid colors, the color channels of the images you blit will be overridden with the solid color specified.  The alpha channel will
' remain intact however.
'
' This allows you to render a solid color sprite, white for example, with alpha, over the original, to make it appear to glow. 
' You can vary the strength of the effect by using SetAlpha() before you blit the second pass.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Function SolidColorOn(R%=255, G%=255, B%=255)

		Local TexColorArray#[4]

		SetColor(R, G, B)

		?Win32
			If TD3D7Max2DDriver(_max2dDriver) ' If we are currently rendering with DirectX...
			
				PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_SELECTARG2)
				PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE)
			
			Else ' We are using one of the OpenGL drivers.
		?		
				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND)
				
				TexColorArray[0] = R
				TexColorArray[1] = G
				TexColorArray[2] = B
			
				glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, TexColorArray)
		?Win32		
			EndIf	
		?
		
	End Function


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function disables solid color rendering.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Function SolidColorOff()

		Local TexColorArray#[4]
	
		SetColor(255, 255, 255)
	
		?Win32
			If TD3D7Max2DDriver(_max2dDriver)
				PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE)
				PrimaryDevice.device.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE)
			Else
		?	
				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
				glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, TexColorArray)
		?Win32		
			EndIf
		?
	
	End Function 


What the above code is doing is this:

SetColor*(1-Texture) + (Texture*TextureColor)

So if texture is 0.25, and SetColor is 1 and TextureColor is 1 (they must be the same or you get weird effects like reversed colors) then you get:

1 * 0.75 + 0.25 * 1 = 1

So that means if you put in white for both colors, you get white back out. The same for any other color, because (1-Texture) + Texture will always equal 1.


Ps:

Grey Alien:
In yo face!

Told you you gave up too easily. :-)