Color Problems

BlitzMax Forums/BlitzMax Beginners Area/Color Problems

Cajun17(Posted 2005) [#1]
I'm having trouble with the colors in the images I'm drawing. All shades of green appear as black. Dark green light green it doesn't matter. I don't think it's a bug, but it could be. If it's needed I can post my code, but it's probably something real simple.


FlameDuck(Posted 2005) [#2]
By all means, do post code. Also post the image in question.


Cajun17(Posted 2005) [#3]
Since I couldn't isolate any area of the code here's the whole thing.
Strict;

Const TILE_WIDTH=96;
Const TILE_LENGTH=60;
Const TILE_HEIGHT=12;
Const TILE_TOP=48;

Const SCREEN_WIDTH=800;
Const SCREEN_HEIGHT=600;

Graphics SCREEN_WIDTH,SCREEN_HEIGHT,32,60
SetMaskColor 255,0,255
SetBlend MASKBLEND
HideMouse()

Type Tile

	Field graphic
	Field passable:Int
	Field reachable:Int
	Field targetable:Int
	Field animated:Int
	Field event:Int
	Field height:Int
	Method AnimateTile()
	End Method
End Type;

Type BattleMap
	Field name:String
	Field width:Int
	Field length:Int
	Field height:Int
	Field slideX:Int
	Field slideY:Int
	Field Map:Tile[,]
	
	Function Create:BattleMap(area:String)
		Local b:BattleMap=New BattleMap
		b.name:String = area
		Local inFile=ReadStream("Maps/"+b.name+".dat")
		b.width=Readint(inFile)
		b.length=Readint(inFile)
		b.height=Readint(inFile)
		Local numTiles=Readint(inFile)
		Local allTiles=LoadAnimImage("Maps/"+b.name+"Tiles.png",TILE_WIDTH,TILE_LENGTH,0,numTiles,MASKEDIMAGE|DYNAMICIMAGE)
		b.Map=New Tile[b.width, b.length]
		For Local xx:Int = 0 To b.width-1
			For Local yy:Int = 0 To b.length-1
				b.Map[xx,yy]=New Tile
				b.Map[xx,yy].height=Readint(inFile)
				If b.Map[xx,yy].height>0 Then
					b.Map[xx,yy].graphic=CreateImage(TILE_WIDTH,(TILE_TOP+(TILE_HEIGHT*b.Map[xx,yy].height)),1,MASKEDIMAGE);
					SetColor(255,0,255)
									
					For Local j = 0 To ImageHeight(b.Map[xx,yy].graphic)
						DrawLine 0,j,TILE_WIDTH,j
					Next
					For Local i:Int = b.Map[xx,yy].height-1 To 0 Step -1
						DrawImage allTiles,0,(i*TILE_HEIGHT),Readint(inFile)
					Next
					GrabImage b.Map[xx,yy].graphic,0,0
				End If
								
				SetColor 255,255,255
			Next
		Next
		
		Return b				
	End Function

	Method Draw()
		SetClsColor 50,50,200
		Cls
		For Local xx:Int = 0 To width-1
			For Local yy:Int = 0 To length-1
				If Map[xx,yy].height>0 Then
					Local screenx=(SCREEN_WIDTH/2)-(TILE_WIDTH/2)+((TILE_WIDTH/2)*xx)-((TILE_WIDTH/2)*yy)+slideX
					Local screeny=(yy*(TILE_TOP/2))+(xx*(TILE_TOP/2))+((height-Map[xx,yy].height)*TILE_HEIGHT)+slideY
					DrawImage Map[xx,yy].graphic,screenx,screeny
					
				EndIf	
			Next
		Next

	End Method 
End Type


Global timer:Int =MilliSecs()+1000
Global ticks:Int=0
Global secs:Int=0
Global a:BattleMap = BattleMap.Create("Testie")
Repeat
	a.Draw()
	DrawText "FPS: "+secs,0,SCREEN_HEIGHT-20
	If timer<=MilliSecs() Then
		timer=MilliSecs()+1000
		secs=ticks
		ticks=0
	Else
		ticks=ticks+1
	End If
		FlushMem()
	Flip 
Until KeyHit(KEY_ESCAPE)
	


and this is the pic


and the data file
http://projects.rpgi.net/tact/files/Testie.dat


ImaginaryHuman(Posted 2005) [#4]
I expect the line "SetColor(255,0,255)" has a lot to do with it - since that color has zero green component.

Also please note that the color that you use for SetColor also affects any images that you draw, working like a `tint` color. For normal drawing you would make sure SetColor is White, ie 255,255,255 before you draw. Otherwise, the SetColor 255,0,255 (which is your magenta color) affects the drawing and will basically turn all your green values to 0.

You'll need to add SetColor 255,255,255 before you DrawImage at some point in the program, probably inside your Draw() method.


Cajun17(Posted 2005) [#5]
Thanks, it's working now. I figured it was something like that, but I didn't think about that line.