






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







The following sample code will set up a simplelight:
float
amb[4]
=
{
0.3,
0.3,
0.3,
};
float
dif[4]
=
{
0.5,
0.5,
0.5,
};
float
pos[4]
=
{
0,
0,
-10,
0
};
glLightfv(GL_LIGHT0,
GL_AMBIENT,
amb);
glLightfv(GL_LIGHT0,
GL_DIFFUSE,
dif);
glLightfv(GL_LIGHT0,
GL_POSITION,
pos);
glEnable(GL_LIGHT0);glEnable(GL_LIGHTING);glEnable(GL_COLOR_MATERIAL);
^
GL_LIGHT0 is the first possible light in GL.
When using specular lighting inOpenGL, the default ‘shininess’setting used in the lightingcalculations is set to themaximum possible shininess:
^
To see a clear highlight, you’llneed to turn down the shine:^ glMaterialf(GL_FRONT_AND_BACK,
GL_SHININESS,10);
//
possible
range:
0--128.
There are a couple of different ways to shadeyour model:
Flat Shading
Smooth Shading
In
flat shading
, the renderer uses the normal of
the polygon to shade the entire polygonuniformly, from corner to corner.
P
P
P
P
P
To specify the shading model in OpenGL: ^
Smooth shading:^
glShadeModel(GL_SMOOTH); ^
Flat shading:^
glShadeModel(GL_FLAT); ^
Note that solid wireframe models look best in flatshading, but most curving surfaces look best insmooth shading.
Another use of normals is
backface culling
, an
optimisation to speed up rendering. ^
If you have a solid object, opaque, then you can’tsee the back of it because the front is in the way. ^
So you can optimize rendering and never evenprocess any polygon on the back of the object. ^
How to tell if it’s on the back? Well, one sure-firetrick is to see if the polygon
faces away from the
camera
. If we see the poly’s back then there
must be some other poly between that poly andour camera.
By default, backface culling is enabled inOpenGL. ^
To enable backface culling:^
glEnable(GL_CULL_FACE); ^
To disable backface culling:^
glDisable(GL_CULL_FACE); ^
To choose between culling fronts or backs:^
glCullFace(GL_FRONT); glCullFace(GL_BACK);
// (Default)