Workshop 3D capture, modelling and augmented reality Capture 3D, modélisation et réalité augmentée

Size: px
Start display at page:

Download "Workshop 3D capture, modelling and augmented reality Capture 3D, modélisation et réalité augmentée"

Transcription

1 International Master Program «Biometrics» Workshop sessions Workshop 3D capture, modelling and augmented reality Capture 3D, modélisation et réalité augmentée Jean-Marc Vézien (LIMSI-CNRS, équipe VENISE) 3D Modelling and Augmented Reality - Jean-Marc Vézien 1

2 Workshop 3D capture, modelling and augmented reality Capture 3D, modélisation et réalité augmentée An introduction to 3D modelling and OpenGL 3D Modelling and Augmented Reality - Jean-Marc Vézien 2

3 Computer Graphics is about animation ( films ) Major driving force now 3D Modelling and Augmented Reality - Jean-Marc Vézien 3

4 And games! 3D Modelling and Augmented Reality - Jean-Marc Vézien 4

5 And a lot of serious apps Medical imaging 3D Modelling and Augmented Reality - Jean-Marc Vézien 5

6 Scientific Visualisation Pymol.org 3D Modelling and Augmented Reality - Jean-Marc Vézien 6

7 Graphics/Rendering Pipeline Graphics processes generally execute sequentially Pipelining the process means dividing it into stages Different hardware resources assigned for each stage real-time 3 stages: 3D Modelling and Augmented Reality - Jean-Marc Vézien 7

8 Application stage Entirely done in software by the CPU Read Data - the world geometry database, - User s input by mice, trackballs, trackers, or sensing gloves In response to the user s input, the application stage changes the view or scene 3D Modelling and Augmented Reality - Jean-Marc Vézien 8

9 Geometry Stage Modeling: shapes Model Transformation Transformation: viewing Hidden Surface Elimination Rasterization Stage Shading: reflection and lighting 3D Modelling and Augmented Reality - Jean-Marc Vézien 9

10 Rasterization Stage Geometry Stage Rasterization and Sampling Texture Mapping Image Composition Intensity and Colour Quantization Framebuffer/Display 3D Modelling and Augmented Reality - Jean-Marc Vézien 10

11 Pipeline illustration The final scene Images courtesy of Picture Inc. 3D Modelling and Augmented Reality - Jean-Marc Vézien 11

12 Geometry Pipeline Loaded 3D Models Model Transformation Transformation: viewing Hidden Surface Elimination Shading: reflection and lighting Imaging 3D Modelling and Augmented Reality - Jean-Marc Vézien 12

13 Preparing Shape Models Designed by polygons, parametric curves/surfaces, implicit surfaces and etc. Defined in its own coordinate system 3D Modelling and Augmented Reality - Jean-Marc Vézien 13

14 Model Transformation Put Objects into the scene by applying translation, scaling and rotation Linear transformation (homogeneous) The location of all the vertices are updated by this transformation 3D Modelling and Augmented Reality - Jean-Marc Vézien 14

15 Model Transformation Rotate Translate Scale 3D Modelling and Augmented Reality - Jean-Marc Vézien 15

16 Perspective Projection Create a picture of the scene viewed from the camera Perspective transformation to convert the 3D coordinates to 2D coordinates of the screen Objects far away appear smaller, closer objects appear bigger 3D Modelling and Augmented Reality - Jean-Marc Vézien 16

17 Perspective Projection 3D Modelling and Augmented Reality - Jean-Marc Vézien 17 M(X,Y,Z) o m(x,y) f z x Focal point Focal plane PM Z Y X f f w wy wx m

18 Hidden Surface Removal Objects occluded by other objects must not be drawn! Also called occlusion culling (OC) or visible surface determination (VSD) Step 1: Remove all polygons outside of viewing frustum (culling) Step 2: Remove all polygons that are facing away from the viewer : N.V < 0 Step 3: Draw the visible faces in an order so the object looks right. Usually a sorting process in depth (the closer wins) 3D Modelling and Augmented Reality - Jean-Marc Vézien 18

19 Frustum Culling (Step 1) Camera has a pyramid of view Quickly discard everything out of view 3D Modelling and Augmented Reality - Jean-Marc Vézien 19

20 Shading Compute the colour p of each pixels : object s colour (reflectance f) lighting condition (light source l) The camera position (position of L and N relative to camera) Simplest model: Lambertian (diffuse) p l. f.cos p Add up light sources (+ occlusions!) 3D Modelling and Augmented Reality - Jean-Marc Vézien 20

21 Shading : Constant Shading - Ambient Objects painted by own colour What children do: instinctive intrinsic representation 3D Modelling and Augmented Reality - Jean-Marc Vézien 21

22 Ex: Flat Shading Object coloured based on its own colour and the lighting condition One colour for one face (normal based) Crude rendering for complex objects 3D Modelling and Augmented Reality - Jean-Marc Vézien 22

23 Gouraud shading Lighting calculation per vertex (average of color normals) Interpolate between vertex 3D Modelling and Augmented Reality - Jean-Marc Vézien 23

24 Specular highlights added Surface = diffuse + mirror (specularities) Illustration of the Phong Reflection Model. Created by the uploaded, Brad Smith, August 7, Ld = [rd, gd,bd]max(0,(n L)) La = [ra, ga,ba] Ls = [rs, gs,bs] max(0, (V R)) p Total Radiance for a light L = A(La + Ld + Ls) A = 1/(a + br + cr 2 ) distance fall-off 3D Modelling and Augmented Reality - Jean-Marc Vézien 24

25 Phong shading Gouraud Shading Highlights (Phong) 3D Modelling and Augmented Reality - Jean-Marc Vézien 25

26 Imaging pipeline Geometry Pipelin e Rasterization and Sampling Texture Mapping Image Composition Intensity and Colour Quantization Framebuffer/Display 3D Modelling and Augmented Reality - Jean-Marc Vézien 26

27 Rasterization Converts the vertex information output by the geometry pipeline into pixel information needed by the video display 1962: Bresenham! function line(x0, x1, y0, y1) int deltax := x1 - x0 int deltay := y1 - y0 real error := 0 real deltaerr := abs (deltay / deltax) // Assume deltax!= 0 (line is not vertical), // note that this division needs to be done in a way // that preserves the fractional part int y := y0 for x from x0 to x1 plot(x,y) error := error + deltaerr if error 0.5 then y := y + 1 error := error Aliasing: distortion artifacts produced when representing a high-resolution signal at a lower resolution. Anti-aliasing : technique to remove aliasing 3D Modelling and Augmented Reality - Jean-Marc Vézien 27

