Tuesday, May 8, 2007

Best Match Balls Rugby

Previous Task 8 8. Textures and light sources

1 .- Investigate how to create and define a light source with OpenGL
- Creation of light
- How many lights can be set
- Parameters of the light source
- Types of lights - light color
- Enable, Disable lights.
- Light by default and default features

The lighting of a scene should follow the following: - Define normal vectors for all vertices of the objects - Place light sources - Choose the type of light - Choose the type of material of each object first executes the command glEnable (GL_LIGHTING), with estimates that are activated lighting necessary.
In standard definition, there are 8 light sources since LIGHT0 to LIGHT7. In OpenGL you can define three different forms of light, these are: ENVIRONMENT, ENVIRONMENT .- \u200b\u200bdiffuse and specular light comes from all directions in a distributed and is reflected equally by the polygons of the scene. .- Diffused light coming from a point source in particular, and touches the surface with an intensity that depends on which comes face to the light, this type of lighting is the one that best defines the contour of 3D objects is TRADING .- the light emitted from the object in a distributed in all directions. The light has the properties of color, position and direction. The color will the lights is determined by the three color components which handles OpenGL, red, green and blue.
The command used to specify all the properties of light is glLiht (), this command has three arguments to identify the light that is in use, ownership and value for the property. After defining the characteristics of the lights come on with the command glEnable (name of the light source to activate). There is also a function to turn off lighting glDisable and off is specified light. The characteristics of light by default to glLight are GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION, GL_SPOT_DIRECTION, GL_SPOT_EXPONENT, GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION. And GL_DIFFUSE GL_ESPECULAR used only with the first source of light. GL_AMBIENT: Sets the values \u200b\u200bof the ambient light. RGBA value, default value is (0.0,0.0,0.0,1.0) GL_DIFFUSE: Sets the values \u200b\u200bof scattered light. RGBA value. default value is (1.0,1.0,1.0,1.0) GL_SPECULAR: Sets the values \u200b\u200bof the specular light. RGBA value. The default value is (1.0,1.0,1.0,1.0) GL_POSITION: Position of light in coordinates {x, y, z, w}, its default value is (0.0,0.0,1.0,0.0) GL_SPOT_DIRECTION: Vector direction of light in coordinates {x, y, z}, the default is (0.0,0.0, -1.0) GL_SPOT_EXPONENT: Represents the concentration intensity of light. Scalar, default 0. GL_SPOT_CUTOFF: angle of the cone of light. Scalar value, default 180. GL_CONSTANT_ATTENUATION: Constant attenuation applied to the light based on distance. Scalar, default 1 GL_LINEAR_ATTENUATION: linear attenuation applied to the light based on distance. Scalar, default 0GL_QUADRATIC_ATTENUATION: quadratic attenuation applied to the light based on distance. Scalar, default 0

2 .- Investigate the difference between light and lighting (light / lighting)
- enabling / disabling the ilumnacion (How?)
- Why you need to enable and disable the light?
Light is a focal point which illuminates objects in a certain range, is a very defined and easy to find, however the lighting gives a light intensity in a wider range giving the impression that there a focal point where the light is emitted, the lighting is a type of light which has no direct impact on the objects. To enable and disable one of the lighting using the commands glEnable (nombre_iluminación) and glDisable (nombre_iluminación). The light source is created with glLightfv (GL_LIGHT0, GL_AMBIENT, ambient light);



3 .- Find out the definition of material properties to a surface
- Characteristics of materials (diffuse, specular, brightness, emissivity, etc)
- How are they defined?
- On which side (s) of a polygon apply

materials Depending on the material properties of light has a different effect on them These properties are defined glMaterial: void glMaterial (GLenum face, GLenum name, TYPOparam) face argument determines the face of the object in which we apply the property, has the following values: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK. The following indicates the property to be used for that face, it can be: GL_AMBIENT, GL_DIFFUSE, GL_AMBIENT_AND_DIFFUSE, GL_SPECULAR, GL_SHININESS, GL_EMISSION, GL_COLOR_INDEXES.
The last parameter specifies a pointer to the value or values \u200b\u200bthat the parameter name to take. · GL_AMBIENT .- \u200b\u200bmaterial ambient color, default values \u200b\u200bare (0.2, 0.2, 0.2, 1.0). · GL_DIFFUSE .- diffuse material color, default values \u200b\u200bare (0.8, 0.8, 0.8, 1.0). · GL_AMBIENT_AND_DIFFUSE .- ambient color and diffuse Materiel · GL_SHININESS .- specular exponent, its value is 0. · GL_EMISSION .- the emission color of the material, their default values \u200b\u200bare (0.0, 0.0, 0.0, 1.0). · GL_COLOR_INDEXES .- ambient color index diffuse and specular, default values \u200b\u200bare (0, 1, 1). It is important to note that developed the optical effect of light on the material depends greatly on the characteristics. They complement each other giving the desired effect.

