Write to terrain texture

Blitz3D Forums/Blitz3D Programming/Write to terrain texture

You need to get the rgb value of the color for your WritePixel command.

For 32 bit RGB values:

alpha = bits 24 to 31
red = bits 16 to 23
green = bits 8 to 15
blue = bits 0 to 7

argb = (red shl 16) + (green shl 8) + blue

or in your case

argb = (255 shl 16) ; you don't use green and blue

or you could just use $FF0000 for red.

Then:

WritePixel x, y, argb, texbuf

and if you are going to bother to lock the buffer then use:

WritePixelFast x,y,argb, texbuf

You might also want to check your LockBuffer db.

Shouldn't that be LockBuffer texbuf?

One more thing, I think your loops should be 0 to 255, not 0 to 256.


;//////////// 
terrain2=LoadTerrain ("Heightmap.bmp") 
ScaleEntity terrain2, 1,12,1 
PositionEntity terrain2,0,7,0 
EntityTexture terrain2,tex1 

texbuf=TextureBuffer(tex1) 
LockBuffer texbuf

For x=0 To 255
For y=0 To 255 
height=TerrainHeight# ( terrain2,x,y ) 
argb = $FF0000
If height>0.5 
WritePixelFast x,y,argb,texbuf 
EndIf 
Next 
Next 
UnlockBuffer texbuf 
;/////////// 


Hope this helps.
MK