Farbwerte in Integers speichern, wo ist der Fehler?

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

 

E. Urbach

ehemals "Basicprogger"

Betreff: Farbwerte in Integers speichern, wo ist der Fehler?

BeitragMi, Jan 31, 2007 14:24
Antworten mit Zitat
Benutzer-Profile anzeigen
Bitte sagt mir, dass der Code falsch ist:

BMax Code: [AUSKLAPPEN]
'Header
SuperStrict

'Init
Graphics 640, 480, 0, 75

'Vars
Global rot:Int = CreateRGBColor(255,0,0)

Print rot
Print Bin(rot)
Print Hex(rot)

'Mainloop
While KeyDown(KEY_ESCAPE)=0 And AppTerminate()=0
   Cls
   
   SetRGBColor(rot)
   DrawText "Test1", 5, 5
   
   SetRGBColor2(rot)
   DrawText "Test2", 5, 25
   
   SetColor 255,0,0
   DrawText "Test3", 5, 45
   
   Flip
Wend

'CreateRGBColor
Function CreateRGBColor:Int(r:Byte, g:Byte, b:Byte)
   
   Return (r Shl 16) + (g Shl 8) + b
   
End Function

'SetRGBColor
Function SetRGBColor(rgb:Int)
   
   SetColor (rgb Shr 16) And 255, (rgb Shr 8) And 255, rgb And 255
   
End Function

'SetRGBColor2
Function SetRGBColor2(rgb:Int)
   
   SetColor (rgb And $00FF0000) / $10000, (rgb And $0000FF00) / $100, rgb And $000000FF
   
End Function


Bei mir wird nur "Test3" rot angezeigt.
Die Funktion CreateRGBColor(r,g,b) packt die 3 Bytes in einen Integer.
Die Funktion SetRGBColor bzw. SetRGBColor2 setzt die aktuelle Farbe durch SetColor.

Das kann doch kein BMax Bug sein.
In B3D funktioniert die Funktion:

B3D Code: [AUSKLAPPEN]
;Init
Graphics 640, 480, 32, 2

;Vars
Global rot% = CreateRGBColor(255,0,0)

Print rot
Print Bin(rot)
Print Hex(rot)

;Mainloop
While KeyDown(1)=0
   Cls
   
   SetRGBColor(rot)
   Text 5, 5, "Test1"
   
   SetRGBColor2(rot)
   Text 5, 25, "Test2"
   
   Color 255,0,0
   Text 5, 45, "Test3"
   
   Flip
Wend

;CreateRGBColor
Function CreateRGBColor%(r, g, b)
   
   Return (r Shl 16) + (g Shl 8) + b
   
End Function

;SetRGBColor
Function SetRGBColor(rgb%)
   
   Color (rgb Shr 16) And 255, (rgb Shr 8) And 255, rgb And 255
   
End Function

;SetRGBColor2
Function SetRGBColor2(rgb%)
   
   Color (rgb And $00FF0000) / $10000, (rgb And $0000FF00) / $100, rgb And $000000FF
   
End Function


Wo ist der Fehler?
The box said, "Requires Windows XP or better", so I installed Ubuntu | Linux is NOT Windows
Flua :: Profiler für BB und BMax :: Partikel-Engine für BMax :: Lyphia-Projekt Quellcode (BMax) :: Automatische Parallelisierung :: Meine Musik

FOODy

BeitragMi, Jan 31, 2007 14:45
Antworten mit Zitat
Benutzer-Profile anzeigen
In BlitzMax ist das Bitwise-And ein & und kein "And".
BlitzMax + MaxGUI, 64-bit Arch Linux: Intel Core² E8500 | 8 GB Ram | GeForce GTX 460 · 1024 MB

BtbN

BeitragMi, Jan 31, 2007 14:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Nicht nur das And ist anders:
And -> &
Or -> |
XOr(Im Normalen sprachraum nichtmehr vorhanden) -> ~
 

E. Urbach

ehemals "Basicprogger"

BeitragMi, Jan 31, 2007 14:54
Antworten mit Zitat
Benutzer-Profile anzeigen
Ok, habs inzwischen selbst bemerkt, war aber etwas verwirrend, weil der Blitz3D-Code ja funktionierte.
Und in der Dokumentation hat mich dieses "binary" verwirrt:
Zitat:
Conditional 'And' binary operator.

Ich hätte mich wirklich besser informieren sollen...
The box said, "Requires Windows XP or better", so I installed Ubuntu | Linux is NOT Windows
Flua :: Profiler für BB und BMax :: Partikel-Engine für BMax :: Lyphia-Projekt Quellcode (BMax) :: Automatische Parallelisierung :: Meine Musik

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group