Sponsored Links
This presentation is the property of its rightful owner.
1 / 8

Overview PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

Overview. Today: - Make sure everyone is set up with an O penGL environment - OpenGL basics: shapes, lighting, textures - P ushing/ Popping modelview stacks Proble m Set 1, due April 13th : 1. create a Camera class which allows users to navigate 3D space interactively

Download Presentation


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript




- Make sure everyone is set up with an OpenGL environment

- OpenGL basics: shapes, lighting, textures

- Pushing/Poppingmodelview stacks

Problem Set 1, due April 13th:

1. create a Camera class which allows users to navigate 3D space interactively

2. create a scene graph data structure

3a. create an interactive visual space that emulates existing work

3b. create an animated version of the above

Vertex and fragment operations

Vertex and Fragment Operations

Last week we talked about how a vertex is transformed from 3D space to a 2D projection onto a display by multiplying it through the graphics pipeline.

The pipeline is split into two operations: vertex operations and pixel (or fragment) operations.

Vertex operations control the position of geometry.

Fragment operations control the way the geometry looks (ie, lighting, blending, texturing), ultimately specifying a color for each pixel.

OpenGL gives you limited control over how your GPU executes these operations. GLSL shader programs give you more control.

Opengl environments

OpenGL environments

Most OpenGL environments simplify the management of the OpenGL context within a windowed application.

init (happens once)

set up camera lens / projection matrix

initialize lighting

load textures from disk

reshape (happens when screen is resized)

re-set projection matrix based on new size of screen

display (happens 60 times per second)

position camera

position drawing cursor coordinates

draw stuff

listen for mouse, keyboard, etc

Init projection matrix

init projection matrix

Define camera attributes and set Projection matrix

- glViewport, usually just the screen bounds

- glPerspective, usually near,far = .1, 100; fovy=45, aspect ratio = w/h

or use glFrustum

or create an array of floats and load it using glLoadMatrix

Init lighting

init lighting

glLightfv defines one of the characteristics for one of the lights

ambient = general background light

diffuse = light from a source that scatters uniformly when it bounces off an object

specular = light from a source that scatters in a particular direction


//enable lighting


// define a light


glLightfv(GL_LIGHT1, GL_AMBIENT,ambient, 0);

glLightfv(GL_LIGHT1, GL_DIFFUSE,diffuse, 0);

glLightfv(GL_LIGHT1, GL_POSITION,lightPosition, 0);

Load textures

load textures

Loading textures by hand is kind of a pain. OpenGL environments generally provide helper methods.

a texture is just an array of data, can be used for images, depth maps, luminance maps, etc

enable textures and generate texture ids

bind a specific texture id

load image from disk

put it into a texture object – usually 2D, RGBA format

set texture attributes (eg, linear filtering, clamping)

textures are copied directly onto the video card, so drawing them is “hardware-accelerated”


glGenTextures(3, int[], 0); //bind 3 textures to IDs

glBindTexture(GL_TEXTURE_2D, textures[0]);


glTexImage2D(textures[0], 0, GL_RGBA, imgWidth, imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgPixelData);

Drawing textures

drawing textures

To draw a texture you “bind” it to your geometry and then position it in relation to vertices.

Texture coordinates are always normalized to between 0 and 1.

glBindTexture(GL_TEXTURE_2D, textureID);


glTexCoord2f(0.0f, 0.0f);glVertex3f(-1.0f, -1.0f, 1.0f);

glTexCoord2f(1.0f, 0.0f);glVertex3f(1.0f, -1.0f, 1.0f);

glTexCoord2f(1.0f, 1.0f);glVertex3f(1.0f, 1.0f, 1.0f);

glTexCoord2f(0.0f, 1.0f);glVertex3f(-1.0f, 1.0f, 1.0f);


Pushing and popping the modelview

Pushing and Popping the Modelview

These are convenience methods to let you save state during drawing.

- set up camera view by moving the cursor 10 units away

glTranslate3f(0f, 0f, -10f)

  • store this view


  • do something which changes the modelview matrix

    glRotatef(45f, 0f, 1f, 0f); glScale3f(2f, .5f, 0f); glTranslate3f(1f, -2f, 3f);

    (draw stuff...)

  • return to nice simple view


    You can nest a large number of these modelviews on the stack with no loss of performance. Used in scene graphs.

  • Login