Opengl Notes

  • Uploaded by: hemsr
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Opengl Notes as PDF for free.

More details

  • Words: 1,118
  • Pages: 26
“Computer Science is no

more about computers than astronomy is about telescopes.”

Professor Edsger Dijkstra

OpenGL Notes & Guides

Required files for Windows •

In the System Directory – glu32.dll – opengl32.dll – glut32.dll



In the C++ Include Directory – – – –



gl\gl.h l\glu.h gl\glaux.h (probably won't need it) gl\glut.h (includes both gl.h and glu.h)

In the C++ Library Directory – – – –

gl\glu32.lib l\opengl32.lib gl\glaux.lib (probably won't need it) gl\glut32.lib

OpenGL Libraries OpenGL Application GLU

GL

GLUT

Frame Buffer Display

GLX

Event Loop •

OpenGL programs often run in an event loop: – Start the program – Run some initialization code – Run an infinite loop and wait for events such as • • • •

Key press Mouse move, click Reshape window Expose event

OpenGL Command Syntax (1) • OpenGL commands start with “gl” • OpenGL constants start with “GL_” • Some commands end in a number and one, two or three letters at the end (indicating number and type of arguments) • A Number indicates number of arguments • Characters indicate type of argument

OpenGL Command Syntax (2) – – – – – – – –

`f' float `d' double float `s' signed short integer `i' signed integer `b' character `ub' unsigned character `us' unsigned short integer `ui' unsigned integer

OpenGL Command Syntax (3) • “v” at the end of the name indicates a vector format. Examples: glColor*() • glColor3b, glColor3d, glColor3f, glColor3i, glColor3s, glColor3ub, glColor3ui, glColor3us, glColor4b, glColor4d, glColor4f, glColor4i, glColor4s, glColor4ub, glColor4ui, glColor4us, glColor3bv, glColor3dv, glColor3fv, glColor3iv, glColor3sv, glColor3ubv, glColor3uiv, glColor3usv, glColor4bv, glColor4dv, glColor4fv, glColor4iv, glColor4sv, glColor4ubv, glColor4uiv, glColor4usv

OpenGL Primitives • • • • • • • • • •

GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP GL_POLYGON

Scene Graph Ground T1 Body T2 Head

T3 Left Arm

T4 Right Arm

OpenGL Program Organization •

main: – – – –

find GL visual and create window initialize GL states (e.g. viewing, color, lighting) initialize display lists loop • • • • • •



check for events (and process them) if window event (window moved, exposed, etc.) modify viewport, if needed redraw else if mouse or keyboard do something, e.g., change states and redraw

redraw: – – – – – – – – –

clear screen (to background color) change state(s), if needed render some graphics change more states render some more graphics . . . swap buffers

glMatrixMode •

glMatrixMode –



C Specification –



void glMatrixMode( GLenum mode )

Parameters –



- specify which matrix is the current matrix

mode Specifies which matrix stack is the target for subsequent matrix operations. Three values are accepted: GL_MODELVIEW, GL_PROJECTION, and GL_TEXTURE. The default value is GL_MODELVIEW.

Description –

glMatrixMode sets the current matrix mode. mode can assume one of three values: GL_MODELVIEW Applies subsequent matrix operations to the modelview matrix stack. GL_PROJECTION Applies subsequent matrix operations to the projection matrix stack.

Viewing Pipeline

General 3D Viewing Pipeline

• • • • • •

Modeling coordinates (MC) World coordinates (WC) Viewing coordinates (VC) Projection coordinates (PC) Normalized coordinates (NC) Device coordinates (DC)

Virtual Camera Model • Viewing Transformation – The camera position and orientation is determined

• Projection Transformation – The selected view of a 3D scene is projected onto a view plane

Viewing-Coordinate Parameters • Look-at point Pref

N = P0 − Pref

• View-up vector V – N and V are specified in the world coordinates

Viewing-Coordinate Reference Frame • The camera orientation is determined by the uvn reference frame

N n= = (nx , n y , nz ) N V ×n u= = (u x , u y , u z ) V v = n × u = (v x , v y , v z )

u v

n

World-to-Viewing Transformation u x v R= x nx  0

M wc ,vc

uy vy ny 0

uz vz nz 0

0 0 0  1

u x v = R ⋅T =  x n x  0

1 0 T= 0  0 uy

uz

vy ny 0

vz nz 0

0 1 0 0

0 − x0  0 − y0  1 − z0   0 1 

− u ⋅ P0  − v ⋅ P0  − n ⋅ P0   1 

Perspective-Projection View Volume • Viewing frustum – Why do we need near and far clipping plane ?

Normalizing Transformation • Transform an arbitrary perspective-projection view volume into the canonical view volume • Step 1: from frustum to parallelepiped

Normalizing Transformation • Transform an arbitrary perspective-projection view volume into the canonical view volume • Step 2: from parallelepiped to normalized

Orthographic Transformation • • • •

Preserves relative dimension The center of projection at infinity The direction of projection is parallel to a principle axis Architectural and engineering drawings

OpenGL 3D Viewing Functions •

Viewing-transformation function – glMatrixMode(GL_MODELVIEW); – gluLookAt(x0,y0,z0,xref,yref,zref,vx,vy,vz); – Default: gluLookAt(0,0,0, 0,0,-1, 0,1,0);



OpenGL orthogonal-projection function – – – –

glMatrixMode(GL_PROJECTION); gluOrtho(xwmin,xwmax, ywmin,ywmax, dnear,dfar); Default: gluOrtho(-1,1, -1,1, -1,1); Note that • dnear and dfar must be assigned positive values • znear=-dnear and zfar=-dfar • The near clipping plane is the view plane

glViewport •

C Specification – void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)



Parameters – x, y: Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0, 0). – width, height: Specify the width and height of the viewport. When a GL context is first attached to a surface (e.g. window), width and height are set to the dimensions of that surface.



glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd, ynd) be normalized device coordinates. Then the window coordinates (xw, yw) are computed as follows:

xw = ( xnd + 1) *

width +x 2

y w = ( ynd + 1) *

height +y 2

OpenGL 3D Viewing Functions •

OpenGL perspective-projection function – – – –

The projection reference point is the viewing-coordinate origin The near clipping plane is the view plane Symmetric: gluPerspective(theta,aspect,dnear,dfar) General: glFrustum(xwmin,xwmax,ywmin,ywmax,dnear,dfar)

glFrustum •

glFrustum – glFrustum - multiply the current matrix by a perspective matrix C Specification – void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far )

 2 * near  right − left   0   0   0 

0 2 * near right − left 0 0

right + left right − left top + bottom top − bottom far + near far − near −1

    0  2 * far * near   far − near  0  0

Related Documents

Opengl Notes
May 2020 1
Ddth-opengl
November 2019 3
Opengl Objects
June 2020 2

More Documents from "api-26188019"

Opengl Notes
May 2020 1