Making a grayscale map

Blitz3D Forums/Blitz3D Programming/Making a grayscale map

Picklesworth(Posted 2004) [#1]
I have set up a production map (a grayscale image with splotches all over it) in order to determine what spots in my game are good for resources. It works, but it doesn't. None of the following return anything (they give 0.0) to fort\production. I have tested it however, and fort\production does exist. The readpixel command returns the right number, but the problem seems to lie in the spot where I divide it or multiply it. Why would this be?
function buildFort(x,y,z,name$ = false)

	fort.fort = new fort
	
	fortNum = FortNum + 1
	
	if name$ = false
		fort\name = "Fort " + fortnum
	else	
		fort\name = name$
	endif	
	
	fort\x = x
	fort\y = terrainheight(terrain,x,z) * 128
	fort\z = z
	
	fort\list_drawpage = 1
	
	fort\buildradius = 50
	
	fort\building = 5
	
	;this is to find the fort's production abilities, and shipping bonus
	;setbuffer imagebuffer(prodMap)
	bittocomponent(readpixel(fort\x,fort\z,imagebuffer(prodMap)))
	;divide red (should be the same value as every other colour) by 255
	;to get a number from 0 to 1
	
	;fort\Production = production# * 100
	;fort\Production# = ((B2Cr + 5) / 255) * 100
	fort\Production# = 64 * 100
	
	;picking and drawing stuff	
			
	e.entity = new entity
	e\entityForm = TradePost
	e\parent_id = handle(fort.fort)
	
	building = createcube()
	scaleentity building,rand(2,5),rand(2,4),rand(2,5),true
	positionentity building,fort\x,fort\y,fort\z,true
	TurnEntity building,0,rand(-180,180),0
	entitycolor building,80,60,40
	entitypickmode building,2
	nameentity building,handle(e.entity)
	
	fort\pickID = handle(e.entity)
	
end function
;the bitTocomponent function

; // Bit (argb) to Component (r,g,b)
Function BitToComponent(ARGB)
	B2Cr=ARGB Shr 16 And $FF
	B2Cg=ARGB Shr 8 And $FF
	B2Cb=ARGB And $FF
End Function

;AARGB! IT DOESN'T WORK!!! (this is fine, I mean the fort function)



Also, is there a way to just read a pixel on an image without using imagebuffer? Because either that method killed my framerate, or something very annoying is running in the background (probably the stupid firewall or virus scanner).


koekjesbaby(Posted 2004) [#2]
is B2Cr global? and if all the variables in
((B2Cr + 5) / 255) * 100
are ints, then it's very likely that it will return 0. you might try:
((B2Cr + 5) / 255.0) * 100


hope it helps.


Picklesworth(Posted 2004) [#3]
yep. actually, I just figured it out, I needed to do a subtotal. Is there a limit to how many calculations you can do in a single variable definition?
I'll release the full source so far for my project within a few days if you want to see.


Picklesworth(Posted 2004) [#4]
oh, and the image question was just me being mislead because of a system hogging program my brother was running, who was logged in.