My texture just turns object green. I'm assuming it has to do with uv texture coords, but I do not completely understand them.
display()
load_grayscale()
make_terrain()
set camera range 0,1,10000
position camera 0,-500,500,-500
point camera 0,0,0,0
change mouse 0
backdrop on
while escapekey()=0
control camera using arrowkeys 0,10,1
endwhile
function load_grayscale()
if file exist("map.bmp")=1
load image "map.bmp",1,1
load image "Common Ground.bmp",2,0
paste image 1,0,0
endif
endfunction
function make_terrain()
backdrop off
tile_size#=10.0
y_tile_size#=10.0
terrain=1
x_size=image width(1)
z_size=image height(1)
size=(x_size+z_size)/2
polys=x_size*z_size*2
vertices=polys*3
memblock_size=12+36*vertices
make memblock terrain, memblock_size
`The first DWORD is the FVF Format, which controls which components each vertex of your mesh will contain.
`The default FVF Format is 338.
write memblock dword terrain,0,338
`The second DWORD is the FVF Size, which is the size in bytes of a single vertex element.
`This size is respective of the FVF Format you specified, which has a default of 36.
write memblock dword terrain,4,36
`The third DWORD is the number of Vertices in your mesh. The remainder of the memblock contains mesh data.
`The mesh data is a sequential list of vertices, containing the component data arranged as specified by the FVF Format.
write memblock dword terrain,8,vertices
position=12
lock pixels
for x=0 to x_size-1
for z=0 to z_size-1
red=rgbr(point(x,z))
green=rgbg(point(x,z))
blue=rgbb(point(x,z))
`````````````````````````````````````````````
`vertice=6*size*(x)+6*(z)
`position=vertice*36+12
x#=x*tile_size#
y#=red*tile_size#
z#=z*tile_size#
u#=x#/10.0
v#=y#/10.0
`````````````````````````````````````````````
make_polys(terrain,position,x#,rgbr(point(x,z))*y_tile_size#,z#,0.0,1.0,0.0,0xFFFFFFFF,0.0,0.0)
position=position+36
make_polys(terrain,position,x#,rgbr(point(x,z+1))*y_tile_size#,z#+10,0.0,1.0,0.0,0xFFFFFFFF,0.0,0.0)
position=position+36
make_polys(terrain,position,x#+10,rgbr(point(x+1,z))*y_tile_size#,z#,0.0,1.0,0.0,0xFFFFFFFF,0.0,0.0)
position=position+36
make_polys(terrain,position,x#+10,rgbr(point(x+1,z))*y_tile_size#,z#,0.0,1.0,0.0,0xFFFFFFFF,0.0,0.0)
position=position+36
make_polys(terrain,position,x#,rgbr(point(x,z+1))*y_tile_size#,z#+10,0.0,1.0,0.0,0xFFFFFFFF,0.0,0.0)
position=position+36
make_polys(terrain,position,x#+10,rgbr(point(x+1,z+1))*y_tile_size#,z#+10,0.0,1.0,0.0,0xFFFFFFFF,0.0,0.0)
position=position+36
next z
next x
unlock pixels
make mesh from memblock terrain,terrain
delete memblock terrain
make object 1,terrain
texture object 1,2
endfunction
function make_polys(ter,pos,x_pos#,y_pos#,z_pos#,nx#,ny#,nz#,diffuse as dword,u#,v#)
`Given the default FVF Format of 338, the first three FLOAT values (12 bytes) of the vertex element would be the XYZ coordinates in model space.
write memblock float ter,pos,x_pos#
write memblock float ter,pos+4,y_pos#
write memblock float ter,pos+8,z_pos#
`The second three FLOAT values (12 bytes) of the vertex element would be the normals coordinates in model space.
write memblock float ter,pos+12,nx#
write memblock float ter,pos+16,ny#
write memblock dword ter,pos+20,nz#
`The next DWORD is a diffuse colour component that specifies the colour of the vertex.
write memblock dword ter,pos+24,diffuse
`The last two FLOATS are UV texture coordinates for the vertex.
write memblock float ter,pos+28,u#
write memblock float ter,pos+32,v#
`This adds up to 36 bytes which is the size of a single vertex.
`Multiply 36 by the number of vertices in the mesh and you get the overall size of the mesh data.
endfunction
function display()
perform checklist for display modes
sr=0
for cq=1 to checklist quantity()
width=checklist value a(cq)
heigt=checklist value b(cq)
depth=checklist value c(cq)
whd=width+heigt+depth
if depth=32
if whd>sr
sr=whd
set display mode width,heigt,depth
endif
endif
next cq
change mouse 1
endfunction