Download presentation
Presentation is loading. Please wait.
1
Open GL: Colors and Lighting
Geb Thomas
2
Specifying Colors void glColor3{b s i f d ub us ui} (TYPEr, TYPEg, TYPEb); void glColor4{b s i f d ub us ui} (TYPEr, TYPEg, TYPEb, TYPEa); void glColor3{b s i f d ub us ui}v (const TYPE*v); void glColor4{b s i f d ub us ui}v (const TYPE*v); Sets the current red, green, blue, and alpha values. This command can have up to three suffixes, which differentiate variations of the parameters accepted. The first suffix is either 3 or 4, to indicate whether you supply an alpha value in addition to the red, green, and blue values. If you don't supply an alpha value, it's automatically set to 1.0. The second suffix indicates the data type for parameters: byte, short, integer, float, double, unsigned byte, unsigned short, or unsigned integer. The third suffix is an optional v, which indicates that the argument is a pointer to an array of values of the given data type.
3
Color Specification Codes
Suffix Data Type Minimum Value Min Value Maps to Maximum Value Max Value Maps to b 1-byte integer -128 -1.0 127 1.0 s 2-byte integer -32,768 32,767 i 4-byte integer -2,147,483,648 2,147,483,647 ub unsigned 1-byte integer 0.0 255 us unsigned 2-byte integer 65,535 ui unsigned 4-byte integer 4,294,967,295
4
Shading Models void glShadeModel (GLenum mode);
Sets the shading model. The mode parameter can be either GL_SMOOTH (the default) or GL_FLAT. Here is a Visual C++ Project example
5
Lighting Define normals Create, position and enable lights
Select a lighting model Define the material properties of objects in the scene
6
Defining Lights void glLight{if}(GLenum light, GLenum pname, TYPEparam); void glLight{if}v(GLenum light, GLenum pname, TYPE *param); Creates the light specified by light, which can be GL_LIGHT0, GL_LIGHT1, ... , or GL_LIGHT7. The characteristic of the light being set is defined by pname, which specifies a named parameter, param indicates the values to which the pname characteristic is set; it's a pointer to a group of values if the vector version is used, or the value itself if the nonvector version is used. The nonvector version can be used to set only single-valued light characteristics.
7
Selected Light Parameters
Parameter Name Default Value Meaning GL_AMBIENT (0.0, 0.0, 0.0, 1.0) ambient RGBA intensity of light GL_DIFFUSE (1.0, 1.0, 1.0, 1.0) diffuse RGBA intensity of light GL_SPECULAR specular RGBA intensity of light GL_POSITION (0.0, 0.0, 1.0, 0.0) (x, y, z, w) position of light GL_SPOT_DIRECTION (0.0, 0.0, -1.0) (x, y, z) direction of spotlight GL_SPOT_EXPONENT 0.0 spotlight exponent
8
Multiple Lights GLfloat light1_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat light1_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light1_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light1_position[] = { -2.0, 2.0, 1.0, 1.0 }; GLfloat spot_direction[] = { -1.0, -1.0, 0.0 }; glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular); glLightfv(GL_LIGHT1, GL_POSITION, light1_position); glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5); glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2); glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0); glEnable(GL_LIGHT1);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.