4 .- Investigate the OpenGL texture mapping - Load bitmap definition - Transformations of the texture - Methods of Application of a texture (repeat, wrap, etc..) - Mapping the texture to a surface

Loading texture memory
The charging process the texture memory is not like OpenGL. You have to make an external function. There are some limitations imposed by the library. The size of all textures carguentienen to be powers of 2, such as 64x64, 128x64, etc. You have to keep in mind that if sedebe be drawing in RGB, not indexed color, or by loading textures in RGB format.
If you load a GIF image, which has indexed color, you have to schedule an extra function to convert to RGB .. Whatever the method, the final will have a pointer to a memory segment that contains the image: unsigned char * texture, is also important to keep the texture properties, specifically its size width and height and depth in bits. If you're working in RGB, the depth is 24 bits. The steps are: •

determined the size ·
estimate the memory that will be necessary ·
reserve memory ·
TGA file generation which comes in RGB format.

If not in this format should make the conversion. Once we have the image loaded into memory, the steps are: • Generating the reference for the texture. [GlGenTextures (1, & texture);] With the texture GLuint you reference "the texture." If you want more, you must create an array of GLuint. 1 means that only generate a texture. · Index that texture: [glBindTexture (GL_TEXTURE_2D, texture);].

This function says that now onwards, all operations involving the handling of textures were applied on this texture. In this case a 2D etextura · specify the filters to the texture: o glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST) \u200b\u200b· OpenGL can apply filters to the textures for better viewing. The first line specifies the filter to use if the texture look larger than it actually is (increase). The second specifies the filter for the texture look smaller than it actually is. Here we use a linear filter for the 1st and the second case discussed below.
Another value could have used the GL_NEAREST, a filter worst but faster · We texture mipmaps through for better performance, instead of filtering the dynamic texture, creating a mipmap, we create various textures different sizes (from the original to smallest). OpenGL, determined on the basis of distance that is the object with the texture, what mipmap to use.

Finally, one need only enable the use of textures:
glEnable (GL_TEXTURE_2D);
In init_gl function. TEXTURE TRANSFORMATION For TGA image generation in memory. The TGA must have the following characteristics:

• Be 24-bit
· Canal ALPHA. (32 bits) and uncompressed
• The size must be square (x = y) and 32x32 or 64x64 or 128x128 or 256x256

