Ok, it's fixed this way. And now I hope that the memblocks used will not come in the way with the memblock you use yourself. And I also deleted the memblocks now after usage.
sync on : sync rate 0
set display mode 1024,768,32
randomize timer()
rem create green texture
for x=0 to 128
for y=0 to 128
ink rgb(rnd(100),200+rnd(50),rnd(100)),0
dot x,y
next y
next x
get image 1,0,0,128,128
rem create opacity map
for x=0 to 128
for y=0 to 128
x#=x : y#=y
ink rgb((sin((x#/128.00)*180.00)*sin((y#/128.00)*180.00))*255,(sin((x#/128.00)*180.00)*sin((y#/128.00)*180.00))*255,(sin((x#/128.00)*180.00)*sin((y#/128.00)*180.00))*255),0
dot x,y
next y
next x
get image 2,0,0,128,128
ink rgb(255,255,255),0
rem make cube object
make object sphere 1,10
texture object 1,1
rem make matrix
make matrix 1,1000,1000,10,10
rem position object
move camera 20
position object 1,camera position x(),camera position y(),camera position z()
move camera -20
rem vars
time=timer()
transparencytype=0
percentage#=100.00
rem LOOP
do
text 0,0,str$(screen fps())
text 0,20,str$(percentage#)
text 0,60,"Press 't' for transparency effect"
text 0,80,"Press 'o' for opacity mapping"
text 0,100,"Press up and down to change percentage"
rem time stuff
dt#=(timer()-time)/1000.0
time=timer()
rem rotate object
yrotate object 1,wrapvalue(object angle y(1)+(120*dt#))
if transparencytype=0
text 0,40,"TRANSPARENCY EFFECT"
if downkey()=1
percentage#=percentage#-(50.0*dt#)
if percentage#<0.00 then percentage#=0.00
if percentage#>100.00 then percentage#=100.00
settransparency(1,1,percentage#)
endif
if upkey()=1
percentage#=percentage#+(50.0*dt#)
if percentage#<0.00 then percentage#=0.00
if percentage#>100.00 then percentage#=100.00
settransparency(1,1,percentage#)
endif
endif
if transparencytype=1
text 0,40,"OPACITY MAPPING"
if downkey()=1
percentage#=percentage#-(50.0*dt#)
if percentage#<0.00 then percentage#=0.00
if percentage#>100.00 then percentage#=100.00
setopacitymappingon(1,1,2,percentage#)
endif
if upkey()=1
percentage#=percentage#+(50.0*dt#)
if percentage#<0.00 then percentage#=0.00
if percentage#>100.00 then percentage#=100.00
setopacitymappingon(1,1,2,percentage#)
endif
endif
if inkey$()="t" then transparencytype=0 : settransparency(1,1,percentage#)
if inkey$()="o" then transparencytype=1 : setopacitymappingon(1,1,2,percentage#)
sync
loop
rem THE FUNCTIONS
function settransparency(object,image,percentage as float)
make memblock from image image+100,image
for x=1 to memblock dword(image+100,0)
for y=1 to memblock dword(image+100,4)
write memblock byte image+100,((((y-1)*memblock dword(image+100,4))+(x-1))*4)+15,int(percentage*2.55)
next y
next x
make image from memblock image,image+100
delete memblock image+100
set object transparency object,1
endfunction
function setopacitymappingon(object,image,opacitymap,percentage as float)
make memblock from image image+100,image
make memblock from image opacitymap+50,opacitymap
part#=percentage/100.00
opacsize=memblock dword(opacitymap+50,0)*memblock dword(opacitymap+50,4)*4
for x=1 to memblock dword(image+100,0)
for y=1 to memblock dword(image+100,4)
pos=((((y-1)*memblock dword(image+100,4))+(x-1))*4)+15
write memblock byte image+100,pos,part#*memblock byte(opacitymap+50,(pos-(int(pos/opacsize)*opacsize))-3)
next y
next x
make image from memblock image,image+100
delete memblock image+100
delete memblock opacitymap+50
set object transparency object,1
endfunction