Erm... I now have a problem... I've changed the code so that it can "LOCK PIXELS" by using "CREATE MEMBLOCK FROM IMAGE", but as every time I use peeks and pokes, I get errors in DBP...
This is the new code that causes memblock out of range error:
Rem ***** Included Source File *****
type texture_mixer
red_rng as integer
grn_rng as integer
blu_rng as integer
red_half as integer
grn_half as integer
blu_half as integer
red_val as integer
grn_val as integer
blu_val as integer
endtype
function create_terrain_texture2(size,noise,seed)
` setup the four base texture values first
dim t(3) as texture_mixer
for a=0 to 3
t(a).red_rng = rnd(250) + 5
t(a).grn_rng = rnd(250) + 5
t(a).blu_rng = rnd(250) + 5
num = rnd(3)
if num = 0
t(a).red_rng = t(a).red_rng >> 1
else
if num = 1
t(a).grn_rng = t(a).grn_rng >> 1
else
if num = 2
t(a).blu_rng = t(a).blu_rng >> 1
endif
endif
endif
t(a).red_half = t(a).red_half >> 1
t(a).grn_half = t(a).grn_half >> 1
t(a).blu_half = t(a).blu_half >> 1
t(a).red_val = rnd(255)
t(a).grn_val = rnd(255)
t(a).blu_val = rnd(255)
next
` get noise map dimensions and scalar vals
nm_wid# = image width(noise)
nm_hgt# = image height(noise)
nm_xmult# = nm_wid# / size
nm_ymult# = nm_hgt# / size
` create temp bitmap for noise image
`bm_noise = find free bitmap()
`create bitmap bm_noise, nm_wid#,nm_hgt#
`paste image noise,0,0
` create memblock from image
mb = find free memblock()
make memblock from image mb, noise
` create temp bitmap for new texture
bm_temp = find free bitmap()
create bitmap bm_temp, size, size
lock pixels
for y=0 to size-1
for x=0 to size-1
` get noise map height for current position
`set current bitmap bm_noise
` *** This line worked in the previous code
`a = ( point(nm_xmult# * x , nm_ymult# * y) >> 6 ) and 3
` *** and now this line doesn't
p = ( ( nm_ymult# * y * nm_wid# ) + ( nm_xmult# * x ) ) * 3
a = ( memblock byte( mb, 14 + p ) >> 6 ) and 3
` calc colour val for the texture and plot pixel
`set current bitmap bm_temp
rc = t(a).red_val + ( rnd(t(a).red_rng) - t(a).red_half )
gc = t(a).grn_val + ( rnd(t(a).grn_rng) - t(a).grn_half )
bc = t(a).blu_val + ( rnd(t(a).blu_rng) - t(a).blu_half )
if rc < 0
rc = 0
else
if rc > 255
rc = 255
endif
endif
if gc < 0
gc = 0
else
if gc > 255
gc = 255
endif
endif
if bc < 0
bc = 0
else
if bc > 255
bc = 255
endif
endif
c = ( rc << 16 ) + ( gc << 8 ) + bc
dot x,y,c
next
next
unlock pixels
` create new image from blended texture
`delete bitmap bm_noise : set current bitmap bm_temp
img = find free image() : get image img, 0,0, size-1,size-1
delete bitmap bm_temp
endfunction img
I'm assuming 4 bytes per pixel with an offset of 12 (I've added 2 to skip the alpha if any to be safe) from the memblock start position. The image has been created with a power of 2 so it won't be stretched so my pixels pitch value should be correct.
Can anybody help me with this error?
Warning! May contain Nuts!