tags:

views:

71

answers:

2

Is there some way to send a struct like:

struct COLOR {
    float r, g, b, a;
};

directly into glColor*() function as one parameter? Would make the code nicer.

I could make own function and send separetely each R,G,B,A values onto glColor4f() but that wouldnt be that nice. So im looking a way to send it the most optimal way as possible.

+4  A: 
COLOR color;
glColor4fv((GLfloat*) &color);

Update: I wouldn't recommend creating an inline function, however, you could use GLfloat in your struct to get the expression clearer. Use &color.r to avoid a compiler warning.

struct COLOR {
  GLfloat r,g,b,a;
};
COLOR color;
glColor4fv(&color.r);
Viktor Sehr
hmm, is it possible to make it any cleaner from that?
Newbie
actually, I think it's as clear as it can possibly be.
Viktor Sehr
GMan
should i make `inline void glColor(const COLOR
Newbie
updated the answer
Viktor Sehr
can you explain why inline function wouldnt be a good idea?
Newbie
Well, because immediate mode is really slow for anything serious. Vertex arrays via interleaved vertex buffers is the way to go. If you'll run into performance problems, it won't be because if the non-inlined functions (which is a compiler hint, by the way). For cleaniness you can use class that has operator const GLFloat* or just a union.
Madman
+3  A: 

The most optimal way of sending vertex data is Vertex Arrays, it will also make your code look nicer, you should take a look.

Matias Valdenegro
i dont always want to create vertex arrays for little things since the optimizing would be useless
Newbie