Open GL Super Bible:Color and Shading
To access the contents, click the chapter and section titles.
Open GL Super Bible
(Publisher: Macmillan Computer Publishing)
Author(s): Waite group Press
ISBN: 1571690735
Publication Date: 08/01/96
Previous
Table of Contents
Next
Summary
This chapter covers one of the most important features supported by a graphics package: color. You have seen how to specify a color in terms of its RGB components, and how these components relate to one another in the RGB color cube. Your understanding of glColor has been expanded to include the coloring of vertices, and you have seen how this affects shading. We explained OpenGLÅ‚s selection of colors in 4-, 8-, 16-, and 24-bit Windows color modes. We demonstrated the building of a 3-3-2 palette for use by OpenGL in 8-bit color modes. Finally, we took a brief look at color index mode and its utilization to gain better palette control in 8-bit color modes.
Good use of color and shading is a prerequisite for good 3D graphics. The upcoming chapter explains how OpenGL uses shading to produce lighting effects. Youłll learn how to specify material colors and lighting conditions and allow OpenGL to select the drawing colors.
Reference Section
glClearIndex
Purpose
Sets the clear value for the color index buffers.
Include File
<gl.h>
Syntax
void glClearIndex(GLfloat color);
Description
This function specifies the color index to use in color index mode to clear the color buffers. This has the net effect of clearing the window and setting the background color to the color in the index specified by the color parameter.
Parameters
color
GLfloat: The value to use when the color index buffers are cleared with glClear. The default is 0.
Returns
None.
Example
See the sample program INDEX in this chapter.
See Also
glClear, glGet
glColor
Purpose
Sets the current color when in RGBA color mode.
Include File
<gl.h>
Variations
void glColor3b(GLbyte red,GLbyte green, GLbyte blue);
void glColor3d(GLdouble red, GLdouble green, GLdouble blue);
void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
void glColor3i(GLint red, GLint green, GLint blue);
void glColor3s(GLshort red, GLshort green, GLshort blue);
void glColor3ub(GLubyte red, GLubyte green, GLubyte blue);
void glColor3ui(GLuint red, GLuint green, GLuint blue);
void glColor3us(GLushort red, GLushort green, GLushort blue);
void glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha);
void glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha);
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
void glColor4i(GLint red, GLint green, GLint blue, GLint alpha);
void glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha);
void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
void glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha);
void glColor4us(GLushort red, GLushort green, GLushort blue, GLushort alpha);
void glColor3bv(const GLbyte *v);
void glColor3dv(const GLdouble *v);
void glColor3fv(const GLfloat *v);
void glColor3iv(const GLint *v);
void glColor3sv(const GLshort *v);
void glColor3ubv(const GLubyte *v);
void glColor3uiv(const GLuint *v);
void glColor3usv(const GLushort *v);
void glColor4bv(const GLbyte *v);
void glColor4dv(const GLdouble *v);
void glColor4fv(const GLfloat *v);
void glColor4iv(const GLint *v);
void glColor4sv(const GLshort *v);
void glColor4ubv(const GLubyte *v);
void glColor4uiv(const GLuint *v);
void glColor4usv(const GLushort *v);
Description
This function sets the current color by
specifying separate red, green, and blue components of the color. Some
functions also accept an alpha component. Each component represents the
range of intensity from zero (0.0) to full intensity (1.0).
Functions with the v suffix take a
pointer to an array that specifies the components. Each element in the
array must be of the same type. When the alpha component is not
specified, it is implicitly set to 1.0. When non-floating point types
are specified, the range from zero to the largest value represented by
that type is mapped to the floating point range 0.0 to 1.0.
Parameters
red
Specifies the red component of the color.
green
Specifies the green component of the color.
blue
Specifies the blue component of the color.
alpha
Specifies the alpha component of the color. Used only in variations that take four arguments.
*v
A pointer to an array of red, green, blue, and possibly alpha values.
Returns
None.
Example
The following code from the CCUBE example in this chapter sets one of the corners of the color cube to white.
// Front face
glBegin(GL_POLYGON);
// White
glColor3ub((GLubyte) 255, (GLubyte)255, (GLubyte)255);
glVertex3f(50.0f,50.0f,50.0f);
See Also
glIndex
glColorMask
Purpose
Enables or disables modification of color components in the color buffers.
Include File
<gl.h>
Syntax
void glColorMask(GLboolean bRed, GLboolean bGreen, GLboolean bBlue, GLboolean bAlpha);
Description
This function allows changes to individual
color components in the color buffer to be disabled or enabled (all are
enabled by default). For example, setting the bAlpha argument to
GL_FALSE disallows changes to the alpha color component.
Parameters
bRed
GLboolean: Specifies whether the red component may be modified.
bGreen
GLboolean: Specifies whether the green component may be modified.
bBlue
GLboolean: Specifies whether the blue component may be modified.
bAlpha
GLboolean: Specifies whether the alpha component may be modified.
Returns
None.
Example
See the sample program MASK on the CD for this chapter.
See Also
glColor, glIndex, glIndexMask, glDepthMask,
glStencilMask
Previous
Table of Contents
Next
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
254 257254 257254 255demo cgi 254257 259254 25626 (257)257 313 (2)254 (2)więcej podobnych podstron