hi all, i want to make my own RGB() function, not using gdi's api, anyone know how to do that?
Posted on 2002-10-25 21:29:54 by dion
Depends if you want to compile a 16-bit pixel or a 32-bit one.

The 16-bit pixel can be 565 (5 bits Red, 6 bites Green, 5 bits blue)
or it can be 555 (5 bits, 5 bits Green, 5 bits blue)

I'm going to sleep now so I wont be able to answer till tomorrow morning see ya later
Posted on 2002-10-25 21:34:29 by x86asm
If you look at the definition for RGB() in the header file you'll see that it's just a macro for assembling a 0x00bbggrr COLORREF.

[size=12]#define RGB(r,g,b) \



[size=12]    movzx  eax,  byte ptr [blue]

shl eax, 16
mov ah, byte ptr [green]
mov al, byte ptr [red][/size]
Posted on 2002-10-25 23:07:58 by iblis
thanks u all ;)

hi x86asm, its so accidentally that u said about 565 and 555 stuff. i just want to ask that after the post. and if u say that it is for 16 bit, then how about 32 bit?

hmmm... wierd! why theres 555? the sum is 15 bit, not 16 bit, what the one bit used for?

Posted on 2002-10-27 20:08:49 by dion
The extra bit is discarded, but you dont need this info if you are not working with DDRAW.

I think the format for a 32-bit pixel is :


R=Red bits(AL)
G=Green Bits(AH)
B=Blue Bits

the remaining 8-bits are discarded. It used to be 24-bit. But as you know the x86 CPU's cant write 24-bits so they would have to write a WORD and then a BYTE. That would reduce performance so they expanded it to 32-bits.
Posted on 2002-10-27 20:11:16 by x86asm
thx again x86asm. i need it though. and one q again. i've heard about palette long time, but i dont know what it is. how this one come play into rgb color/screen?

Posted on 2002-10-27 20:18:46 by dion
A'ight sure I'm willing to help!
The palette is for 256 color modes, 16-bit, 24-bit and 32-bit display modes dont use palettes because the RGB values are read directly from the WORD/DWORD you wrote in that location.

For example the Palette is a 768 byte buffer holding RGB values for 256 indexes.
Index 0 - Byte 1:Red, Byte 2:Green, Byte 3:Blue
Index 255- Byte 1:Red, Byte 2:Green, Byte 3:Blue

Therefore you can represent one pixel with one byte now instead of 2 or 4 bytes. But you are limitied in the amount of colors you are able to place on the screen at once.

So lets say I want Index 144 to go into screen position 20,100:

You would find the offset into the backbuffer (or VRAM if your using it directly) and then write the BYTE value 144 into that position. If you need further clarification let me know :D
Posted on 2002-10-27 20:23:21 by x86asm
hmm... but i heard that palette related to hardware register stuff... ???

what is in my head was thinking that palette is like this. for example i've 16 color text. then in graph mode, it'll using palette to render the char with proper color, ie in 256 color mode.

do i am wrong here?

Posted on 2002-10-28 05:17:24 by dion
The palette is a hardware register but that is with VGA programming in MS-DOS, I'm assuming you using DirectDraw 256 color?

I think you got the idea of the palette, but just to reiterate:

Say I have Palette index 123 Set at red: 72 green: 21 and blue :89

Say I write the byte 123 to (100,34), Red: 72, green: 21 and blue: 89 will appear in that location.
Posted on 2002-10-28 07:25:17 by x86asm
thx a lot x86asm ;)

but, one thing was left. u dont tell me about the extra bit meant???

Posted on 2002-10-28 20:16:07 by dion
Is the RGB 555 mode, the extra bit is ignored. So that bit is a "garbage" bit. Its included so it is easier to work with. Its easier to work with 16-bits then to work with 15-bits ;)

No problem dion willing to help whenever I can ;)
Posted on 2002-10-28 20:18:05 by x86asm