DrawSquare proc x:DWORD, y:DWORD, dwidth:DWORD, dheight:DWORD, red:DWORD, green:DWORD, blue:DWORD, hdc:HDC
local LineCounterX:DWORD
local LineCounterY:DWORD
local tempX:DWORD
local tempY:DWORD 
local FinalColor:DWORD

mov eax,red
mul eax,1000000
mov red,eax
mov eax,blue
  mul eax,1000
  mov blue,eax
  mov eax,green
  add eax,blue
  add eax,red
  mov FinalColor,eax
  mov eax, dheight
    mov LineCounterY,eax
  mov eax, dwidth
    mov LineCounterX,eax
mov eax, x
add eax, LineCounterX
mov tempX, eax
mov eax, y
add eax, LineCounterY
mov tempY, eax
invoke SetPixel, hdc, tempX, tempY, FinalColor
  dec LineCounterX
  cmp LineCounterX,0
  jne DrawSquareX
dec LineCounterY
cmp LineCounterY, 0   
jne DrawSquareY
DrawSquare endp

This code is almost working.. if I put a nine figure number as a color variable (where Finacolor is) it works.. but I get an error (invalid syntax) for the lines with mul (mul eax,1000000)...

erm... why? (I feel like such a brat, but at least I am keeping it in one thread :))
Posted on 2006-06-19 18:43:47 by talmir
Hi talmir,

Just a suggestion but when dealing with colours stay away from decimal numbers, you should be thinking in HEX. there are no muls involved with colours when dealing with them in hex only shifts which are much more straight forward and alot less costly in speed than MUL. For example if the colour red is 255,0,0 in hex it is represented by 0FF0000h. If you had 0FFh you would only have to SHL eax,16... no multiplication at all. Since the processor sees everything in binary anyway you only have to change your way of thinking about how to structure numbers, HEX is much more compatible with the native CPU instructions than decimal.
Posted on 2006-06-19 18:50:40 by donkey
hmm.. but then I can only set one color, right? If I shift them the preceding spaces get filled with zero´s? Like this 000000040h becomes 000040000h, but I dont know how to add to that so that I could only change the red color and still preserve the previous ones...
Posted on 2006-06-21 10:45:20 by talmir
My description of 24bit color encodings (I might be wrong about the order of the primary color channels, it depends on whether the color system is RGB or BGR etc.. - described is RGB encoding)

Imagine that Primary Colors are constructed of one byte (2 hex digits each.. ie, 00 to FF), giving 256 intensities of each primary color (red, green and blue)..
Our colors are 32bit values (4 bytes) but only 24 bits (3 bytes) are actually used:
XXRRGGBB where XX is always 00

00FFFFFF is intensely white (max red, max green, max blue)
00FF00FF is intensely purple (max red, no green, max blue)

You can invent a heck of a lot of colors, heh.

Posted on 2006-06-21 11:18:24 by Homer
Thanks for the reply but this was not what I was asking about :) I am pretty good with hex numbers and binary.. and can tell what they mean..

my question was :
What is the best way (or easyest) to combine for example 00FF0000h and 0000FFFFh to make 00FFFFFFh?
Posted on 2006-06-21 11:59:44 by talmir
talmir: look up bitwise instructions. If you know you're going to combine eg. the Red part in one register with Blue+Green in another, do something like...

AND  EAX, 000FF0000h
AND  EBX, 00000FFFFh
or    EAX, EBX

- if EAX only has Red part, you can skip the first AND. If EBX only has green+blue, you can skip the second AND. Also, some 24/32bpp implementations use RGB ordering, other use BGR. Some 32bpp implementations use the topmost bits for alpha, other leave them blank (and keep them just for alignment purposes).
Posted on 2006-06-21 12:13:09 by f0dder