CSCI 420: Computer Graphics
Hao Li
http://cs420.hao-li.com
1
Fall 2018
1.2 Basic Graphics Programming Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation
Fall 2018 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 Simulation
CSCI 420: Computer Graphics
http://cs420.hao-li.com
1
Fall 2018
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)
23
24
25
26
27
Mac, Linux, Windows: ships with the OS Linux: Mesa, freeware implementation
31
the result the scene
32
33
34
primitives+ material properties translate rotate scale is it visible
3D to 2D convert to pixels shown
(framebuffer)
36
primitives+ material properties translate rotate scale is it visible
3D to 2D convert to pixels shown
(framebuffer)
37
working in parallel, busses between stages
typical graphics use
38
39
40
41
perspective
42
43
glBegin(type); glVertex3f(x1,y1,z1); … glVertex3f(xN,yN,zN); glEnd();
44
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()
45
glBegin(GL_POINTS); glVertex3f(…); … glVertex3f(…); glEnd() draw points
46
47
(a) simple, but not convex (b) non-simple (c) convex
48
process and render
polygons is “undefined”
(tessellation)
49
attributes!
50
51
52
wavelength (nm) amplitude Cone response Source: VOS & Walraven
53
Convenient for display Can be unintuitive (3 floats in OpenGL)
Hue: what color? Saturation: how far away from gray? Value: how bright?
54
Gimp Color Picker
55
int main(int argc, char ** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); …
56
… glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
57
void init() { glClearColor (0.0,0.0,0.0,0.0); // glShadeModel (GL_FLAT); glShadeModel (GL_SMOOTH); }
58
void display() { glClear(GL_COLOR_BUFFER_BIT); // clear buffer setupCamera(); // set up camera triangle(); // draw triangle glutSwapBuffers(); // force display }
59
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(); }
60
glShadeModel(GL_FLAT) glShadeModel(GL_SMOOTH)
color of last vertex each vertex separate color smoothly interpolated
61
Flat Shading Smooth Shading
62
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); }
63
64
65
66
67
68
69
CPU GPU “client” “server”
70