Typically set viewport set projection matrix etc

This preview shows page 20 - 33 out of 41 pages.

// typically set viewport, //set projection matrix, etc. }
Image of page 20

Subscribe to view the full document.

Example Code Using OpenGL Input (4) void mouse (int button, int state, int x, int y) { switch (button) case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) // do whatever case GLUT_RIGHT_BUTTON: // etc., etc. }
Image of page 21
Example Code Using OpenGL Input (5) void motion (int x, int y) { // do whatever is appropriate, // e.g., move object to point (x, y) }
Image of page 22

Subscribe to view the full document.

Example Code Using OpenGL Input (6) void keyboard(unsigned char key, int x, int y) { switch (key) { case ‘s’: // do whatever break; case ‘S’; // do whatever here also break; . . . } }
Image of page 23
Creating a Normal Vector glNormal3{dfi}(TYPE nx, TYPE ny, TYPE nz ) TYPE is GLdouble, GLfloat, or GLint (nx, ny, nz) are the coordinates of the normal vector If GL_RESCALE_NORMAL is enabled, normals do not have to be unit size – the system will normalize them for you Normalization is disabled by default Can enable by calling glEnable() with either GL_NORMALIZE or GL_RESCALE_NORMAL
Image of page 24

Subscribe to view the full document.

Lighting Enable lighting. Set up one of the lights, Color of ambient light, Color of diffuse light, Etc, then Light position. turn it on.
Image of page 25
Lighting To enable lighting in the scene: glEnable(GL_LIGHTING ) This enables lighting in the scene, but does not enable individual lights To enable each light source: glEnable(GL_LIGHT i ) where 0 ≤ i < GL_MAX_LIGHTS
Image of page 26

Subscribe to view the full document.

Lighting To set the value of a light source parameter: glLight{if}v(GLenum light, GLenum pname, TYPE params ) light is the light number of the form GL_LIGHT i , where 0 ≤ i < GL_MAX_LIGHTS pname specifies the light source parameter to set, and is one of GL_AMBIENT (RGBA) GL_DIFFUSE (RGBA) GL_SPECULAR (RGBA) GL_POSITION (x, y, z, w) – if w is 0, it is a directional light source GL_SPOT_DIRECTION (x, y, z) params is a pointer to an array that contains the data
Image of page 27
Lighting To set the ambient lighting in the scene: glLightModel{if}{v}( GLenum GL_LIGHT_MODEL_AMBIENT, TYPE params ) params contains a pointer to 4 int or float values that specify the ambient RGBA intensity for the entire scene.
Image of page 28

Subscribe to view the full document.

Shading To set the shading type for the scene: glShadeModel (GLenum mode ) mode specifies the type of shading to be done, and is either GL_FLAT GL_SMOOTH (Gouraud shading) The default is GL_SMOOTH
Image of page 29
Setting Material Properties To set the material properties for the current material: glMaterial{fi}{v}(GLenum face, GLenum pname, TYPE params ) face specifies which face the properties should be applied to and is: GL_FRONT GL_BACK GL_FRONT_AND_BACK GL_BACK is used for shading back-facing polygons when two-sided lighting is enabled
Image of page 30

Subscribe to view the full document.

Setting Material Properties (2) pname specifies which parameter is to be set and is: GL_AMBIENT RGBA that specifies the ambient reflectance of the material GL_DIFFUSE RGBA that specifies the diffuse reflectance of the material GL_SPECULAR RGBA that specifies the specular reflectance of the material GL_EMISSION RGBA that specifies the emitted light intensity of the material GL_SHININESS int or float that specifies the specular exponent of the material
Image of page 31
Texture Mapping
Image of page 32

Subscribe to view the full document.

Image of page 33
You've reached the end of this preview.
  • Spring '08
  • Jones,M
  • Light, Pointer, Diffuse reflection, current matrix

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern