Public Group

# opengl basics help (batch of unrelated Q's)

This topic is 4115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, so over the last 6 months I've been cramming programming books into my brain trying to learn as quickly as possible basics through 2d though 3d. I pickedup c++ and with exception to comprehensive knowledge of the STL I got that down pretty quickyly. Added on top of that SDL, Win32, and python pretty easily. So I started hastily into OpenGL thinking that I could breeze through that as easily as the others, and I was very wrong. I've been reading and playing with it for 2 weeks too stubborn to ask for help and now I am too lost not 2. 1. Matrics - I keep seeing everywhere that you need to have certain math skills to get anything done in 3D games, but as I read on I see that opengl provides glRotate(), glScale(), glTranslate(), glLoadIdentity(). With those it appears as though you don't need to know matrics to make 3d apps. I read about how matrics work and learned how to multiply them and add them and their dot/cross products and even though I can do the math, I still can't understand how/why matrics are used when API functions are provided for you. If someone could give me some examples of what I need that knowledge for I would be very appreciative. 2. Calculating Normals - I don't get it, a plane perpendicular to another given plane is that planes normal. Thats easy enough untill it comes time to do the math. Could someone point me in the direction of a tutorial that explains how to do this in plain english please? 3. Lighting - If I want to set different material properties for different objects in a scene how would that look in code, as it is ATM I set the material propertis at the same time I set a lights properties so I am making the assumption that the light will treat everything it touches as if it was that material. In order to give everything different material properties would it look like this in code?: createlight(); setmaterial(); drawobject(); setmaterial(); drawobject(); If this is the proper way to do things it means I probably need to start from square one on lighting. Thanks for reading this far. I'm very long-winded today...

##### Share on other sites
Hello,

1. OpenGL just provides you with a basic framework for working with matrices. To perform something else then just the transformation or rotation of objects, you'll have to design your own matrix class etc... You'll need this knowledge later on when you're implementing complex algorithms (e.g. shadowmapping techniques)

2. You calculate the normal of a surface by taking 3 points (ABC --> triangle) and take two sides as vectors: AB and AC for example. Then you take the cross product --> AB x AC (This is not the same as the dot product!).
The result will be your normal vector.

3. You mostly create your lights at the initialization of your game and specify the materials when you render the objects. I wouldn't bother learning the fixed function opengl functions anymore, but if I were you, I'd jump straight to shaders. That way you'll also have a better understanding of the underlying math then when you'd just use old OpenGL functions.

Jeroen

##### Share on other sites

I wrote some inlines to calculate plane normals based off that and they seem to work well. Thank you for that. Also about learning shaders before opengl lighting, how would I go about doing that? Any suggestions on where to start? Do I need to go pickup a GLSL book?

Reason I did'nt start with shaders was because I thought it would be way more involved than neccisary for someone who still has a very shaky understanding of OPENGL itself. Are GL lighting commands not being used anymore in professional games?

and how long do you think it would take to get a grip on GLSL?

##### Share on other sites
1. True. You can do basic graphics in OpenGL without ever having to manipulate a matrix directly.

2. A normal is a vector, not a plane. The cross-product of two vectors is a vector perpendicular to both, so it is common to take the cross product of two non-parallel vectors in a plane to get a vector that is perpedicular to the plane. However, if you have the plane's equation: Ax + By + Cz + D = 0, the normal is the vector [A, B, C].

3. Yes. That is the way to do it. In OpenGL, properties remain the same until changed.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×