If the above is true, it returns a pointer to the image and size Image Texture Mapping FOR TEXTURE 1D • To set the texture: • void glTexImage1D (GLenum target, Glint level • Glint components, GLsizei width, Glint border, GLenum format, GLenum type, const GLvoid * pixels) • Where: Target is always worth GL_TEXTURE_1D-level indicates the level of detail (0 for individual textures)-components worth 1 (rate mode), 3 (RGB) or 4 (RGBA)-width indicates the width in pixel of the texture map (must be a power of 2)-edge indicates the number of pixels that form the border of the texture (0, 1 or 2)-format indicates the format of the pixels: GL_RED, GL_RGB, GL_LUMINANCE-type indicates the data type of pixels: GL_UNSIGNED_INT, GL_FLOAT-pixels is a pointer to the pixels of the texture TEXTURE MAPPING FOR 2D • To set the texture:
• void glTexImage2D (GLenum target, Glint level
• Glint components, GLsizei width, GLsizei height,
• Glint border, GLenum format, GLenum type,
• const GLvoid * pixels) • Where: Target is always worth GL_TEXTURE_2D-level indicates the level of detail (0 for individual textures)-components worth 1 (rate mode or luminance ), 3 (RGB) or 4 (RGBA)-width indicates the width in pixels of the texture map (must be a power of 2)-high indicator height in pixels of the texture map (must be a power of 2)-edge indicates the number of pixels that form the border of the texture (0, 1 or 2)-format indicates the format of the pixels: GL_RED, GL_RGB, GL_LUMINANCE -type indicates the data type of pixels: GL_UNSIGNED_INT, GL_FLOAT-pixels is a pointer to the pixels of the texture TEXTURE MAPPING IN AN AREA • By mapping the texture image onto a surface, the texels will not correspond exactly with pixels Magnification: If the surface is greater than the texture, each pixel will correspond to a small piece of texel minification: If the surface is less than the texture, each pixel will correspond to a set adjacent texels
mapping modes
• To set the mapping mode:
• glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, Glint value)
• where value can take 3 values: "GL_DECAL: the value texel is copied directly to the pixel-GL_MODULATE: texel value is scaled by the color of the object-GL_BLEND: texel value is used to interpolate between the object's color and a constant color to the texture defined by the function
• glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GLfloat color [4]) MODES OF APPLICATION OF TEXTURES GL TEXTURE WRAP S Sets wrap parameter for texture coordinate s GL_CLAMP, GL_CLAMP_TO_EDGE or GL_REPEAT. GL_CLAMP causes s coordinates are limited to the range [0.1] and is useful for preventing wrapping artifacts (compression?) When mapping a single image on an object.
GL_CLAMP_TO_EDGE causes s coordinates are limited to the range [1/2n, 1 - (1/2n) i], where n is the size of the texture in the direction of the boundary. GL_REPEAT causes the integer part of s are ignored, the GL uses only the fractional part, thereby creating a repeating pattern. The Border texture elements are accessed only if wrapping is set to GL_CLAMP. Initially set GL_TEXTURE_WRAP_S to GL_REPEAT. GL TEXTURE WRAP T Sets the wrap parameter for texture coordinate t GL_CLAMP, GL_CLAMP_TO_EDGE or GL_REPEAT (see above). Initially set to GL_REPEAT GL_TEXTURE_WRAP_T.

5 .- Write a program that defines two distinct features lights Draw a cube in which each side has different material properties applied to Draw a cube on each side which applies a different texture. One of them must be a photo of the student. Pressing the left mouse button on / off the first light Pressing the right mouse button on / off the second light when using the keyboard arrow keys change the position of the first light.

/ / Previous 8
/ / Cube textured Christian Duran Jorge Lara

# include / / glut library tool

# include # include "bitmap.h"

