Jorg's Graphics Lecture Notes: Basic OpenGL Programming, Study notes of Computer Science

An introduction to opengl programming, covering global state, primitives, attributes, matrix stacks, events, and various drawing modes. Opengl uses a global state organized as a tree-like stack, with attributes and primitives defined through various functions. The document also discusses the use of glut for interaction with x windows and input devices.

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-468
koofers-user-468 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Jorg’s Graphics Lecture Notes 2. Basic openGL Programming 1
2. Basic openGL Programming
Global state
OpenGL is not object oriented!
It has a global state organized as a tree-like stack via ‘push’ and ‘pop’ separators.
image = GlobState(attributes; objects)
Primitives: (what, shape node) points, line segments, polygons, pixels,
curves
Attributes system state: (how, property) accum buffer, color, current,
depth buffer, enable, eval, fog, hint, lighting, line, list, pixel mode, point,
polygon, polygon stipple, scissor, stencil buffer, texture, transform, view-
port.
2 matrix stacks:
glMatrixMode(GL PROJECTION ) Viewing: projection, clipping
glMatrixMode(GL MODELVIEW ) Transformation: rotate, scale, trans-
late
events (input, error handling, network connection, etc.)
Example:
glClear()
glColor3f()
glBegin (GL_POINTS)
glVertex2fv()
glEnd (GL_POINTS)
glFlush()
OPENGL/1bufftst
Clipping and viewing volume
glOrtho( left, right, bottom, top, near, far )
camera always looks down negative z-axis.
camera ‘views’ everything in the viewing volume (frustum) also objects
‘behind’ the camera.
glOrtho2D( left, right, bottom, top) = glOrtho( left, right, bottom, top,
-1, 1 )
pf3
pf4

Partial preview of the text

Download Jorg's Graphics Lecture Notes: Basic OpenGL Programming and more Study notes Computer Science in PDF only on Docsity!

2. Basic openGL Programming

Global state

OpenGL is not object oriented! It has a global state organized as a tree-like stack via ‘push’ and ‘pop’ separators.

image = GlobState(attributes; objects)

  • Primitives: (what, shape node) points, line segments, polygons, pixels, curves
  • Attributes system state: (how, property) accum buffer, color, current, depth buffer, enable, eval, fog, hint, lighting, line, list, pixel mode, point, polygon, polygon stipple, scissor, stencil buffer, texture, transform, view- port.
  • 2 matrix stacks: glMatrixMode(GL PROJECTION ) Viewing: projection, clipping glMatrixMode(GL MODELVIEW ) Transformation: rotate, scale, trans- late
  • events (input, error handling, network connection, etc.)

Example:

glClear() glColor3f() glBegin (GL_POINTS) glVertex2fv() glEnd (GL_POINTS) glFlush()

OPENGL/1bufftst

Clipping and viewing volume

  • glOrtho( left, right, bottom, top, near, far )
  • camera always looks down negative z-axis.
  • camera ‘views’ everything in the viewing volume (frustum) – also objects ‘behind’ the camera.
  • glOrtho2D( left, right, bottom, top) = glOrtho( left, right, bottom, top, -1, 1 )

z 5 0 z

x

y

Viewing rectangle

(a) (b)

GLUT organizes interaction with X windows, input devices (Xlib,Xtk) see glut.h

  • glutInitWindowSize() How large is the window? Note: image may be smaller than window

xy w

h Viewport Graphics window

Clipping window

  • glutInitWindowPosition() Where on the screen does the image appear? (0,0) = upper left 2D (Physical) device coordinates = raster coordinates = screen coordi- nates vs. 3D world coordinates distortion if width, height ratio of gluOrtho 6 = glutInitWindowSize

h

w

avoid distortion: glViewport( ll x, ll y, width, height ) in pixels part of state – hence interactive change possible

  • OpenGL (scene), Postscript: origin lower left, x right, y up
  • X: upper left, x right, y down
  • ascii: upper left, x down, y right (landscape)

Primitives glBegin(GL SOMETHING)... glEnd(); GL POINTS, GL LINES (segments 1-2, 3-4) vs GL LINE STRIP (poly-line) Polygon: simple, convex, flat (triangles will do!)

Color – additive, subtractive colors

Blue

Red

Green

Yellow

Cyan

Magenta (a) (b)

Magenta

Cyan

Yellow

White

Green

Red

Blue

Black

Cyan

Blue

Green Yellow

Red

Magenta

White

Black R

G

B

glColor (r,g,b), glClearColor(r,g,b,α): 2^24 colors 1280 × 1024 pixels with 24 bits (RGB) + α > 4 · 220 bytes = 4MB. Color gamut Hue, Saturation, Intensity model

lookup table (old)

Event Processing

  • Immediate mode: primitive is rendered as soon as defined. Present system state determines appearance.
  • disappears “too fast”
  • glutMainLoop(): event-processing loop displays current until interupted
  • glutDisplay( *func) display callback called: initially, when moving windows, etc.