:P
Ovals for erm... prime minister
For what it's worth, not much considering Rob's code is better (added some scene code to show the final result and added in alpha based on the darkness of the pixels):
Graphics3D 800,600
SetBuffer BackBuffer()
Global steps = 255
Global size# = 256 ; texture size
Global texture = CreateTexture(size,size,2)
Global image = CreateImage(size,size)
gradiant_color(texture,steps,0,0,0,255,255,255)
set_alpha(texture)
;set up a little scene to see the texture on a sprite
Global sprite = CreateSprite()
EntityTexture sprite,texture
Global camera = CreateCamera()
PositionEntity camera,0,0,-10
Global cube = CreateCube()
EntityColor cube,255,255,0
PositionEntity cube,0,1,5
While Not KeyHit(1)
TurnEntity cube,1,1,1
UpdateWorld
RenderWorld
DrawImage image,0,0
Flip
Wend
End
Function gradiant_color(texture,steps,start_R,start_G,start_B,end_R,end_G,end_B)
Local size# = TextureWidth(texture)
Local percent#
Local temp1#
Local temp%
SetBuffer TextureBuffer(texture)
For loop = 0 To (size/2)-1
stage_percent# = 1.0/steps ; get the number between 0 and 1, that step will be set against1
percent# = loop/(size/2) ; get the percentage of the loop completed (0 to 1 basically)
temp = Int(percent / stage_percent) ; count number of steps done so far.
temp1# = temp ; make the temp variable into a float number
temp1# = temp1/steps ; round number between 0 and 1 so to work out color information
temp_r# = (end_R - start_R) * temp1
temp_g# = (end_G - start_G) * temp1
temp_b# = (end_B - start_B) * temp1
Color temp_r,temp_g,temp_b
Oval loop,loop,size-(loop*2),size-(loop*2)
Next
SetBuffer BackBuffer()
End Function
Function set_alpha(texture)
LockBuffer TextureBuffer(texture)
For loop=0 To TextureWidth(texture)-1
For loop1=0 To TextureHeight(texture)-1
RGB1=ReadPixelFast(loop,loop1,TextureBuffer(texture)) ; read the RGB value from the texture
r=(RGB1 And $FF0000)Shr 16;separate out the red
g=(RGB1 And $FF00) Shr 8;green
b=RGB1 And $FF;and blue parts of the color
a=(RGB1 And $FF000000)Shr 24 ; extract the alpha
a=r
newrgb= (a Shl 24) Or (r Shl 16) Or (g Shl 8) Or b ; combine the ARGB back into one value
WritePixelFast(loop,loop1,newrgb,TextureBuffer(texture)); write back to the texture
Next
Next
UnlockBuffer TextureBuffer(texture)
End Function