BITMAPINFO * texinfo / * Texture bitmap information * / GLubyte * TexBits
/ * Texture Bitmap pixel bits * / int r =-
45, rx = 30, rz = 0;
cubo_relleno
void (void) {


glRotatef (rx, 1.0,0.0,0.0 )
glRotatef (ry, 0.0,1.0,0.0);
/ / glRotatef (rz, 0.0,0.0,1.0);
glColor3f (1.0, 1.0, 1.0);
glTranslatef (0.0,0.0,0.0);

/ / activate texture mapping
glEnable(GL_TEXTURE_2D);
TexBits = LoadDIBitmap("glass.bmp", &TexInfo);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(1.0,1.0); glVertex3f(0.5,0.5,0.5);
glTexCoord2f(0.0,1.0); glVertex3f(-0.5,0.5,0.5);
glTexCoord2f(0.0,0.0); glVertex3f(-0.5,-0.5,0.5);
glTexCoord2f(1.0,0.0); glVertex3f(0.5,-0.5,0.5);
glEnd();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
TexBits = LoadDIBitmap("sirenoman2.bmp", &TexInfo);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(1.0,1.0); glVertex3f(-0.5,0.5,-0.5);
glTexCoord2f(0.0,1.0); glVertex3f( 0.5,0.5,-0.5);
glTexCoord2f(0.0,0.0); glVertex3f(0.5,-0.5,-0.5);
glTexCoord2f(1.0,0.0); glVertex3f(-0.5,-0.5,-0.5);
glEnd();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
TexBits = LoadDIBitmap("Logo_BCU.bmp", &TexInfo);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(1.0,1.0); glVertex3f(-0.5,0.5,0.5);
glTexCoord2f(0.0,1.0); glVertex3f(-0.5,0.5,-0.5);
glTexCoord2f(0.0,0.0); glVertex3f(-0.5,-0.5,-0.5);
glTexCoord2f(1.0,0.0); glVertex3f(-0.5,-0.5,0.5);
glEnd();
glDisable(GL_TEXTURE_2D);
//TexBits = LoadDIBitmap("mrbighead.bmp", &TexInfo);
//glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glEnable(GL_TEXTURE_2D);
TexBits = LoadDIBitmap("spirit.bmp", &TexInfo);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(0.0,1.0); glVertex3f(0.5,0.5,0.5);
glTexCoord2f(0.0,0.0); glVertex3f(0.5,-0.5,0.5);
glTexCoord2f(1.0,0.0); glVertex3f( 0.5,-0.5,-0.5);
glTexCoord2f(1.0,1.0); glVertex3f(0.5,0.5,-0.5);
glEnd();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
TexBits = LoadDIBitmap("Cascada1.bmp", &TexInfo);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(0.0,1.0); glVertex3f(-0.5,0.5,-0.5);
glTexCoord2f(0.0,0.0); glVertex3f(-0.5,0.5,0.5);
glTexCoord2f(1.0,0.0); glVertex3f(0.5,0.5,0.5);
glTexCoord2f(1.0,1.0); glVertex3f( 0.5,0.5,-0.5);
glEnd();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
TexBits = LoadDIBitmap("Kylie.bmp", &TexInfo);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexInfo->bmiHeader.biWidth,TexInfo->bmiHeader.biHeight, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TexBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glBegin (GL_QUADS)
glTexCoord2f (0.0,0.0) glVertex3f (0.5, -0.5, -0.5);
glTexCoord2f (1.0,0.0) glVertex3f (-0.5, -0.5, -0.5);
glTexCoord2f (1.0,1.0) glVertex3f (-0.5, -0.5,0.5);
glTexCoord2f (0.0,1.0) glVertex3f (0.5, -0.5,0.5);
glEnd ();
glDisable (GL_TEXTURE_2D);


} void display () {

glClearColor (0.0, 0.0, 0.0, 0.0), / / \u200b\u200bchoose the color of lines and solid
glLoadIdentity ();
glEnable (GL_DEPTH_TEST)
gluLookAt (0.0,0.0,3.0,0.0 , 0.0, 0.0, 0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT
//{
// glViewport (0, 0, (GLsizei) w, (GLsizei) h);
// glMatrixMode (GL_PROJECTION);
// glLoadIdentity ();
// glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
// glMatrixMode (GL_MODELVIEW);
//}


void arrow_keys ( int a_keys, int x, int y ) // Create Special Function (required for arrow keys)
{
switch ( a_keys ) {
case GLUT_KEY_UP: // When Up Arrow Is Pressed...
rx = rx - 2;
glutPostRedisplay();
/*rx=rx-2;
humanoide();*/
break;
case GLUT_KEY_DOWN: // When Down Arrow Is Pressed...
rx = rx + 2;
glutPostRedisplay();
//rx=rx+2;
//humanoide();
break;
case GLUT_KEY_LEFT: // When Down Arrow Is Pressed...
ry = ry - 2;
glutPostRedisplay();
//ry=ry-2;
//humanoide();
break;
case GLUT_KEY_RIGHT: // When Down Arrow Is Pressed...
ry = ry + 2;
glutPostRedisplay();
//ry=ry+2;
//display();
break;

default:
break;
}
}

/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}


int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_RGB
glutKeyboardFunc (keyboard);
glutSpecialFunc (arrow_keys)
glutMainLoop ();
return 0;}







Prior to the lights



# include # include static int


