Macro error

Post questions regarding programming in C/C++ in Linux/Unix.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Macro error

Postby tomcant » Fri Oct 31, 2003 3:18 pm

Hi. I am currently reading a book on wingows game programming. It has proved to be extremely good so far. However, I am at a stage where I am learning about simple pixel plotting and it is all very simple, except for 32-bit pixel plotting. In the book it says to use this macro: #define _RGB32BIT(a, r, g, b) ( + ((g) << 8) + ((r) << 16) + ( << 24)), which I am. VC++ returns an error: error C2059: syntax error : '<<'. I can see where it's getting it from, but does this mean that the book is wrong?

Any help appreciated.

________
Tom
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Re

Postby Dudi Hatotah » Fri Oct 31, 2003 7:03 pm

First of all, use code tags when writing code. It will prevent the annoying 8) .

At any rate, I'm assuming the book ment:
Code: Select all
#define _RGB32BIT(a, r, g, b) ( + ((g) << 8) + ((r) << 16) + ( << 24))


The syntax is very wrong, and 'b' and 'a' are not used.
If the book really said so, then the book is wrong.

I would suggest doing as following:
(Assuming that the 4-byte structure is ARGB, which I'm really not sure of)
Code: Select all
#define _RGB32BIT(a, r, g, b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))
User avatar
Dudi Hatotah
 
Posts: 222
Joined: Fri Oct 03, 2003 4:17 pm
Location: Micronesia, the island of Yap

Postby tomcant » Mon Nov 03, 2003 5:47 am

The new macro works great, thx! :D

One more thing, could you possibly write me a macro for 16 BIT pixel plotting? Its just that the one supplied in the book makes the pixels slightily obscure to the eye.

Appreciated,

_______
Tom
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Re

Postby Dudi Hatotah » Fri Nov 07, 2003 4:13 pm

I'm glad I could help.
However, I really don't know how to write a "macro for 16 BIT pixel plotting". I don't even know WHAT IS 16 BIT pixel plotting.
Is it inserting a RGB value into a 16-bit integer?
If it is, then I guess it should look worse than the 32-bit version. It would be impossible for all the colors to be 8-bit, so the quality must be slightly worse.

At any rate, you can post the book's macro though and I'd try to figure it out and fix it if it is possible...
User avatar
Dudi Hatotah
 
Posts: 222
Joined: Fri Oct 03, 2003 4:17 pm
Location: Micronesia, the island of Yap

Postby MXP » Fri Nov 07, 2003 7:56 pm

If I recall correctly from my DirectDraw days 16 bits per pixel has two formats (without alpha): 555 and 565. The first being of the form XRRRGGGBBB and the second being of the form RRRGGGGBBB. Which of these are you using?
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby tomcant » Sat Nov 08, 2003 5:29 am

I am using non-alpha, 555 I do believe :)
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby jgbauman » Sat Nov 08, 2003 1:53 pm

Try
Code: Select all
typedef unsigned char u8_t;
typedef unsigned short u16_t;

inline u16_t rgb555(u8_t r, u8_t g, u8_t b) {
  return
    (u16_t(r & 0xf8) << 7) ||
    (u16_t(g & 0xf8) << 2) ||
    (u16_t(b & 0xf8) >> 3);
}
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am

Postby saramakos » Sun Nov 09, 2003 11:48 pm

I think I have read a very similar tutorial to the one you are using. Here are the defines that worked for me:

Code: Select all
#define RGB_16(r, g, b) (((r) << 11) | ((g) << 5) | (b))
#define RGB_32(r, g, b) (((r) << 16) | ((g) << 8) | (b))


Hope this helps somewhat
saramakos
 
Posts: 19
Joined: Thu Oct 16, 2003 7:37 am
Location: Western Australia

Postby tomcant » Mon Nov 10, 2003 8:28 am

Thank you, this helps greatly :)
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK


Return to Unix/Linux

Who is online

Users browsing this forum: No registered users and 2 guests