1 / 8

Open GL: Colors and Lighting

This tutorial covers the specification of colors and the setting of shading models using the Open.GL library. It also explains how to define and enable lights, and provides an example of lighting in a Visual C++ project.

bpalacios
Télécharger la présentation

Open GL: Colors and Lighting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  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

  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);

More Related