A few basic OpenGL function questions

Started by
3 comments, last by sinful 23 years, 2 months ago
Ok I am currently in the process of learning OpenGL, and I have a few questions about what certain things mean or what their purpose is, to better understand what is going on.. The first is, in Nehe''s tutorials, I see alot of functions declared using GLvoid. Is this necessary, or can a simple int/void be used there? gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); Can you explain what each of the parameters in this function do? What is the range of colors in OpenGL? I don''t know if this is a stupid question but, OK, I''ve read that 0.0f is lowest value of RGB color, and 0.1f is highest value of RGB color..but lets say I wanted the color (in relation to RGB) Red = 120, Green = 40, Blue = 255? How would I translate that to all this x.xf business? I''m sure there are a few other questions I have but I won''t post them until later
Advertisement
The Answer to the first question is, GLvoid is just a void.
But it is good practice to use GL typecasting.

The answer to the second question is, the color is just calculated by color/255.

so if red == 210, then you would use,
red = 210/255;

but that is messy, you can use normal color values (0-255) if u use glColor3ub(red,green,blue);

e.g.
glColor3ub(255,0,0);

I hope this helps
Okay, lets see now.... hmmm

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

This sets the perspecive so that it has an angle of 45 degrees, fills the windows width and height ( just to fill it ), I'm not 100% sure, but I think that the 0.1f is the minimum distance away from you that it draws things, ( so anything closer that 0.1f wont be drawn ). The 100.0f is the maximum distance away from you that things will be drawn. (Everything further than 100.0f will not be drawn).




The color thingy....
1.0f is the maximum for each, and 0.0f is the minimum for each. However, this is ONLY if you are using floating point colours ( using color3f ). If you are using Unsigned bytes for the colour, then you use color3ub, and set RGB values from 0,0,0 to 255,255,255.

( where 255 is maximum and 0 is minimum )


I hope this has helped.

~Cobra~



Edit : HyprLogik.. thanx for pointing that out.. I was kinda rushing, and I guess I had 256 colours ( as a desktop setting ) in my head! hehehe. I've made the alterations to fix that.. well spotted.

Edited by - Cobra on January 27, 2001 8:21:35 PM

Edited by - Cobra on January 27, 2001 8:22:23 PM
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"
Actually, Cobra, the max is 255, not 256

|-|A[k3R$Z R \/\/|-|AT |V|Ak3 t|-|3 \/\/0R|_D g0 R0|_||\|D!!
|-|A[k3R$Z R //|-|AT |V|Ak3 t|-|3 //0R|_D g0 R0|_|||D!!
The GLvoid and GLint stuff is not compleatly uesless it is there
so that int sive od the a int, float, ect is the same nomatter what platform the code is complled for If you know that you are never going to port your code to somthing else the you can just ues int and void but it never hurts to ues the GL data types and it is good habit to get into.

This topic is closed to new replies.

Advertisement