CSCI 420: Computer Graphics
Hao Li
http://cs420.hao-li.com
1
Fall 2014
1.2 Basic Graphics Programming Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation
Fall 2014 CSCI 420: Computer Graphics 1.2 Basic Graphics Programming Hao Li http://cs420.hao-li.com 1 Last time Last Time Computer Story Image Graphics Last Time 3D Printing 3D Capture Animation 3D Rendering Modeling
CSCI 420: Computer Graphics
http://cs420.hao-li.com
1
Fall 2014
Computer Graphics Image Story
4
3D Capture Modeling Design Animation Simulation 3D Printing 3D Rendering Sound Rendering
emerging fields
5
realistic effective
6
7
input data
8
drawing photography
12
13
14
15
16
17
Scene is composed of geometric structures with the buiding block of a
vector raster rasterization
camera
should be shown there
19
20
21
22
Graphics.
Khronos)
24
25
Mac, Linux, Windows: ships with the OS Linux: Mesa, freeware implementation
30
the result the scene
31
32
33
primitives+ material properties translate rotate scale is it visible
3D to 2D convert to pixels shown
(framebuffer)
35
primitives+ material properties translate rotate scale is it visible
3D to 2D convert to pixels shown
(framebuffer)
36
working in parallel, busses between stages
typical graphics use
37
38
39
40
perspective
41
42
glBegin(type): glVertex3f(x1,y1,z1); … glVertex3f(xN,yN,zN); glEnd();
43
glBegin(GL_LINE_LOOP); glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,0.0,0.0) ; glVertex3f(1.0,1.0,0.0); glVertex3f(0.0,1.0,0.0); glEnd()
and glEnd()
44
glBegin(GL_POINTS); glVertex3f(…); … glVertex3f(…); glEnd() draw points
45
46
(a) simple, but not convex (b) non-simple (c) convex
47
process and render
polygons is “undefined”
(tesselation)
48
attributes!
49
50
51
wavelength (nm) amplitude Cone response Source: VOS & Walraven
52
Convenient for display Can be unintuitive (3 floats in OpenGL)
Hue: what color? Saturation: how far away from gray? Value: how bright?
53
Gimp Color Picker
54
int main(int argc, char ** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); …
55
… glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
56
void init() { glClearColor (0.0,0.0,0.0,0.0); // glShadeModel (GL_FLAT); glShadeModel (GL_SMOOTH); }
57
void display() { glClear(GL_COLOR_BUFFER_BIT); // clear buffer setupCamera(); // set up camera triangle(); // draw triangle glutSwapBuffers(); // force display }
58
void triangle() { glBegin(GL_TRIANGLES); glColor3f(1.0,0.0,0.0); // red glVertex2f(5.0,5.0); glColor3f(0.0,1.0,0.0); // green glVertex2f(25.0,5.0); glColor3f(0.0,0.0,1.0); // blue glVertex2f(5.0,25.0); glEnd(); }
59
glShadeModel(GL_FLAT) glShadeModel(GL_SMOOTH)
color of last vertex each vertex separate color smoothly interpolated
60
Flat Shading Smooth Shading
61
void reshape (int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) gluOrtho2D(0.0,30.0,0.0,30.0 * (GLfloat) h/(GLfloat) w); else gluOrtho2D(0.0,30.0 * (GLfloat) w/(GLfloat) h, 0.0,30.0); glMatrixMode(GL_MODELVIEW); }
62
63
64
65
66
67
68
CPU GPU “client” “server”
69