Skip to main content
gamedev.net
🔒 Locked

Function

Started by Ethan 8 replies 200+ views
Original Post
Ethan
Ethan
I use glColor3f but there i must give 3 parameter for red, green, blue. Exist an funtion where i only must give one parameter? thx
MENTAL
MENTAL
no
MENTAL
MENTAL
wait, did you mean a function where you only specify a single color, or a single variable that contains all 3 colors? if it''s the latter, shove an "v" on the end of the function name and pass the address of the first element in the group. example:

struct COLOR
{
float R, G, B;
};

COLOR MyColor;

glColor3f (&MyColor.R);

this applies to most polygon functions - tex co-ords, colors, normals, vertex pos, etc.

MENTAL
Ethan
Ethan
I mean that the color is only in a single variable,
or must i split the color?

Dactylos
Dactylos
You can write for example

  
unsigned long colour = 0x00ffffff // white


glColor3ubv(&colour); // pass the color as a vector of 3 unsigned bytes

Neophyte
Neophyte
I find that the easiest way to do this is to implement a color-struct with union. Such as:
  
struct Color {
union {
float f[3];
float r, g, b;
};
};

Color c;
c.r = 1.0f;
c.g = 0.0f;
c.b = 0.5f;

glColor3fv (c.f);


-Neophyte
Neophyte
Neophyte
> Neophyte, that won't work. You should have done this:

Oops.

-Neophyte

EDIT: Amazing that it's possible to make a spelling-mistake in that short a message...

Edited by - Neophyte on October 16, 2001 1:10:04 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.