28 Anti-aliasing Aliased polygons ( edges (jagged Anti-aliased polygons Must low-pass filter the input signal OR Oversample it (create higher frequencies) 3D Modelling and Augmented Reality - Jean-Marc Vézien 28

29 Anti-aliasing Each pixel is subdivided (sub-sampled) in n regions, Each sub-pixel has a color Compute the average color value 3D Modelling and Augmented Reality - Jean-Marc Vézien 29

30 Texture mapping Paint objects with images (wallpaper) A texture map is applied (mapped) to the surface of a shape or polygon. Every vertex in a polygon is assigned a 2D texture coordinate Texture coordinates are interpolated on the polygon surface with rasterization algorithm. A surface color can be computed for each pixel Note: possible warping Modulated with lighting as previously seen 3D Modelling and Augmented Reality - Jean-Marc Vézien 30

31 Texture mapping 3D Modelling and Augmented Reality - Jean-Marc Vézien 31

32 OpenGL 3D Modelling and Augmented Reality - Jean-Marc Vézien 32

33 What is OpenGL? A software interface to graphics hardware Graphics rendering API (Low Level) + pipeline High-quality color images composed of geometric and image primitives Window system independent Operating system independent Doom3 3D Modelling and Augmented Reality - Jean-Marc Vézien 33

34 OpenGL : A brief history Silicon Graphics (SGI) revolutionized the graphics workstation by implementing the pipeline in hardware (1982) To access the system, application programmers used a library called GL relatively simple to program 3D interactive applications The success of GL lead to OpenGL (1992), a platform-independent API that was: Easy to use Close enough to the hardware to get excellent performance Focus on rendering Omitted windowing and input to avoid window system dependencies 3D Modelling and Augmented Reality - Jean-Marc Vézien 34

35 Control Architectural Review Board (ARB) Members include SGI, Microsoft, Nvidia, HP, 3DLabs, IBM, etc. Rapidly evolving (4.0 in 2011) ; evolution reflects new hardware capabilities Allows for platform specific features through extensions 3D Modelling and Augmented Reality - Jean-Marc Vézien 35

36 OpenGL Basics Rendering Typically execution of OpenGL commands Converting geometric/mathematical object descriptions into frame buffer values OpenGL can render: Geometric primitives: lines, points, polygons, etc Bitmaps and Images Images and geometry linked through texture mapping Graphics Pipeline 3D Modelling and Augmented Reality - Jean-Marc Vézien 36

37 Transformation Pipeline Position object w.r.t. camera Project object coordinates 3D Modelling and Augmented Reality - Jean-Marc Vézien 37

38 Objects Made up of sets of polygons Which are made up of lines Which are made of points No curved surfaces +Y Just a shell Not a solid object Everything is a set of points (vertex) In local coordinate system Polygons +Z +X 3D Modelling and Augmented Reality - Jean-Marc Vézien 38

39 OpenGL Geometric Primitives The geometry is specified by vertices. There are 10 primitive types: 3D Modelling and Augmented Reality - Jean-Marc Vézien 39

40 Simple Example void drawrhombus( GLfloat color[] ) { glbegin( GL_QUADS ); glcolor3fv( color ); glvertex2f( 0.0, 0.0 ); glvertex2f( 1.0, 0.0 ); glvertex2f( 1.5, ); glvertex2f( 0.5, ); glend(); } 3D Modelling and Augmented Reality - Jean-Marc Vézien 40

41 Polygon Issues OpenGL will only display polygons correctly that are: Simple: edges cannot cross Convex: all points on line segment between two points in a polygon are also in the polygon Flat: all vertices are in the same plane User program can check if above true OpenGL will produce output if these conditions are violated but it may not be what is desired Triangles satisfy all conditions triangulation algorithms 3D Modelling and Augmented Reality - Jean-Marc Vézien 41

42 OpenGL Command Format glvertex3fv 3D Modelling and Augmented Reality - Jean-Marc Vézien 42

43 Vertices and Primitives Primitives are specified between glbegin( primtype ); glend(); primtype determines how vertices are combined glend(); GLfloat red, green, blue; Glfloat coords[nverts][3]; /*Initialize coords and colors somewhere in program*/ glbegin( primtype ); for ( i = 0; i < nverts; ++i ) { glcolor3f( red, green, blue ); glvertex3fv( coords[i] ); } 3D Modelling and Augmented Reality - Jean-Marc Vézien 43

44 An Example void drawparallelogram( GLfloat color[] ) { glbegin( GL_QUADS ); glcolor3fv( color ); glvertex2f( 0.0, 0.0 ); glvertex2f( 1.0, 0.0 ); glvertex2f( 1.5, ); glvertex2f( 0.5, ); glend(); } 3D Modelling and Augmented Reality - Jean-Marc Vézien 44

45 Vertices and Primitives Points: GL_POINTS Individual points Point size can be altered: glpointsize (float size) glbegin(gl_points); glcolor3fv( color ); glvertex2f( P0.x, P0.y ); glvertex2f( P1.x, P1.y ); glvertex2f( P2.x, P2.y ); glvertex2f( P3.x, P3.y ); glvertex2f( P4.x, P4.y ); glvertex2f( P5.x, P5.y ); glvertex2f( P6.x, P6.y ); glvertex2f( P7.x, P7.y ); glend(); 3D Modelling and Augmented Reality - Jean-Marc Vézien 45

46 Vertices and Primitives Lines: GL_LINES Pairs of vertices interpreted as individual line segments Can specify line width using gllinewidth (float width) glbegin(gl_lines); glcolor3fv( color ); glvertex2f( P0.x, P0.y ); glvertex2f( P1.x, P1.y ); glvertex2f( P2.x, P2.y ); glvertex2f( P3.x, P3.y ); glvertex2f( P4.x, P4.y ); glvertex2f( P5.x, P5.y ); glvertex2f( P6.x, P6.y ); glvertex2f( P7.x, P7.y ); glend(); Lines are useful for rays 3D Modelling and Augmented Reality - Jean-Marc Vézien 46

47 Vertices and Primitives Line Strip: GL_LINE_STRIP series of connected line segments 3D Modelling and Augmented Reality - Jean-Marc Vézien 47

48 Vertices and Primitives Line Loop: GL_LINE_LOOP Line strip with a segment added between last and first vertices 3D Modelling and Augmented Reality - Jean-Marc Vézien 48

49 Vertices and Primitives Polygon : GL_POLYGON boundary of a simple, convex polygon 3D Modelling and Augmented Reality - Jean-Marc Vézien 49

50 Vertices and Primitives Triangles : GL_TRIANGLES triples of vertices interpreted as triangles VERY USED! 3D Modelling and Augmented Reality - Jean-Marc Vézien 50

51 Vertices and Primitives Triangle Strip : GL_TRIANGLE_STRIP linked strip of triangles v0 v1 v2 v3 v4 v5 v6 v7 3D Modelling and Augmented Reality - Jean-Marc Vézien 51

52 Vertices and Primitives Triangle Fan : GL_TRIANGLE_FAN linked fan of triangles v1 v2 v3 v4 v0 v5 3D Modelling and Augmented Reality - Jean-Marc Vézien 52

53 Vertices and Primitives Quads : GL_QUADS quadruples of vertices interpreted as four-sided polygons 3D Modelling and Augmented Reality - Jean-Marc Vézien 53

54 Vertices and Primitives Between glbegin/ glend, these opengl commands are allowed: glvertex*() : set vertex coordinates glcolor*() : set current color glindex*() : set current color index glnormal*() : set normal vector coordinates (Light.) gltexcoord*() : set texture coordinates (Texture) 3D Modelling and Augmented Reality - Jean-Marc Vézien 54

55 Example glbegin(gl_triangles); for (int i=0; i<ntris; i++) { glcolor3f(tri[i].r0,tri[i].g0,tri[i].b0); // Color of vertex glnormal3f(tri[i].nx0,tri[i].ny0,tri[i].nz0);// Normal glvertex3f(tri[i].x0,tri[i].y0,tri[i].z0); // Position glcolor3f(tri[i].r2,tri[i].g2,tri[i].b2); glnormal3f(tri[i].nx2,tri[i].ny2,tri[i].nz2); glvertex3f(tri[i].x2,tri[i].y2,tri[i].z2); } glend(); // Sends all the vertices/normals to OpenGL library 3D Modelling and Augmented Reality - Jean-Marc Vézien 55

56 OpenGL: Camera Two things to specify: Physical location of camera in the scene (MODELVIEW matrix in OpenGL). Where is the camera? Which direction is it pointing? What is the orientation of the camera? Projection properties of the camera (PROJECTION matrix in OpenGL): Depth of field? Field of view in the x and y directions? 3D Modelling and Augmented Reality - Jean-Marc Vézien 56

57 OpenGL: Camera Coordinate-systems are represented as matrices in OpenGL. Camera = a coordinate-system centered at its image plane. Camera Matrix = specify the physical properties of the camera. 3D Modelling and Augmented Reality - Jean-Marc Vézien 57

58 OpenGL: MODELVIEW eye= z Camera up = y y p Point p in world is: (MODELVIEW * p) in camera coord-sys!!! x center = (0,0,0) x World glmatrixmode(gl_modelview); // Specify matrix mode glloadidentity(); // Clear modelview matrix //GLU API (included with OpenGL) glulookat(eyex,eyey,eyez,centerx, centery,centerz,upx,upy,upz); z 3D Modelling and Augmented Reality - Jean-Marc Vézien 58

59 OpenGL: GL_MODELVIEW World coord-system: Camera coord-system: 3D Modelling and Augmented Reality - Jean-Marc Vézien 59

60 OpenGL: GL_PROJECTION Goal: set intrinsic (optical) properties of camera: glmatrixmode(gl_projection); glloadidentity(); gluperspective(fovy, aspect, near, far); Everything before near and after far is discarded 3D Modelling and Augmented Reality - Jean-Marc Vézien 60

61 OpenGL: GL_PROJECTION (C td) Camera viewport: window on the scene far gluperspective(fovy, aspect, near, far); near x center fov aspect = w/h z y z y h far Note: symetric camera only! x w near 3D Modelling and Augmented Reality - Jean-Marc Vézien 61

62 OpenGL: Setting Camera Assume window is width x height: void SetCamera() { glviewport(0, 0, width, height); /* Set camera position */ glmatrixmode(gl_modelview); glloadidentity(); glulookat( m_veye[0], m_veye[1], m_veye[2], m_vref[0], m_vref[1], m_vref[2], m_vup[0], m_vup[1], m_vup[2]); /* Set projection frustrum */ glmatrixmode(gl_projection); glloadidentity(); gluperspective(m_fyfov, width / height, m_fnear, m_ffar); } Typical: 45 16/ D Modelling and Augmented Reality - Jean-Marc Vézien 62

63 OpenGL: Lighting Set light: gllightfv(light_num, property, value); Light_num : id of light (GL_LIGHTx) Property: one of the 3 components for each light: diffuse (lambertian) component: GL_DIFFUSE specular component : GL_SPECULAR ambient light: GL_AMBIENT Value: GLfloat[4] (between 0 and 1): RGBA. 3D Modelling and Augmented Reality - Jean-Marc Vézien 63

64 OpenGL: Lighting Set material (for objects): glmaterialfv(side, property, value); Side : which side (GL_FRONT, GL_BACK, GL_FRONT_AND_BACK) Property: one of the 3 properties: diffuse albedo: GL_AMBIENT_AND_DIFFUSE specular albedo: GL_SPECULAR shininess (in phong s model): GL_SHININESS Value: GLFloat[] 3D Modelling and Augmented Reality - Jean-Marc Vézien 64

65 OpenGL: Lighting example GLfloat mat_diffuse[4] = {0.75, 0.75, 0.75, 1.0}; GLfloat mat_specular[4] = {0.55, 0.55, 0.55, 1.0}; GLfloat mat_shininess[1] = {80}; glmaterialfv(gl_front_and_back, GL_AMBIENT_AND_DIFFUSE,mat_diffuse); glmaterialfv(gl_front,gl_specular,mat_specular); glmaterialfv(gl_front,gl_shininess,mat_shininess); GLfloat light0_ambient[4] = { 0.0, 0.0, 0.0, 1.0}; GLfloat light0_color[4] = { 0.4, 0.4, 0.4, 1.0 }; gllightfv(gl_light0, GL_AMBIENT, light0_ambient); gllightfv(gl_light0, GL_DIFFUSE, light0_color); gllightfv(gl_light0, GL_SPECULAR, light0_color); glenable(gl_light0); glenable(gl_lighting); 3D Modelling and Augmented Reality - Jean-Marc Vézien 65

66 OpenGL: Shading model There are two shading modes in OpenGL: Flat shading: entire face is the color computed at the 0 th vertex. glshademodel(gl_flat); Gouraud ( smooth ) shading: color computed at each vertex and interpolated across polygon. glshademodel(gl_smooth); 3D Modelling and Augmented Reality - Jean-Marc Vézien 66

67 OpenGL: Flat Shading glshademodel(gl_flat); 3D Modelling and Augmented Reality - Jean-Marc Vézien 67

68 OpenGL: Flat Shading glshademodel(gl_smooth); 3D Modelling and Augmented Reality - Jean-Marc Vézien 68

69 OpenGL: Lighting is Optional! Lighting is an explicit option : glenable(gl_lighting); gldisable(gl_lighting); When disabled, the color of each vertex is directly glcolor3f(r,g,b). Do not need lighting when debugging your renderer. 3D Modelling and Augmented Reality - Jean-Marc Vézien 69

70 Texture Mapping y x z t geometry screen image s 3D Modelling and Augmented Reality - Jean-Marc Vézien 70

71 Texture mapping: basic principle Three steps to applying a texture 1. Specify the texture Read or generate image Assign to texture Enable texturing 2. Assign texture coordinates to vertices Proper mapping function is left to application 3. Specify texture parameters wrapping, filtering 3D Modelling and Augmented Reality - Jean-Marc Vézien 71

72 Texture Example The texture is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective 1. Define a texture image from an array of texels (texture elements) in CPU memory Glubyte my_texels[512][512][4]; Fill it as any other pixel array Scan Via application code Enable texture mapping glenable(gl_texture_2d) OpenGL supports 1-4 dimensional texture maps 3D Modelling and Augmented Reality - Jean-Marc Vézien 72

73 Assign Image as a Texture glteximage2d( target, level, components, w, h, border, format, type, texels ); Ex: target: type of texture, e.g. GL_TEXTURE_2D level: used for mipmapping (discussed later) components: elements per texel w, h: width and height of texels in pixels border: used for smoothing (discussed later) format and type: describe texels texels: pointer to texel array glteximage2d(gl_texture_2d, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); 3D Modelling and Augmented Reality - Jean-Marc Vézien 73

74 Converting A Texture Image OpenGL requires texture dimensions to be powers of 2 If dimensions of image are not powers of 2: gluscaleimage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out ); data_in = source image data_out = destination image Image interpolated and filtered during scaling 3D Modelling and Augmented Reality - Jean-Marc Vézien 74

75 Mapping a Texture Based on parametric texture coordinates: gltexcoord*() specified at each vertex t 0, 1 Texture Space a 1, 1 Object Space (s, t) = (0.2, 0.8) A b 0, 0 1, 0 c s (0.4, 0.2) B C (0.8, 0.4) 3D Modelling and Augmented Reality - Jean-Marc Vézien 75

76 Mapping a Texture : example glbegin(gl_polygon); glcolor3f(r0, g0, b0); glnormal3f(u0, v0, w0); gltexcoord2f(s0, t0); glvertex3f(x0, y0, z0); glcolor3f(r1, g1, b1); glnormal3f(u1, v1, w1); gltexcoord2f(s1, t1); glvertex3f(x1, y1, z1);.. glend(); Note that we can use vertex arrays to increase efficiency 3D Modelling and Augmented Reality - Jean-Marc Vézien 76

77 Interpolation OpenGL uses bilinear interpolation to find proper texels from specified texture coordinates Distorsions can occur! good selection of tex coordinates poor selection of tex coordinates texture stretched over trapezoid showing effects of bilinear interpolation 3D Modelling and Augmented Reality - Jean-Marc Vézien 77

78 Texture Parameters OpenGL has a variety of parameters that determine how texture is applied gltexparameteri( target, type, mode ) Wrapping parameters determine what happens of s and t if outside the (0,1) range Filter modes allow to use area averaging instead of point samples Mipmapping = use textures at multiple resolutions Environment parameters determine how texture mapping interacts with shading 3D Modelling and Augmented Reality - Jean-Marc Vézien 78

79 Wrapping Mode Two modes: clamping or wrapping GL_CLAMP : if s,t > 1 use 1, if s,t <0 use 0 t GL_WRAP : use s,t modulo 1 gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) texture s GL_REPEAT wrapping GL_CLAMP wrapping 3D Modelling and Augmented Reality - Jean-Marc Vézien 79

80 Magnification and Minification More than one texel can cover a pixel (minification) or more than one pixel can cover a texel (magnification) Texture Magnification Polygon Texture Polygon Minification 3D Modelling and Augmented Reality - Jean-Marc Vézien 80

81 Filter Modes Minification and magnification can use point sampling (nearest texel) or linear filtering ( 2 x 2 filter) to obtain texture values: gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Note that linear filtering requires a border of an extra texel for filtering at edges (border = 1) 3D Modelling and Augmented Reality - Jean-Marc Vézien 81

82 Mipmapped Textures Mipmapping allows for prefiltered texture maps of decreasing resolutions Lessens interpolation errors for smaller textured objects Declare mipmap level at texture definition glteximage2d( GL_TEXTURE_*D, level, ) GLU mipmap builder routines will build all the textures from a given image glubuild2dmipmaps( ) 3D Modelling and Augmented Reality - Jean-Marc Vézien 82

83 Example Simple point sampling Linear filtering Mipmapped point sampling Mipmapped linear 3D Modelling and Augmented Reality - Jean-Marc Vézien 83

84 Texture Functions Controls how texture is applied gltexenv{fi}[v]( GL_TEXTURE_ENV_MODE, prop, param ) GL_TEXTURE_ENV_MODE modes GL_MODULATE: modulates with computed shading GL_BLEND: blends with an environmental color GL_REPLACE: use only texture color GL(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); Set blend color with GL_TEXTURE_ENV_COLOR 3D Modelling and Augmented Reality - Jean-Marc Vézien 84

85 Perspective Correction Hint Texture coordinate and color interpolation are computed: either linearly in screen space or using depth/perspective values (slower) Noticeable for polygons on edge glhint( GL_PERSPECTIVE_CORRECTION_HINT, hint ) hint is one of GL_DONT_CARE GL_NICEST GL_FASTEST 3D Modelling and Augmented Reality - Jean-Marc Vézien 85

86 Generating Texture Coordinates OpenGL can generate texture coordinates automatically Specify a plane gltexgen{ifd}[v]() Generate texture coordinates based upon distance from the plane Generation modes: GL_OBJECT_LINEAR GL_EYE_LINEAR GL_SPHERE_MAP (used for environmental maps) 3D Modelling and Augmented Reality - Jean-Marc Vézien 86

87 Texture Objects Texture is part of the OpenGL state Different textures for different objects moving large data from processor memory to texture memory Recent versions of OpenGL have texture objects: one image per texture object Texture memory can hold multiple texture objects 3D Modelling and Augmented Reality - Jean-Marc Vézien 87

88 Other Texture Features Environmental Maps Take image of environment with wide angle lens Use this texture to generate a spherical map Use automatic texture coordinate generation on box-like container for scene Multi-texturing Apply a sequence of textures through cascaded texture units 3D Modelling and Augmented Reality - Jean-Marc Vézien 88

89 OpenGL and GLUT 3D Modelling and Augmented Reality - Jean-Marc Vézien 89

90 OpenGL and GLUT GLUT (OpenGL Utility Toolkit) An auxiliary library Portable windowing API Easier to show the output of your OpenGL application Not officially part of OpenGL Handles: Window creation, OS system calls Mouse buttons, movement, keyboard, etc Callbacks 3D Modelling and Augmented Reality - Jean-Marc Vézien 90

91 How to install GLUT? Download GLUT Copy the files to following folders: glut.h VC/include/gl/ glut32.lib VC/lib/ glut32.dll windows/system32/ Header Files: #include <GL/glut.h> #include <GL/gl.h> Include glut automatically includes other header files 3D Modelling and Augmented Reality - Jean-Marc Vézien 91

92 Application Structure: GLUT Basics Configure and open window Initialize OpenGL state Register input callback functions render resize input: keyboard, mouse, etc. Enter event processing loop 3D Modelling and Augmented Reality - Jean-Marc Vézien 92

93 Sample Program #include <GL/glut.h> #include <GL/gl.h> void main(int argc, char** argv) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutinitwindowsize( 500,500 ); glutcreatewindow( Simple ); init(); glutdisplayfunc( display ); glutkeyboardfunc( key ); glutmainloop(); } 3D Modelling and Augmented Reality - Jean-Marc Vézien 93

94 Sample Program #include <GL/glut.h> #include <GL/gl.h> void main(int argc, char** argv) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutinitwindowsize( 500,500 ); glutcreatewindow( Simple ); init(); glutdisplayfunc( display ); glutkeyboardfunc( key ); glutmainloop(); } Specify the display Mode RGB or color Index, single or double Buffer 3D Modelling and Augmented Reality - Jean-Marc Vézien 94

95 Sample Program #include <GL/glut.h> #include <GL/gl.h> void main(int argc, char** argv) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutinitwindowsize( 500,500 ); glutcreatewindow( Simple ); init(); glutdisplayfunc( display ); glutkeyboardfunc( key ); glutmainloop(); } Create a window Named simple with resolution 500 x 500 3D Modelling and Augmented Reality - Jean-Marc Vézien 95

96 Sample Program #include <GL/glut.h> #include <GL/gl.h> void main(int argc, char** argv) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutinitwindowsize( 500,500 ); } glutcreatewindow( Simple ); init(); glutdisplayfunc( display ); glutkeyboardfunc( key ); glutmainloop(); Your OpenGL initialization code (Optional) 3D Modelling and Augmented Reality - Jean-Marc Vézien 96

97 Sample Program #include <GL/glut.h> #include <GL/gl.h> void main(int argc, char** argv) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutinitwindowsize( 500,500 ); glutcreatewindow( Simple ); } init(); glutdisplayfunc( display ); glutkeyboardfunc(key); glutmainloop(); Register your call back functions 3D Modelling and Augmented Reality - Jean-Marc Vézien 97

98 glutmainloop() #include <GL/glut.h> #include <GL/gl.h> int main(int argc, char** argv) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode(mode); glutinitwindowsize(500,500); glutcreatewindow( Simple ); init(); glutdisplayfunc(display); } Sample Program glutkeyboardfunc(key); glutmainloop(); The program goes into an infinite loop waiting for events 3D Modelling and Augmented Reality - Jean-Marc Vézien 98

99 OpenGL Initialization Set up whatever state you re going to use Specify camera, window (= viewport), lights void init( void ) { glclearcolor (0.0, 0.0, 0.0, 0.0); glviewport(0, 0, width, height); glmatrixmode(gl_projection); glloadidentity(); glortho(-10, 10, -10, 10, -10, 20); glmatrixmode(gl_modelview); glloadidentity(); } glenable( GL_LIGHT0 ); glenable( GL_LIGHTING ); glenable( GL_DEPTH_TEST ); 3D Modelling and Augmented Reality - Jean-Marc Vézien 99

100 GLUT Callback functions GLUT is Event-driven: Programs that use windows Input/Output events Wait until an event happens and then execute some pre-defined functions according to the user s input Events = key press, mouse button press and release, window resize, redraw, etc. Your OpenGL program will be in infinite loop 3D Modelling and Augmented Reality - Jean-Marc Vézien 100

101 GLUT Callback Functions Callback function : Routine to call when an event happens Window resize or redraw User input (mouse, keyboard) Animation (render many frames) Register callbacks with GLUT: glutdisplayfunc( my_display_func ); glutidlefunc( my_idle_func ); glutkeyboardfunc( my_key_events_func ); glutmousefunc ( my_mouse_events_func ); 3D Modelling and Augmented Reality - Jean-Marc Vézien 101

102 GLUT s Event Queue MainLoop() Event queue Keyboard. Mouse Window Mouse_callback() {. { Keypress_callback() {. { window_callback() {. { 3D Modelling and Augmented Reality - Jean-Marc Vézien 102

103 Events in GLUT Event Example OpenGL Callback Function Keypress KeyDown Mouse Motion Window System KeyUp leftbuttondown leftbuttonup With mouse press Without Moving Resizing Idle Timer Software What to draw glutkeyboardfunc glutmousefunc glutmotionfunc glutpassivemotionfunc glutreshapefunc glutidlefunc gluttimerfunc glutdisplayfunc 3D Modelling and Augmented Reality - Jean-Marc Vézien 103

104 Rendering Callback Callback function where all the drawing is done Every GLUT program must have a display callback glutdisplayfunc( my_display_func ); /* this part is in main.c */ void my_display_func (void ) { glclear( GL_COLOR_BUFFER_BIT ); glbegin( GL_TRIANGLE ); glvertex3fv( v[0] ); glvertex3fv( v[1] ); glvertex3fv( v[2] ); glend(); glflush(); } 3D Modelling and Augmented Reality - Jean-Marc Vézien 104

105 Idle Callback Called when not doing anything else Use for animation and continuous update Can use gluttimerfunc or timed callbacks for animations glutidlefunc( idle ); void idle( void ) { /* change something */ t += dt; glutpostredisplay(); } 3D Modelling and Augmented Reality - Jean-Marc Vézien 105

106 User Input Callbacks Process user input glutkeyboardfunc( my_key_events ); void my_key_events (char key, int x, int y ) { switch ( key ) { case q : case Q : exit ( EXIT_SUCCESS); break; case r : case R : rotate = GL_TRUE; break; } } 3D Modelling and Augmented Reality - Jean-Marc Vézien 106

107 Mouse Callback Captures mouse press and release events glutmousefunc( my_mouse ); void mymouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { } } 3D Modelling and Augmented Reality - Jean-Marc Vézien 107

108 References Many, many others 3D Modelling and Augmented Reality - Jean-Marc Vézien 108

109 THE END 3D Modelling and Augmented Reality - Jean-Marc Vézien 109

Introduction to Computer Graphics with OpenGL/GLUT

Introduction to Computer Graphics with OpenGL/GLUT Introduction to Computer Graphics with OpenGL/GLUT What is OpenGL? A software interface to graphics hardware Graphics rendering API (Low Level) High-quality color images composed of geometric and image

More information

RECITATION - 1. Ceng477 Fall

RECITATION - 1. Ceng477 Fall RECITATION - 1 Ceng477 Fall 2007-2008 2/ 53 Agenda General rules for the course General info on the libraries GLUT OpenGL GLUI Details about GLUT Functions Probably we will not cover this part 3/ 53 General

More information

CS212. OpenGL Texture Mapping and Related

CS212. OpenGL Texture Mapping and Related CS212 OpenGL Texture Mapping and Related Basic Strategy Three steps to applying a texture 1. specify the texture read or generate image assign to texture enable texturing 2. assign texture coordinates

More information

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options OpenGL Texture Mapping Objectives Introduce the OpenGL texture functions and options 1 Basic Strategy Three steps to applying a texture 1. 2. 3. specify the texture read or generate image assign to texture

More information

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO SANTA BARBARA SANTA CRUZ EECS 104 Fundamentals of Computer Graphics OpenGL Slides courtesy of Dave Shreine, Ed Angel and Vicki Shreiner

More information

OpenGL refresher. Advanced Computer Graphics 2012

OpenGL refresher. Advanced Computer Graphics 2012 Advanced Computer Graphics 2012 What you will see today Outline General OpenGL introduction Setting up: GLUT and GLEW Elementary rendering Transformations in OpenGL Texture mapping Programmable shading

More information

Lecture 4 of 41. Lab 1a: OpenGL Basics

Lecture 4 of 41. Lab 1a: OpenGL Basics Lab 1a: OpenGL Basics William H. Hsu Department of Computing and Information Sciences, KSU KSOL course pages: http://snipurl.com/1y5gc Course web site: http://www.kddresearch.org/courses/cis636 Instructor

More information

Computer Graphics 1 Computer Graphics 1

Computer Graphics 1 Computer Graphics 1 Projects: an example Developed by Nate Robbins Shapes Tutorial What is OpenGL? Graphics rendering API high-quality color images composed of geometric and image primitives window system independent operating

More information

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial CS335 Graphics and Multimedia Slides adopted from OpenGL Tutorial Texture Poly. Per Vertex Mapping CPU DL Texture Raster Frag FB Pixel Apply a 1D, 2D, or 3D image to geometric primitives Uses of Texturing

More information

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science CSC 307 1.0 Graphics Programming Department of Statistics and Computer Science Graphics Programming Texture Mapping 2 Texture Poly. Per Vertex Mapping CPU DL Pixel Texture Raster Frag FB Apply a 1D, 2D,

More information

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2)

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2) CS 480/680 INTERACTIVE COMPUTER GRAPHICS Texture Mapping and NURBS Week 7 David Breen Department of Computer Science Drexel University Objectives Introduce Mapping Methods Texture Mapping Environmental

More information

COMP 371/4 Computer Graphics Week 1

COMP 371/4 Computer Graphics Week 1 COMP 371/4 Computer Graphics Week 1 Course Overview Introduction to Computer Graphics: Definition, History, Graphics Pipeline, and Starting Your First OpenGL Program Ack: Slides from Prof. Fevens, Concordia

More information

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics VI Guoying Zhao 1 / 73 Texture mapping Guoying Zhao 2 / 73 Objectives Introduce Mapping Methods Texture Mapping Environment Mapping Bump Mapping Consider basic

More information

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics. Bing-Yu Chen National Taiwan University Computer Graphics Bing-Yu Chen National Taiwan University Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering

More information

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics. Bing-Yu Chen National Taiwan University Computer Graphics Bing-Yu Chen National Taiwan University Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering

More information

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations #include int main(int argc, char** argv) { glutinit(&argc, argv); Typical OpenGL/GLUT Main Program // GLUT, GLU, and OpenGL defs // program arguments // initialize glut and gl // double buffering

More information

Programming using OpenGL: A first Introduction

Programming using OpenGL: A first Introduction Programming using OpenGL: A first Introduction CMPT 361 Introduction to Computer Graphics Torsten Möller Machiraju/Zhang/Möller 1 Today Overview GL, GLU, GLUT, and GLUI First example OpenGL functions and

More information

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics OpenGL Tutorial Ceng 477 Introduction to Computer Graphics Adapted from: http://www.cs.princeton.edu/courses/archive/spr06/cos426/assn3/opengl_tutorial.ppt OpenGL IS an API OpenGL IS nothing more than

More information

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Teacher Assistant : Tamir Grossinger   Reception hours: by  - Building 37 / office -102 Assignments: 4 programing using Teacher Assistant : Tamir Grossinger email: tamirgr@gmail.com Reception hours: by email - Building 37 / office -102 Assignments: 4 programing using C++ 1 theoretical You can find everything you need in

More information

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW OpenGL Syntax Functions have prefix gl and initial capital letters for each word glclearcolor(), glenable(), glpushmatrix() glu for GLU functions glulookat(), gluperspective() constants begin with GL_,

More information

Graphics Programming

Graphics Programming Graphics Programming 3 rd Week, 2011 OpenGL API (1) API (application programming interface) Interface between an application program and a graphics system Application Program OpenGL API Graphics Library

More information

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3) Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1 http://www.cs.columbia.edu/~cs4160 To Do Start thinking (now) about HW 3. Milestones are due soon. Course Course 3D Graphics Pipeline 3D Graphics

More information

CS 4204 Computer Graphics

CS 4204 Computer Graphics CS 4204 Computer Graphics OpenGL Basics Yong Cao Virginia Tech References: 2001 Siggraph, An Interactive Introduction to OpenGL Programming, Dave Shreiner,Ed Angel, Vicki Shreiner Official Presentation

More information

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University OpenGL Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University Background Software interface to graphics hardware 250+ commands Objects (models) are built from geometric primitives

More information

Computer graphics MN1

Computer graphics MN1 Computer graphics MN1 http://www.opengl.org Todays lecture What is OpenGL? How do I use it? Rendering pipeline Points, vertices, lines,, polygons Matrices and transformations Lighting and shading Code

More information

Computer Graphics. OpenGL

Computer Graphics. OpenGL Computer Graphics OpenGL What is OpenGL? OpenGL (Open Graphics Library) is a library for computer graphics It consists of several procedures and functions that allow a programmer to specify the objects

More information

Lecture 2 2D transformations Introduction to OpenGL

Lecture 2 2D transformations Introduction to OpenGL Lecture 2 2D transformations Introduction to OpenGL OpenGL where it fits what it contains how you work with it OpenGL parts: GL = Graphics Library (core lib) GLU = GL Utilities (always present) GLX, AGL,

More information

Exercise 1 Introduction to OpenGL

Exercise 1 Introduction to OpenGL Exercise 1 Introduction to OpenGL What we are going to do OpenGL Glut Small Example using OpenGl and Glut Alexandra Junghans 2 What is OpenGL? OpenGL Two Parts most widely used and supported graphics API

More information

VR-programming tools (procedural) More VRML later in this course! (declarative)

VR-programming tools (procedural) More VRML later in this course! (declarative) Realtime 3D Computer Graphics & Virtual Reality OpenGL Introduction VR-programming Input and display devices are the main hardware interface to users Immersion embeds users through the generation of live-like

More information

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.

More information

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.

More information

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3 OpenGL Introduction Introduction OpenGL OpenGL is an API for computer graphics. Hardware-independent Windowing or getting input is not included in the API Low-level Only knows about triangles (kind of,

More information

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Lecture 2 CISC440/640 Spring Department of Computer and Information Science Lecture 2 CISC440/640 Spring 2015 Department of Computer and Information Science Today s Topic The secrets of Glut-tony 2 So let s do some graphics! For the next week or so this is your world: -1 1-1 1

More information

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs 91.427 Computer Graphics I, Fall 2008 1 1 Objectives Refine first program Alter default values Introduce standard program structure Simple viewing 2-D

More information

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M UNIT 7 LIGHTING AND SHADING 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M Ans: Phong developed a simple model that can be computed rapidly It considers three

More information

Lecture 3 Advanced Computer Graphics (CS & SE )

Lecture 3 Advanced Computer Graphics (CS & SE ) Lecture 3 Advanced Computer Graphics (CS & SE 233.420) Programming with OpenGL Program Structure Primitives Attributes and States Programming in three dimensions Inputs and Interaction Working with Callbacks

More information

OpenGL/GLUT Intro. Week 1, Fri Jan 12

OpenGL/GLUT Intro. Week 1, Fri Jan 12 University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week 1, Fri Jan 12 http://www.ugrad.cs.ubc.ca/~cs314/vjan2007 News Labs start next week Reminder:

More information

Programming of Graphics

Programming of Graphics Peter Mileff PhD Programming of Graphics Introduction to OpenGL University of Miskolc Department of Information Technology OpenGL libraries GL (Graphics Library): Library of 2D, 3D drawing primitives and

More information

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Texture Mapping CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 1 Objectives Introduce Mapping Methods - Texture Mapping - Environment Mapping - Bump Mapping Consider

More information

Most device that are used to produce images are. dots (pixels) to display the image. This includes CRT monitors, LCDs, laser and dot-matrix

Most device that are used to produce images are. dots (pixels) to display the image. This includes CRT monitors, LCDs, laser and dot-matrix Scan Conversion of Lines Raster devices Most device that are used to produce images are raster devices, that is, use rectangular arrays of dots (pixels) to display the image. This includes CRT monitors,

More information

Basic Graphics Programming

Basic Graphics Programming 15-462 Computer Graphics I Lecture 2 Basic Graphics Programming Graphics Pipeline OpenGL API Primitives: Lines, Polygons Attributes: Color Example January 17, 2002 [Angel Ch. 2] Frank Pfenning Carnegie

More information

Introduction to OpenGL Week 1

Introduction to OpenGL Week 1 CS 432/680 INTERACTIVE COMPUTER GRAPHICS Introduction to OpenGL Week 1 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico Objectives

More information

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1 CS 432/680 INTERACTIVE COMPUTER GRAPHICS Introduction to OpenGL Week 1 David Breen Department of Computer Science Drexel University Objectives Learn the basic design of a graphics system Introduce graphics

More information

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science CSC 307 1.0 Graphics Programming Department of Statistics and Computer Science Graphics Programming GLUT 2 Events in OpenGL Event Example Keypress KeyDown KeyUp Mouse leftbuttondown leftbuttonup With mouse

More information

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D CS334 Spring 2012 Daniel G. Aliaga Department of Computer Science Purdue University Computer Graphics Pipeline Geometric Primitives

More information

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation Lecture 19: OpenGL Texture Mapping CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives Introduce the OpenGL texture functions and options

More information

Basic Graphics Programming

Basic Graphics Programming CSCI 480 Computer Graphics Lecture 2 Basic Graphics Programming January 11, 2012 Jernej Barbic University of Southern California http://www-bcf.usc.edu/~jbarbic/cs480-s12/ Graphics Pipeline OpenGL API

More information

Precept 2 Aleksey Boyko February 18, 2011

Precept 2 Aleksey Boyko February 18, 2011 Precept 2 Aleksey Boyko February 18, 2011 Getting started Initialization Drawing Transformations Cameras Animation Input Keyboard Mouse Joystick? Textures Lights Programmable pipeline elements (shaders)

More information

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실. Graphics Texture Mapping 고려대학교컴퓨터그래픽스연구실 3D Rendering Pipeline 3D Primitives 3D Modeling Coordinates Model Transformation 3D World Coordinates Lighting 3D World Coordinates Viewing Transformation 3D Viewing

More information

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008 CS559: Computer Graphics Lecture 12: OpenGL Li Zhang Spring 2008 Reading Redbook Ch 1 & 2 So far: 3D Geometry Pipeline Model Space (Object Space) Rotation Translation Resizing World Space M Rotation Translation

More information

Computer Graphics Introduction to OpenGL

Computer Graphics Introduction to OpenGL Computer Graphics 2015 3. Introduction to OpenGL Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2015-09-28 2. 2D Graphics Algorithms (cont.) Rasterization Computer Graphics @ ZJU Hongxin Zhang,

More information

Graphics Pipeline & APIs

Graphics Pipeline & APIs Graphics Pipeline & APIs CPU Vertex Processing Rasterization Fragment Processing glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glpushmatrix (); gltranslatef (-0.15, -0.15, solidz); glmaterialfv(gl_front,

More information

Lecture 07: Buffers and Textures

Lecture 07: Buffers and Textures Lecture 07: Buffers and Textures CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA October 26, 2010 OpenGL Pipeline Today s Focus Pixel Buffers: read and write image data to and from

More information

Imaging and Raster Primitives

Imaging and Raster Primitives Realtime 3D Computer Graphics & Virtual Reality Bitmaps and Textures Imaging and Raster Primitives Vicki Shreiner Imaging and Raster Primitives Describe OpenGL s raster primitives: bitmaps and image rectangles

More information

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API) CSCI 420 Computer Graphics Lecture 2 Basic Graphics Programming Teaching Assistant Yijing Li Office hours TBA Jernej Barbic University of Southern California Graphics Pipeline OpenGL API Primitives: Lines,

More information

Graphics Pipeline & APIs

Graphics Pipeline & APIs 3 2 4 Graphics Pipeline & APIs CPU Vertex Processing Rasterization Processing glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glpushmatrix (); gltranslatef (-0.15, -0.15, solidz); glmaterialfv(gl_front,

More information

Graphics Hardware and OpenGL

Graphics Hardware and OpenGL Graphics Hardware and OpenGL Ubi Soft, Prince of Persia: The Sands of Time What does graphics hardware have to do fast? Camera Views Different views of an object in the world 1 Camera Views Lines from

More information

Computer Graphics Primitive Attributes

Computer Graphics Primitive Attributes Computer Graphics 2015 4. Primitive Attributes Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2015-10-12 Previous lessons - Rasterization - line - circle /ellipse? => homework - OpenGL and

More information

Programming with OpenGL Part 1: Background

Programming with OpenGL Part 1: Background Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Development of the OpenGL API

More information

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt CS334 Fall 2015 Daniel G. Aliaga Department of Computer Science Purdue University Books (and by now means complete ) Interactive Computer

More information

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL Visual Computing and Multimedia Abel J. P. Gomes 1. Getting Started 2. Installing Graphics Libraries: OpenGL and GLUT 3. Setting up an IDE to run graphics programs in OpenGL/GLUT 4. A First OpenGL/GLUT

More information

Introduction to OpenGL

Introduction to OpenGL Introduction to OpenGL Banafsheh Azari http://www.uni-weimar.de/cms/medien/cg.html What You ll See Today What is OpenGL? Related Libraries OpenGL Command Syntax B. Azari http://www.uni-weimar.de/cms/medien/cg.html

More information

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

GRAFIKA KOMPUTER. ~ M. Ali Fauzi GRAFIKA KOMPUTER ~ M. Ali Fauzi Texture Mapping WHY TEXTURE? Imagine a Chess Floor Or a Brick Wall How to Draw? If you want to draw a chess floor, each tile must be drawn as a separate quad. A large flat

More information

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

GLUT. What is OpenGL? Introduction to OpenGL and GLUT What is OpenGL? Introduction to OpenGL and An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality h color images composed of geometric and image primitives

More information

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL Today s Agenda Basic design of a graphics system Introduction to OpenGL Image Compositing Compositing one image over another is most common choice can think of each image drawn on a transparent plastic

More information

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++ Computer Graphics Graphics Programming August 31, 2005 Contents Our Goal in This Chapter Programming of the Sierpinski gasket How To? Programming with OpenGL and C/C++ OpenGL API (Application Programmer

More information

Rendering. Part 1 An introduction to OpenGL

Rendering. Part 1 An introduction to OpenGL Rendering Part 1 An introduction to OpenGL Olivier Gourmel VORTEX Team IRIT University of Toulouse gourmel@irit.fr Image synthesis The Graphics Processing Unit (GPU): A highly parallel architecture specialized

More information

Computer Graphics (Basic OpenGL)

Computer Graphics (Basic OpenGL) Computer Graphics (Basic OpenGL) Thilo Kielmann Fall 2008 Vrije Universiteit, Amsterdam kielmann@cs.vu.nl http://www.cs.vu.nl/ graphics/ Computer Graphics (Basic OpenGL, Input and Interaction), ((57))

More information

Lectures OpenGL Introduction

Lectures OpenGL Introduction Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma State University Rohnert Park, California 2004, Tom Duff and George Ledin Jr 1 What is

More information

Computer graphic -- Programming with OpenGL I

Computer graphic -- Programming with OpenGL I Computer graphic -- Programming with OpenGL I A simple example using OpenGL Download the example code "basic shapes", and compile and run it Take a look at it, and hit ESC when you're done. It shows the

More information

An Interactive Introduction to OpenGL Programming

An Interactive Introduction to OpenGL Programming An Interactive Introduction to OpenGL Programming Course # 29 Dave Shreiner Ed Angel Vicki Shreiner Table of Contents Introduction...iv Prerequisites...iv Topics...iv Presentation Course Notes...vi An

More information

COMPUTER GRAPHICS LAB # 3

COMPUTER GRAPHICS LAB # 3 COMPUTER GRAPHICS LAB # 3 Chapter 2: COMPUTER GRAPHICS by F.S HILLs. Initial steps in drawing figures (polygon, rectangle etc) Objective: Basic understanding of simple code in OpenGL and initial steps

More information

2 Transformations and Homogeneous Coordinates

2 Transformations and Homogeneous Coordinates Brief solutions to Exam in Computer Graphics Time and place: 08:00 3:00 Tuesday March 7, 2009, Gimogatan 4, sal Grades TD388: 3: 20pts; 4: 26pts; 5: 34pts. Glossary API Application Programmer s Interface.

More information

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II Emmanuel Agu Recall: OpenGL Skeleton void main(int argc, char** argv){ // First initialize toolkit, set display mode and create window glutinit(&argc,

More information

An Overview GLUT GLSL GLEW

An Overview GLUT GLSL GLEW OpenGL, GLUT, GLEW, GLSL An Overview GLUT GLEW GLSL Objectives Give you an overview of the software that you will be using this semester OpenGL, GLUT, GLEW, GLSL What are they? How do you use them? What

More information

Computer graphics MN1

Computer graphics MN1 Computer graphics MN1 http://www.opengl.org Todays lecture What is OpenGL? HowdoI useit? Rendering pipeline Points, vertices, lines, polygons Matrices and transformations Lighting and shading Code examples

More information

Rendering Pipeline/ OpenGL

Rendering Pipeline/ OpenGL Chapter 2 Basics of Computer Graphics: Your tasks for the weekend Piazza Discussion Group: Register Post review questions by Mon noon Use private option, rev1 tag Start Assignment 1 Test programming environment

More information

Texture Mapping. Mike Bailey.

Texture Mapping. Mike Bailey. Texture Mapping 1 Mike Bailey mjb@cs.oregonstate.edu This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License TextureMapping.pptx The Basic Idea

More information

OpenGL. Toolkits.

OpenGL. Toolkits. http://www.opengl.org OpenGL Open Graphics Library Graphics API Delivered with UNIX, Win9x/2000/Me/Nt/Xp, Mac OS Direct3D (DirectX) is only Windows Utilizes the window system and event handling of the

More information

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display CMSC 427: Chapter 2 Graphics Libraries and OpenGL Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Graphics Libraries OpenGL and its Structure Drawing Primitives in OpenGL GLUT

More information

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field Cameras (and eye) Ideal Pinhole Real Pinhole Real + lens Depth of field 1 Z-buffer How do we draw objects? Polygon Based Fast Raytracing Ray/Object intersections Slow Copyright Pixar 2 Raytracing for each

More information

An Interactive Introduction to OpenGL and OpenGL ES Programming. Ed Angel Dave Shreiner

An Interactive Introduction to OpenGL and OpenGL ES Programming. Ed Angel Dave Shreiner An Interactive Introduction to OpenGL and OpenGL ES Programming Ed Angel Dave Shreiner Welcome This morning s Goals and Agenda Describe the OpenGL APIs and their uses Demonstrate and describe OpenGL s

More information

QUESTION 1 [10] 2 COS340-A October/November 2009

QUESTION 1 [10] 2 COS340-A October/November 2009 2 COS340-A QUESTION 1 [10] a) OpenGL uses z-buffering for hidden surface removal. Explain how the z-buffer algorithm works and give one advantage of using this method. (5) Answer: OpenGL uses a hidden-surface

More information

Drawing Primitives. OpenGL basics

Drawing Primitives. OpenGL basics CSC 706 Computer Graphics / Dr. N. Gueorguieva 1 OpenGL Libraries Drawing Primitives OpenGL basics OpenGL core library OpenGL32 on Windows GL on most unix/linux systems (libgl.a) OpenGL Utility Library

More information

Computer Graphics Programming

Computer Graphics Programming Computer Graphics Programming Graphics APIs Using MFC (Microsoft Foundation Class) in Visual C++ Programming in Visual C++ GLUT in Windows and Unix platform Overview and Application Graphics APIs Provide

More information

CS452/552; EE465/505. Texture Mapping in WebGL

CS452/552; EE465/505. Texture Mapping in WebGL CS452/552; EE465/505 Texture Mapping in WebGL 2-26 15 Outline! Texture Mapping in WebGL Read: Angel, Chapter 7, 7.3-7.5 LearningWebGL lesson 5: http://learningwebgl.com/blog/?p=507 Lab3 due: Monday, 3/2

More information

Using OpenGL with CUDA

Using OpenGL with CUDA Using OpenGL with CUDA Installing OpenGL and GLUT; compiling with nvcc Basics of OpenGL and GLUT in C Interoperability between OpenGL and CUDA OpenGL = Open Graphic Library creation of 3D graphic primitives

More information

3D computer graphics: geometric modeling of objects in the computer and rendering them

3D computer graphics: geometric modeling of objects in the computer and rendering them SE313: Computer Graphics and Visual Programming Computer Graphics Notes Gazihan Alankus, Spring 2012 Computer Graphics 3D computer graphics: geometric modeling of objects in the computer and rendering

More information

Introduction to OpenGL

Introduction to OpenGL CS100433 Introduction to OpenGL Junqiao Zhao 赵君峤 Department of Computer Science and Technology College of Electronics and Information Engineering Tongji University Before OpenGL Let s think what is need

More information

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008 CS559: Computer Graphics Lecture 2: OpenGL Transformation Li Zhang Spring 28 Today Transformation in OpenGL Reading Chapter 3 Last time Primitive Details glpolygonmode(glenum face, GLenum mode); face:

More information

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010) Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3 http://inst.eecs.berkeley.edu/~cs184 Methodology for Lecture Lecture deals with lighting (teapot shaded as in HW1) Some Nate

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program Comp 410/510 Computer Graphics Spring 2017 Programming with OpenGL Part 2: First Program Objectives Refine the first program Introduce a standard program structure - Initialization Program Structure Most

More information

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson Syllabus 1) First program and introduction to data types and control structures with applications for games learning how to use the programming

More information

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015 Buffers 1 Objectives Introduce additional WebGL buffers Reading and writing buffers Buffers and Images 2 Buffer Define a buffer by its spatial resolution (n x m) and its depth (or precision) k, the number

More information

Computer Graphics Course 2005

Computer Graphics Course 2005 Computer Graphics Course 2005 Introduction to GLUT, GLU and OpenGL Administrative Stuff Teaching Assistant: Rony Goldenthal Reception Hour: Wed. 18:00 19:00 Room 31 (Ross 1) Questions: E-mail: cg@cs Newsgroups:

More information

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives Programming with OpenGL Part 1: Background Early History of APIs Objectives Development of the OpenGL API OpenGL Architecture - OpenGL as a state machine Functions - Types -Formats Simple program IFIPS

More information

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016 Announcements Tomorrow: assignment 1 due Grading

More information

Lecture 4 Advanced Computer Graphics (CS & SE )

Lecture 4 Advanced Computer Graphics (CS & SE ) Lecture 4 Advanced Computer Graphics (CS & SE 233.420) Topics Covered Animation Matrices Viewing Lighting Animating Interactive Programs Consider planet.c Want to animate rotating the Earth around the

More information

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009 s The s Lecture 22 Sections 8.8, 8.9, 8.10 Hampden-Sydney College Wed, Oct 28, 2009 Outline s The 1 2 3 4 5 The 6 7 8 Outline s The 1 2 3 4 5 The 6 7 8 Creating Images s The To create a texture image internally,

More information

Programming with OpenGL Part 1: Background

Programming with OpenGL Part 1: Background Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Development of the OpenGL API

More information