Spinx = 0 ;
spiny static int = 0;
static int p1 = 1;
static int p2 = 1;
static int ry, rx, rz;
/ * Initialize prpiedaes material, light source and z buffer * /
void init (void) {

glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH)
glEnable (GL_LIGHTING)
glEnable (GL_LIGHT0)
glEnable (GL_LIGHT1)
glEnable (GL_DEPTH_TEST) } void display (void) {
/ * Arrays for the light * /
GLfloat position [] = {0.0, 0.0, 2.5, 0.0};
GLfloat position2 [] = {0.0, 3.0, 3.0, 0.0}; light_ambient GLfloat [] = {0.4, 0.4, 0.4, 1.0};
light_diffuse GLfloat [] = {0.4, 0.4, 0.4, 1.0}; light_specular GLfloat [] = {0.8, 0.8, 0.8, 1.0};
/ * Arrays for material * / GLfloat
no_mat [] = {0.0,0.0,0.0,1.0};
mat_ambient GLfloat [] = {0.7,0.7,0.7,1.0} ;
mat_ambient_color GLfloat [] = {0.8,0.8,0.2,1.0};
GLfloat mat_diffuse[] = {0.1,0.5,0.8,1.0};
GLfloat mat_specular[] = {1.0,1.0,1.0,1.0};
GLfloat no_shininess[] = {0.0};
GLfloat low_shininess[] = {5.0};
GLfloat high_shininess[] = {100.0};
GLfloat mat_emission[] = {0.3,0.2,0.2,1.0};

GLfloat mat_amb_diff[] = {0.1, 0.5, 0.8, 1.0};
GLfloat mat_amb_diff2[] = {1.0, 0.1, 0.1, 1.0};
GLfloat mat_emission1[] = {0.3,0.8,0.2,1.0};



glClear (GL_COLOR_BUFFER_BIT 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

/ light * 0 * /
glPushMatrix ();
glRotated ((GLdouble) Spinx, 1.0, 0.0, 0.0);
glRotated ((GLdouble) spiny , 0.0, 1.0, 0.0);
glLightfv (GL_LIGHT0, GL_POSITION, position);


glTranslated (0.0, 0.0,2.5);
glDisable (GL_LIGHTING);
glColor3f (1.0, 1.0, 1.0);
glutWireCube (0.1 );
glEnable (GL_LIGHTING);
glPopMatrix ();
/ * end light 0 * /

/ * light * 1 /
glPushMatrix ();
glLightfv (GL_LIGHT1, GL_POSITION, position2);
glLightfv (GL_LIGHT1, GL_AMBIENT, light_ambient) / / GL_DIFFUSE
glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv (GL_LIGHT1, GL_SPECULAR, light_specular);

glTranslated (0.0,2.5,2.5);
glDisable (GL_LIGHTING) glColor3f
(1.0, 1.0, 1.0);
glutWireCube (0.1);
glEnable (GL_LIGHTING);
glPopMatrix ();
/ * 1 * fin light /

/ materials * cube * /
glPushMatrix ();
glScalef (2 , 2.2);
glRotatef (rx, 1.0,0.0,0.0);
glRotatef (ry, 0.0,1.0,0.0);
glRotatef (rz, 0.0,0.0,1.0);

glPushMatrix ();
/ * Only spread across * /
glMaterialfv (GL_FRONT, GL_AMBIENT, no_mat)
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse)
glMaterialfv (GL_FRONT, GL_SPECULAR, no_mat)
glMaterialfv (GL_FRONT, GL_SHININESS, no_shininess) ;
glMaterialfv (GL_FRONT, GL_EMISSION, no_mat)

glBegin (GL_QUADS)
glNormal3f (0.0,0.0,1.0);
glVertex3f (0.5,0.5,0.5) glVertex3f
(-0.5,0.5,0.5)
glVertex3f (-0.5, -0.5,0.5);
glVertex3f (0.5, -0.5,0.5);
glEnd ();
glPopMatrix ();

glPushMatrix ();
/ * diffuse and specular low brightness * /
glMaterialfv (GL_FRONT, GL_AMBIENT, no_mat)
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse)
glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular)
glMaterialfv (GL_FRONT, GL_SHININESS, low_shininess) ;
glMaterialfv (GL_FRONT, GL_EMISSION, no_mat)

glBegin (GL_QUADS)
glNormal3f (0.0,0.0, -1.0);
glVertex3f (-0.5,0.5, -0.5);
glVertex3f (0.5,0.5, -0.5 )
glVertex3f (0.5, -0.5, -0.5);
glVertex3f (-0.5, -0.5, -0.5);
glEnd ();
glPopMatrix ();

glPushMatrix ();
/ * diffuse, with high gloss specular * /
glMaterialfv (GL_FRONT, GL_AMBIENT, no_mat)
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse)
glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular)
glMaterialfv ( GL_FRONT, GL_SHININESS, high_shininess)
glMaterialfv (GL_FRONT, GL_EMISSION, no_mat)

glBegin (GL_QUADS)
glNormal3f (-1.0,0.0,0.0)
glVertex3f (-0.5,0.5,0.5)
glVertex3f (- 0.5,0.5, -0.5);
glVertex3f (-0.5, -0.5, -0.5);
glVertex3f (-0.5, -0.5,0.5);
glEnd ();
glPopMatrix ();

glPushMatrix ();
/ * ambient, diffuse and Broadcast * /
glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient)
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse)
glMaterialfv (GL_FRONT, GL_SPECULAR, no_mat) ;
glMaterialfv (GL_FRONT, GL_SHININESS, no_shininess)
glMaterialfv (GL_FRONT, GL_EMISSION, mat_emission)

glBegin (GL_QUADS)
glNormal3f (1.0,0.0,0.0);
glVertex3f (0.5,0.5,0.5) glVertex3f
(0.5, -0.5,0.5);
glVertex3f (0.5, -0.5, -0.5);
glVertex3f (0.5,0.5, -0.5);
glEnd ();
glPopMatrix ();

glPushMatrix ();
/ * ambient color, diffuse, reflection mirror and dim * /
glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient_color)
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse)
glMaterialfv ( GL_FRONT, GL_SPECULAR, mat_specular)
glMaterialfv (GL_FRONT, GL_SHININESS, low_shininess)
glMaterialfv (GL_FRONT, GL_EMISSION, no_mat)

glBegin (GL_QUADS)
glNormal3f (0.0,1.0,0.0);
glVertex3f (-0.5, 0.5, -0.5);
glVertex3f (-0.5,0.5,0.5)
glVertex3f (0.5,0.5,0.5);
glVertex3f (0.5,0.5, -0.5);
glEnd ();
glPopMatrix ();

glPushMatrix ();
/ * ambient color, diffuse, reflection mirror and high brightness * /
glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient_color )
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse)
glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular)
glMaterialfv (GL_FRONT, GL_SHININESS, high_shininess)
glMaterialfv (GL_FRONT, GL_EMISSION, no_mat)

glBegin (GL_QUADS)
glNormal3f (0.0, -1.0,0.0);
glVertex3f (0.5, -0.5, -0.5);
glVertex3f (-0.5, -0.5, -0.5);
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(0.5,-0.5,0.5);
glEnd();
glPopMatrix ();
glPopMatrix ();

/*fin cubo de materiales*/
glPopMatrix ();
glFlush ();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

/* ARGSUSED2 */
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN) {
if (p1 == 1)
{
glDisable(GL_LIGHT0);
p1 = 0;
glutPostRedisplay();
}
else
{
glEnable(GL_LIGHT0);
p1 = 1;
glutPostRedisplay();
}
}
break;
case GLUT_RIGHT_BUTTON:
if (state == GLUT_DOWN) {
if (p1 == 1)
{
glDisable(GL_LIGHT1);
p1 = 0;
glutPostRedisplay();
}
else
{
glEnable(GL_LIGHT1);
p1 = 1;
glutPostRedisplay();
}
}
break;
default:
break;
}
}
void special(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_RIGHT:
spiny = (spiny + 3) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_LEFT:
spiny = (spiny - 3) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_UP:
spinx = (spinx - 3) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN:
spinx = (spinx + 3) % 360;
glutPostRedisplay();
break;
default:
break;
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
case 'a':
ry = (ry + 3)%360;
glutPostRedisplay();
break;
case 's':
rx = (rx + 3)%360;
glutPostRedisplay();
break;
case 'd':
rz = (rz + 3)%360;
glutPostRedisplay();
break;
case 'p':
spinx = 0;
spiny = 0;
rx = 0;
rz = 0;
ry = 0;
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glutPostRedisplay();
break;

}


} int main (int argc, char ** argv) {

glutInit (& argc, argv);
glutInitDisplayMode (GLUT_SINGLE

is that which comes from a particular direction and is reflected in a
one direction, so that it produces intense glare in certain areas.
is the case, for example, of metal objects.

Every light bulb in the scene has three components: ambient light, diffuse light and specular light. The proportion of each component determines the type of light. For example, a laser is almost entirely composed of specular light.






The diffuse and environmental components are minimal and are due to the presence of dust in the atmosphere
. A focus, however, is an important part of ambient light and diffuse and a fraction
specular light.

When defining a light bulb is not only necessary to define the three components of the light, but also the color of each component. Browse Source





www.cs.buap.mx/ ~ asanchez/iluminacion2.pdf





0 comments:

Post a Comment