Introduction To Modern OpenGL

Size: px
Start display at page:

Download "Introduction To Modern OpenGL"

Transcription

1 Introduction To Modern OpenGL

2 How OpenGL Works OpenGL uses a series of matrices to control the position and way primitives are drawn OpenGL 1.x - 2.x allows these primitives to be drawn in two ways immediate mode core profile (this mode uses buffer objects to retain the data and is sometimes called retained mode)

3 Immediate Mode In immediate mode the vertices to be processed are sent to the GPU (Graphics Card) one at a time. This means there is a bottleneck between CPU and GPU whilst data is sent This method is easy to use but not very efficient Immediate mode has become deprecated as part of OpenGL 3.x and is not available in OpenGL ES

4 Core Profile Mode In this mode the data to be drawn is sent to the GPU and stored in graphics memory. A pointer to this object is returned to the user level program and this object reference is called when drawing etc. This requires a little more setup but does improve the Frame Rate considerably. For most of the examples we will use this mode. This is also the way DirectX works

5 GLSL OpenGL Shading Language is a high level shading language based on C It allows us to program directly on the GPU and can be used for Shading calculations for vertex and fragment based processing. We will look at this in more detail later but to use the full OpenGL 3.x functionality we need to also create a GLSL shader and process the vertices on the GPU Using GLSL we can also manipulate the actual vertices of the system.

6 Immediate Mode OpenGL provides tools for drawing many different primitives, including Points, Lines Quads etc. Most of them are described by one or more vertices. In OpenGL we describe a list of vertices by using the glbegin() and glend() functions. The argument to the glbegin() function determines how the vertices passed will be drawn. We will not be using this mode and most examples on the web will use this

7 OpenGL Profiles The current OpenGL version is 4.5, it has full compatibility with OpenGL ES 3.0 for embedded devices There are two profiles associated with this version Core Profile Compatibility profile

8 OpenGL 4.5 Core Released 2014 (see History_of_OpenGL) The Core profile is very new and many GPU s do not fully support this This profile doesn t contain any of the immediate mode GL elements and has no backward compatibility Will not be fully available in drivers / GPU cores for a while

9 OpenGL 4 Compatibility The compatibility profile contains lots of OpenGL immediate mode elements as well as earlier GLSL structures and components This means legacy code will still work with the drivers but may not be optimal This year the ngl library has been ported to work with only OpenGL 3.2 core profile. This needs Mac OSX Lion, linux or window with the latest drivers. There is now also a port for ios 5 / OpenGL ES2.0 and Raspberry Pi / EGL

10 Compatibility Profile The main problem with the compatibility profile is there are no clear guidelines on the implementation Different vendors behave differently Usually the whole system will fall back to the software implementation (not on the GPU)

11 Programmers view of OpenGL To the programmer, OpenGL is a set of commands that allow the specification of geometric objects in two or three dimensions, together with commands that control how these objects are rendered into the framebuffer. A typical program that uses OpenGL begins with calls to open a window into the framebuffer. (in our case using Qt) Once a GL context is allocated, the programmer is free to issue OpenGL commands.

12 Programmers view of OpenGL Some calls are used to draw simple geometric objects (i.e. points, line segments, and polygons) Others affect the rendering of these primitives including how they are lit or coloured and how they are mapped from the user s two- or threedimensional model space to the two-dimensional screen. There are also calls to effect direct control of the framebuffer, such as reading and writing pixels.

13 Client Server Model The model for interpretation of OpenGL commands is client-server. That is, a program (the client) issues commands, and these commands are interpreted and processed by the OpenGL (the server). The server may or may not operate on the same computer as the client. In this sense, the GL is network-transparent. A server may maintain a number of OpenGL contexts, each of which is an encapsulation of current GL state.

14 OpenGL Context before we can use OpenGL we need to generate an OpenGL context This initialises the GL state and other elements of the library This is not the responsibility of OpenGL to create this and varies in the different Operating systems There are many ways to create the context but I will concentrate on two methods Qt 5 SDL 2

15 OpenGL Context Both Qt and SDL work well on multiple platforms to create an OpenGL context Qt is best for GUI / Windowed based systems SDL is perfect for games and also has Joystick / Gamepad interfaces As Modern OpenGL is quite complex I will start with creating a compatibility profile OpenGL Demo and expand to core profile once we learn some more OpenGL

16 SDL To quote the SDL website ( "Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power." SDL is ideal for game so if you want to do some games programming use SDL over Qt

17 sdl2-config When sdl is installed a script called sdl2-config is placed in the /usr/bin directory This script can be run to get the correct build flags for sdl there is also an sdl-config for earlier SDL 1.x libs as well sdl2-config --cflags --libs -I/usr/local/include/SDL2 -I/usr/X11R6/include -D_THREAD_SAFE -L/usr/local/lib -lsdl2

18 #include <SDL.h> #if defined (LINUX) defined (WIN32) #include <GL/gl.h> #include <GL/glu.h> #endif #ifdef DARWIN #include <unistd.h> #include <OpenGL/gl.h> #include <OpenGL/glu.h> #endif Depending upon platform gl.h is in different directories use Compiler -D switch to define OS for example -D DARWIN will use mac includes

19 SDL Window // now create our window SDL_Window *window=sdl_createwindow("sdlngl", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, rect.w/2, rect.h/2, SDL_WINDOW_OPENGL SDL_WINDOW_RESIZABLE ); // check to see if that worked or exit if (!window) { SDLErrorExit("Unable to create window"); } // Create our opengl context and attach it to our window } SDL_GLContext glcontext=createopenglcontext(window); if(!glcontext) { SDLErrorExit("Problem creating OpenGL context"); } // make this our current GL context (we can have more than one window but in this case not) SDL_GL_MakeCurrent(window, glcontext); /* This makes our buffer swap syncronized with the monitor' s vertical refresh */ SDL_GL_SetSwapInterval(1);

20 OpenGL Context SDL_GLContext createopenglcontext(sdl_window *window) { // Request an opengl 3.2 context first we setup our attributes, if you need any // more just add them here before the call to create the context // SDL doesn't have the ability to choose which profile at this time of writing, // but it should default to the core profile // for some reason we need this for mac but linux crashes on the latest nvidia drivers // under centos #ifdef DARWIN SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); #endif // set multi sampling else we get really bad graphics that alias SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4); // Turn on double buffering with a 24bit Z buffer. // You may need to change this to 16 or 32 for your system // on mac up to 32 will work but under linux centos build only 16 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); // enable double buffering (should be on by default) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // return SDL_GL_CreateContext(window); }

21 SDL_GLContext glcontext=createopenglcontext(window); if(!glcontext) { SDLErrorExit("Problem creating OpenGL context"); } // make this our current GL context (we can have more than one window but in this case not) SDL_GL_MakeCurrent(window, glcontext); /* This makes our buffer swap syncronized with the monitor's vertical refresh */ SDL_GL_SetSwapInterval(1); // now setup a basic camera for viewing glclear(gl_color_buffer_bit); glmatrixmode(gl_projection); gluperspective(45,(float)rect.w/rect.h,0.5,100); glmatrixmode(gl_modelview); glulookat(2,2,2,0,0,0,0,1,0); loop {... process events } // now clear screen and render glclear(gl_color_buffer_bit); // draw a triangle drawtriangle(); // swap the buffers SDL_GL_SwapWindow(window);

22 void drawtriangle() { static int rot=0; glpushmatrix(); glrotated(rot,0,1,0); glbegin(gl_triangles); glcolor3f(1,0,0); glvertex3d(0,1,0); glcolor3f(0,1,0); glvertex3d(1,-1,0); glcolor3f(0,0,1); glvertex3d(-1,-1,0); glend(); glpopmatrix(); ++rot; }

23 Qt 5.5 Qt 4 had a specific GLWidget for creating an OpenGL context Qt 5 improves on this by extending the basic window to allow the usage of OpenGL rendering (as well as others) Qt5 uses a QSurface as an abstraction for a rendering surface all we have to do is setup an OpenGL context and create a surface Qt5 also has a number of OpenGL functions encapsulated into Qt itself we will not be using this as the ngl:: library already has these.

24 } // create an OpenGL format specifier QSurfaceFormat format; // set the number of samples for multisampling // will need to enable glenable(gl_multisample); once we have a context format.setsamples(4); #if defined( APPLE ) // at present mac osx Mountain Lion only supports GL3.2 // the new mavericks will have GL 4.x so can change format.setmajorversion(4); format.setminorversion(1); #else // with luck we have the latest GL version so set to that format.setmajorversion(4); format.setminorversion(5); #endif // now we are going to set to CoreProfile OpenGL so we can' t use and old Immediate mode GL format.setprofile(qsurfaceformat::coreprofile); // now set the depth buffer to 24 bits format.setdepthbuffersize(24); // set that as the default format for all windows QSurfaceFormat::setDefaultFormat(format);

25 QOpenGLWindow / Widget We inherit from these classes and implement our own OpenGL functions. The Window is a stand alone window class with an OpenGL context / drawing area The Widget is used within another window to allow use to develop GUI and OpenGL components together. Both are very similar and have the same virtual methods for us to override.

26 initalizegl This is called once when the OpenGL context has been created (after the window has been created but before the first call to paintgl) We usually use this for initialisation of OpenGL specific things (loading shaders, creating geo etc) which will need to have an active context. Always start timers in this method and not the ctor as if the timer function called paint GL it may crash if not valid context is present. This is also where we will need to load extensions etc (usually using GLEW or ngl::nglinit::instance();

27 resizegl(int _w, int _h) This is merely a convenience function in order to provide an API that is compatible with QOpenGLWidget. Unlike with QOpenGLWidget, derived classes are free to choose to override resizeevent() instead of this function. Avoid issuing OpenGL commands from this function as there may not be a context current when it is invoked. If it cannot be avoided, call makecurrent(). Also worth noting we may need to take into account devicepixelratio() for retina displays (for SDL you have to use platform specific function calls)

28 resizegl(qresizeevent *_event) Use this event to set width and height attributes (we can call width() / height()) Usually I set a class attribute then call glviewport each frame before drawing m_width=_event->size().width()*devicepixelratio(); m_height=_event->size().height()*devicepixelratio();

29 paintgl This method is called every time update() is called on the window (and is usually synched to vsynch of the monitor but this can be changed). This is usually used for drawing our scene and other operations. Depending upon advanced OpenGL usage we may need to think about which context we are using as well as which RenderBuffer etc as Qt uses it s own internal states as well.

30 GL Command Syntax GL commands are functions or procedures. Various groups of commands perform the same operation but differ in how arguments are supplied to them. To specify the type of parameter GL uses a specific syntax GL commands are formed from a name which may be followed, depending on the particular command, by a sequence of characters describing a parameter to the command. If present, a digit indicates the required length (number of values) of the indicated type. Next, a string of characters making up one of the type descriptors

31 GL Command Syntax A final v character, if present, indicates that the command takes a pointer to an array (a vector) of values rather than a series of individual arguments.

32 GL Command Syntax gl Library command name 4f 4 floats 1 void gluniform4f( int location, float v0, float v1, float v2, float v3 ); void glgetfloatv( enum value, float *data ); v array pointer

33 Block Diagram of OpenGL To aid learning we will concentrate on each of Transform Feedback the elements in turn Ignoring the others and assuming they just work Vertex Data Pixel Data Vertex Shading and Per-Vertex Operations Primitive Assembly and Rasterization Fragment Shading and Per-Fragment Operations Framebuffer out of the box without Texture Memory setup Pixel Pack / Unpack Finally we shall put the whole system together

34 Block Diagram of OpenGL Vertex Data Vertex Shading and Per-Vertex Operations Transform Feedback Primitive Assembly and Rasterization Fragment Shading and Per-Fragment Operations Framebuffer Pixel Data Texture Memory Pixel Pack / Unpack Commands enter the GL on the left. Some commands specify geometric objects to be drawn while others control how the objects are handled by the various stages. Commands are effectively sent through a processing pipeline. The first stage operates on geometric primitives described by vertices: points, line segments, and polygons. In this stage vertices may be transformed and lit, followed by assembly into geometric primitives, which may optionally be used by the next stage, geometry shading, to generate new primitives.

35 Block Diagram of OpenGL Vertex Data Vertex Shading and Per-Vertex Operations Transform Feedback Primitive Assembly and Rasterization Fragment Shading and Per-Fragment Operations Framebuffer Pixel Data Texture Memory Pixel Pack / Unpack The final resulting primitives are clipped to a viewing volume in preparation for the next stage, rasterization. The rasterizer produces a series of framebuffer addresses and values using a two-dimensional description of a point, line segment, or polygon. Each fragment produced is fed to the next stage that performs operations on individual fragments before they finally alter the framebuffer. Finally, values may also be read back from the framebuffer or copied from one portion of the framebuffer to another.

36 coordinates Primitives and Vertices Vertex Shader Execution Shaded Vertices Point, Line Segment, or Triangle (Primitive) Assembly Point culling, Line Segment or Triangle Clipping Rasterization varying outputs In the OpenGL, most geometric objects are drawn by specifying a series of generic attribute sets using DrawArrays Generic Vertex Attributes Primitive type (from DrawArrays or DrawElements mode) or one of the other drawing commands. Points, lines, polygons, and a variety of related geometric objects can be drawn in this way.

37 Primitives and Vertices Each vertex is specified with one or more generic vertex attributes. Each attribute is specified with one, two, three, or four scalar values. Generic vertex attributes can be accessed from within vertex shaders and used to compute values for consumption by later processing stages. For example we may set vertex colour, vertex normals, texture coordinates or generic vertex attributes used by the processing shader

38 Primitive types OpenGL has a number of primitive types that can be specified to DrawArrays and other primitive drawing commands These are Points, Line Strips, Line Loops, Separate Lines,Triangle Strips, Triangle Fans, Separate Triangles, Lines with adjacency, Line Strips with Adjacency, Triangles with Adjacency, Triangle Strips with Adjacency, Separate Patches We will investigate these elements later for now we will concentrate on drawing some points

39 Vertex Arrays Vertex data is placed into arrays that are stored in the server s address space (GPU). Blocks of data in these arrays may then be used to specify multiple geometric primitives through the execution of a single OpenGL command. The client may specify up to the value of MAX_VERTEX_ATTRIBS arrays to store one or more generic vertex attributes.

40 Vertex Arrays Vertex arrays are a simple way of storing data for models so that Vertices, normals and other information may be shared. This allows a more compact representation of data and reduces the number of calls OpenGL needs to make and the reduction of data stored. We can create the data in a series of arrays either procedurally or by loading it from some model format The data may then be stored either by downloading it to the GPU or storing it on the client side and telling the GPU to bind to it.

41 Example Drawing Points The following example will draw a series of points to the OpenGL context m_points = new GLfloat[3*s_numPoints]; The data is stored on the client side (our program) We need to create the data (3xGLfloat values) in an array Then tell OpenGL where this data is and draw it x y z x y z... Create data Enable Vertex Arrays and Draw

42 Create the Data GLfloat *m_points; in OpenGLWindow.h const static int s_numpoints=10000; // first we generate random point x,y,z values m_points = new GLfloat[2*s_numPoints]; for( int i=0; i<2*s_numpoints; ++i) { m_points[i]= -1.0f + (float)rand()/((float) RAND_MAX/(1.0f- -1.0f)); } in ctor we allocate some random x,y,z values

43 Drawing the Data tell GL we are using void OpenGLWindow::render() { // usually we will make this context current and render m_context->makecurrent(this); // clear the screen and depth buffer glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glenableclientstate(gl_vertex_array); Vertex Arrays } glvertexpointer(2, GL_FLOAT, 0, m_points); gldrawarrays(gl_points,0,s_numpoints); gldisableclientstate(gl_vertex_array); // finally swap the buffers to make visible m_context->swapbuffers(this); tell GL where the data is on the client Now Draw

44 glvertexpointer 1 void glvertexpointer( GLint size,glenum type,glsizei stride,const GLvoid *pointer); size :- the number of coordinates per vertex. Must be 2, 3, or 4. The initial value is 4. type :- the data type of each coordinate in the array. Symbolic constants GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE are accepted. default : GL_FLOAT. stride :- the byte offset between consecutive vertices. If stride is 0, the vertices are understood to be tightly packed in the array. default : 0 pointer :- a pointer to the first coordinate of the first vertex in the array. default : 0.

45 glvertexpointer glvertexpointer has been marked for deprecation At present it works but the new method of drawing is a lot more complex and requires different shaders to be developed. We usually do not use client side data anyway so this is just serving as an example before we add to the overall GL construction required for GL 3.x functionality We will expand on the new functions later

46 gldrawarrays 1 void gldrawarrays( GLenum mode,glint first,glsizei count); mode :- what kind of primitives to render. Symbolic constants GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON are accepted. first :- the starting index in the enabled arrays. count :- the number of indices to be rendered.

47 ARB and GLEW ARB stands for Architecture review board and are extensions authorised by the OpenGL standards group Most of these extensions are part of the OpenGL driver for the GPU installed and we need to make link between the driver binary library and the OpenGL code we are writing This process is quite complex and to make it easier we can use GLEW (not required on Mac OSX) The ngl::init class contains the following code to do this

48 Initialising GLEW 1 // we only need glew on linux mac ok (should add a windows ref as well) 2 #if defined(linux) defined(win32) 3 { 4 GLenum err = glewinit(); 5 if (GLEW_OK!= err) 6 { 7 /* Problem: glewinit failed, something is seriously wrong. */ 8 std::cerr<< "Error: "<<glewgeterrorstring(err)<<std::endl; 9 exit(exit_failure); 10 } 11 std::cerr<<"status: Using GLEW "<<glewgetstring(glew_version)<<std::endl; 12 } 13 #endif

49 Adding Extensions 1 // make sure you've included glext.h 2 extern PFNGLISRENDERBUFFEREXTPROC glisrenderbufferext; 3 4 and in one c/cpp file: 5 PFNGLISRENDERBUFFEREXTPROC glisrenderbufferext; 6 7 // now bind the address from the driver to our function pointer 8 9 glisrenderbufferext = glxgetprocaddressarb((const GLubyte*)"glIsRenderbufferEXT"); For every function we need to access we have to write some code similar to the lines above This is quite tedious so GLEW does it for us

50 Adding Colour The process of adding Colour is similar to that of setting the vertices We create a single array of per-vertex RGB values We then create a pointer to this and draw using the same draw command m_colours = new GLfloat[3*s_numPoints]; for( int i=0; i<3*s_numpoints; ++i) { m_colours[i]= 0.0f + (float)rand()/((float)rand_max/(1.0f)); }

51 Adding Colour void OpenGLWindow::render() { // usually we will make this context current and render m_context->makecurrent(this); // clear the screen and depth buffer glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glenableclientstate(gl_vertex_array); glenableclientstate(gl_color_array); glvertexpointer(2, GL_FLOAT, 0, m_points); glcolorpointer(3,gl_float,0,m_colours); gldrawarrays(gl_points, 0, s_numpoints); gldisableclientstate(gl_vertex_array); gldisableclientstate(gl_color_array); // finally swap the buffers to make visible m_context->swapbuffers(this); }

52 Other Primitives void OpenGLWindow::render() { // usually we will make this context current and render m_context->makecurrent(this); // clear the screen and depth buffer glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glenableclientstate(gl_vertex_array); glenableclientstate(gl_color_array); glvertexpointer(2, GL_FLOAT, 0, m_points); glcolorpointer(3,gl_float,0,m_colours); gldrawarrays(gl_triangles, 0, s_numpoints/3); gldisableclientstate(gl_vertex_array); gldisableclientstate(gl_color_array); // finally swap the buffers to make visible m_context->swapbuffers(this); }

53 Problems Although this method works, it is still slow. Each frame the client (our program) has to send the data to the server (GPU) If we increase the s_numpoints constant to about 3000 the program slows to a halt We really need to create a faster method of doing things

54 Vertex Buffer Objects The idea behind VBOs is to provide regions of memory (buffers) accessible through identifiers. A buffer is made active through binding, following the same pattern as other OpenGL entities such as display lists or textures. Data is effectively stored on the GPU for execution and this greatly increases the speed of drawing.

55 VBO Allocation and process Create VBO (once) Draw VBO (many times) Get a Buffer ID Enable Arrays Data deleted once bound Bind Buffer Vertex Data Bind to Buffer set pointer Stored on GPU draw disable Arrays

56 Data Packing We can pack the data in a number of ways for passing to the VBO The two simplest schemes are All Vertex Data - All Normal Data - All Texture Data etc etc Alternatively we can pack the data by interleaving the data in a number of pre-determined GL formats For the following examples we will use the 1st format.

57 Grid in OpenGLWindow.h 1 a simple draw grid function 2 _size the size of the grid (width and height) 3 _step sxstep the spacing between grid points 4 o_datasize the size of the buffer allocated 5 a pointer to the allocated VBO 6 GLuint MakeGrid( 7 GLfloat _size, 8 int _steps, 9 int &o_datasize 10 ); 11 a pointer to our VBO data 12 GLuint m_vbopointer; 13 store the size of the vbo data 14 GLint m_vbosize; 1 const static float gridsize=1.5; 2 const static int steps=24;

58 1 // allocate enough space for our verts 2 // as we are doing lines it will be 2 verts per line 3 // and we need to add 1 to each of them for the <= loop 4 // and finally muliply by 12 as we have 12 values per line pair 5 o_datasize= (_steps+2)*12; 6 float *vertexdata= new float[o_datasize]; 7 // k is the index into our data set 8 int k=-1; 9 // claculate the step size for each grid value 10 float step=_size/(float)_steps; 11 // pre-calc the offset for speed 12 float s2=_size/2.0f; 13 // assign v as our value to change each vertex pair 14 float v=-s2; 15 // loop for our grid values 16 for(int i=0; i<=_steps; ++i) 17 { 18 // vertex 1 x,y,z 19 vertexdata[++k]=-s2; // x 20 vertexdata[++k]=v; // y 21 vertexdata[++k]=0.0; // z // vertex 2 x,y,z 24 vertexdata[++k]=s2; // x 25 vertexdata[++k]=v; // y 26 vertexdata[++k]=0.0; // z // vertex 3 x,y,z 29 vertexdata[++k]=v; 30 vertexdata[++k]=s2; 31 vertexdata[++k]=0.0; // vertex 4 x,y,z 34 vertexdata[++k]=v; 35 vertexdata[++k]=-s2; 36 vertexdata[++k]=0.0; 37 // now change our step value 38 v+=step; 39 } Creating Data for vertices Vertex 0 x,y,z Vertex 1 x,y,z vertexdata[] V0 X V0 Y V0 Z V1 X V1 Y V1 Z...

59 Binding the data 1 // now we will create our VBO first we need to ask GL for an Object ID 2 GLuint VBOBuffers; 3 // now create the VBO 4 glgenbuffers(1, &VBOBuffers); 5 // now we bind this ID to an Array buffer 6 glbindbuffer(gl_array_buffer, VBOBuffers); 7 // finally we stuff our data into the array object 8 // First we tell GL it's an array buffer 9 // then the number of bytes we are storing (need to tell it's a sizeof(float) 10 // then the pointer to the actual data 11 // Then how we are going to draw it (in this case Statically as the data will not change) 12 glbufferdata(gl_array_buffer, o_datasize*sizeof(gl_float), vertexdata, GL_STATIC_DRAW); // now we can delete our client side data as we have stored it on the GPU 15 delete [] vertexdata; 16 // now return the VBO Object pointer to our program so we can use it later for drawing 17 return VBOBuffers; Now we bind the data onto the GPU and once this is done we can delete the client side data as it s not needed

60 Building the Grid We must have a valid GL context before we can call this function, and if required we must initialise GLEW void OpenGLWindow::initialize() { m_context->makecurrent(this); glclearcolor(0.0f, 0.0f, 0.0f, 1.0f); m_vbopointer=makegrid(gridsize,steps,m_vbosize); }

61 Drawing the buffer void OpenGLWindow::render() { if(!m_initialized) { initialize(); m_initialized=true; } // usually we will make this context current and render m_context->makecurrent(this); glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); // enable vertex array drawing glenableclientstate(gl_vertex_array); // bind our VBO data to be the currently active one glbindbuffer(gl_array_buffer, m_vbopointer); // tell GL how this data is formated in this case 3 floats tightly packed starting at the begining // of the data (0 = stride, 0 = offset) glvertexpointer(3,gl_float,0,0); // draw the VBO as a series of GL_LINES starting at 0 in the buffer and _vbosize*glfloat gldrawarrays( GL_LINES, 0, m_vbosize); } // now turn off the VBO client state as we have finished with it gldisableclientstate(gl_vertex_array); // finally swap the buffers to make visible m_context->swapbuffers(this);

62 Vertex arrays To enable the use of vertex arrays we need very few steps as shown below 1. Invoke the function glenableclientstate(gl_vertex_array); to activate the vertex-array feature of OpenGL 2. Use the function glvertexpointer to specify the location and data format for the vertex co-ordinates 3. Display the scene using a routine such as gldrawarraysinstancedarb

63 A Cube This cube has vertex colours and vertex normals

64 Cube Vertices 1 // vertex coords array 2 GLfloat vertices[] = { 3 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0-v1-v2-v3 4 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0-v3-v4-v5 5 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0-v5-v6-v1 6-1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1-v6-v7-v2 7-1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7-v4-v3-v2 8 1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 // v4-v7-v6-v5 9 }; V6 V1 V5 The array above stores the vertices for a unit cube in face order of quads V7 V0 V4 V2 V3

65 Vertex Normals 1 // normal array 2 GLfloat normals[] = { 3 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 4 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 5 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 6-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 7 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7-v4-v3-v2 8 0, 0,-1, 0, 0, -1, 0, 0,-1, 0, 0,-1 // v4-v7-v6-v5 9 }; This array stores the normals for each vertex

66 Vertex Colour Array 1 // color array 2 GLfloat colours[] = 3 { 4 1,1,1, 1,1,0, 1,0,0, 1,0,1, // v0-v1-v2-v3 5 1,1,1, 1,0,1, 0,0,1, 0,1,1, // v0-v3-v4-v5 6 1,1,1, 0,1,1, 0,1,0, 1,1,0, // v0-v5-v6-v1 7 1,1,0, 0,1,0, 0,0,0, 1,0,0, // v1-v6-v7-v2 8 0,0,0, 0,0,1, 1,0,1, 1,0,0, // v7-v4-v3-v2 9 0,0,1, 0,0,0, 0,1,0, 0,1,1 // v4-v7-v6-v5 10 }; Array of colour values for each vertex these will be interpolated across the faces

67 Assigning the data In this case we have 3 different arrays which we are going to combine into one VBO buffer. The data will be packed in the format Vertices -> Normal -> Colour First we have to allocate enough space for all 3 arrays

68 void GLWindow::createCube(GLfloat _scale,gluint &o_vbopointer) { // first we scale our vertices to _scale for(int i=0; i<24*3; ++i) { vertices[i]*=_scale; } // now create the VBO glgenbuffers(1, &o_vbopointer); // now we bind this ID to an Array buffer glbindbuffer(gl_array_buffer, o_vbopointer); } // this time our buffer is going to contain verts followed by normals // so allocate enough space for all of them glbufferdata(gl_array_buffer, 72*3*sizeof(GL_FLOAT), 0, GL_STATIC_DRAW); // now we copy the data for the verts into our buffer first glbuffersubdata(gl_array_buffer,0,24*3*sizeof(gl_float),vertices); // now we need to tag the normals onto the end of the verts glbuffersubdata(gl_array_buffer,24*3*sizeof(gl_float),24*3*sizeof(gl_float),normals); // now we need to tag the colours onto the end of the normals glbuffersubdata(gl_array_buffer,48*3*sizeof(gl_float),24*3*sizeof(gl_float),colours);

69 void OpenGLWindow::render() { // usually we will make this context current and render m_context->makecurrent(this); GLubyte indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; // this macro is used to define the offset into the VBO data for our normals etc // it needs to be a void pointer offset from 0 #define BUFFER_OFFSET(i) ((float *)NULL + (i)) glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glpushmatrix(); static int xrot=0; static int yrot=0; glrotatef(xrot++,1,0,0); glrotatef(yrot++,0,1,0); // enable vertex array drawing glenableclientstate(gl_vertex_array); // enable Normal array glenableclientstate(gl_normal_array); // enable the colour array glenableclientstate(gl_color_array); } // bind our VBO data to be the currently active one glbindbuffer(gl_array_buffer, m_vbopointer); // we need to tell GL where the verts start glvertexpointer(3,gl_float,0,0); // now we tell it where the nornals are (thes are basically at the end of the verts glnormalpointer(gl_float, 0,BUFFER_OFFSET(24*3)); // now we tell it where the colours are (thes are basically at the end of the normals glcolorpointer(3,gl_float, 0,BUFFER_OFFSET(48*3)); gldrawelementsinstancedarb(gl_quads,24,gl_unsigned_byte,indices,1); // now turn off the VBO client state as we have finished with it gldisableclientstate(gl_vertex_array); gldisableclientstate(gl_normal_array); gldisableclientstate(gl_color_array); glpopmatrix(); // finally swap the buffers to make visible m_context->swapbuffers(this);

70 Vertex Array Objects Modern OpenGL use generic vertex attributes as the input to the vertex shader stage (more in a later lecture) This replaces the specific glvertex,glcolour,glnormal pointers This gives us a more flexible approach to shader writing We need to bind these before we can use them and tell the shader which input does what

71 Vertex Array Objects Vertex Array objects are way of storing this state information and recalling it when required. All modern OpenGL use these

72 Vertex Array Objects Internally ngl:: uses Vertex Array Objects (VAOs) to store and draw all of the graphical elements ngl::vertexarrayobject class encapsulates all the functionality for creating these objects and then binding and drawing them This class may also be used to batch data for drawing in user programs and is the main way of accessing drawing in ngl

73 Vertex Array Object The OpenGL spec defines a VAO as This extension introduces named vertex array objects which encapsulate vertex array state on the client side. These objects allow applications to rapidly switch between large sets of array state. In addition, layered libraries can return to the default array state by simply creating and binding a new vertex array object. VAOs are a collection of state, like all OpenGL Objects. Unlike texture objects or Buffer Objects, VAOs are pure state objects; they do not contain any large blocks of data or anything.

74 VAO If you were to define the VAO state in terms of a C structs, it would look like the following struct VertexAttribute { bool bisenabled = GL_FALSE; //This is the number of elements in this attribute, 1-4. int isize = 4; unsigned int istride = 0; VertexAttribType etype = GL_FLOAT; bool bisnormalized = GL_FALSE; bool bisintegral = GL_FALSE; void * pbufferobjectoffset = 0; BufferObject * pbufferobj = 0; }; struct VertexArrayObject { BufferObject *pelementarraybufferobject = NULL; VertexAttribute attributes[gl_max_vertex_attrib]; }

75 VAO VAO basically store the state and attribute information for other buffers Once allocated we can use less commands to re-activate the state and draw (usually 3)

76 Generate VAO GenVertexArrays generates n empty vertex array objects Once bound subsequent operations are applied to the currently bound object GLuint m_vaoid[2]; // Two VAOs allocation glgenvertexarrays(2, &m_vaoid[0]); // First VAO setup glbindvertexarray(m_vaoid[0]);

77 VOA glgenbuffers(1, &m_vboid[2]); glbindbuffer(gl_array_buffer, m_vboid[2]); glbufferdata(gl_array_buffer, 9*sizeof(GLfloat), vert2, GL_STATIC_DRAW); glvertexattribpointer((gluint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); glenablevertexattribarray(0); glbindvertexarray(0); Normal VBO operations are done now the VAO is bound, all state allocated in this operations is retained in the VAO

78 Drawing // select first VAO glbindvertexarray(m_vaoid[0]); // draw first object gldrawarrays(gl_triangles, 0, 3); Fist we bind the VAO which will set the stored attribute state into the current state Then draw as usual

79 ngl::vertexarrayobject VertexArrayObject - m_drawmode : GLenum - m_indicescount : GLenum - m_id : GLuint - m_allocated : bool - m_indexed : bool - m_bound : bool - VertexArrayObject(_mode : GLenum) - VertexArrayObject(_v : VertexArrayObject) - ~VertexArrayObject() + createvoa(_mode : GLenum ) : VertexArrayObject * + bind() + unbind() + removevoa() + getid() : GLuint + isbound() : bool + isallocated() : bool + setdata(_size : uint, &_data : float, _mode=: GLenum ) + setindexeddata(_size : uint, &_data : float, _indexsize : uint, &_indexdata : GLubyte, _mode: GLenum ) + setvertexattributepointer(_id : GLuint,_size : GLint,_type : GLenum, _stride : GLsizei,_dataOffset : uint,_normalise : bool) + draw() + setnumindices(_n : GLuint)

80 ngl::vertexarrayobject First thing you will notice about this class is that the constructor and destructor are private This means it is not possible for the user to instantiate the class directly We need to do this as the lifetime of the VAO needs to be controlled and not be destroyed when it goes out of scope We also need to control the construction so it passes the correct values to the VAO and this is not possible using a ctor

81 Building a VAO There are two methods of using the VAO class per vertex data indexed data The first example demonstrates using the VAO to build a cube using Triangles, by setting the vertex and vertex colour as attributes

82 data const Index values point into the vert and colour arrays indicating which elements make up the face triangles static GLubyte indices[]= { 0,1,5,0,4,5, // back 3,2,6,7,6,3, // front 0,1,2,3,2,0, // top 4,5,6,7,6,4, // bottom 0,3,4,4,7,3, // Left 1,5,2,2,6,5 // Right }; GLfloat vertices[] = { -1,1,-1, 1,1,-1, 1,1,1, -1,1,1, -1,-1,-1, 1,-1,-1, 1,-1,1, -1,-1,1 }; GLfloat colours[]={ 1,0,0, 0,1,0, 0,0,1, 1,1,1, 0,0,1, 0,1,0, 1,0,0, 1,1,1 };

83 // create a vao as a series of GL_TRIANGLES m_vao= ngl::vertexarrayobject::createvoa(gl_triangles); m_vao->bind(); // in this case we are going to set our data as the vertices above m_vao->setindexeddata(8*sizeof(ngl::vec3),vertices[0],sizeof(indices),indices[0]); // now we set the attribute pointer to be 0 (as this matches vertin in our shader) m_vao->setvertexattributepointer(0,3,gl_float,0,0); m_vao->setindexeddata(8*sizeof(ngl::vec3),colours[0],sizeof(indices),indices[0]); // now we set the attribute pointer to be 0 (as this matches vertin in our shader) m_vao->setvertexattributepointer(1,3,gl_float,0,0); m_vao->setnumindices(sizeof(indices)); // now unbind m_vao->unbind();

84 shader->bindattribute("colourshader",0,"invert"); shader->bindattribute("colourshader",1,"incolour"); Shaders #version 150 Model View Projection Matrix uniform mat4 MVP; in vec3 invert; in vec3 incolour; out vec3 vertcolour; void main(void) { // calculate the vertex position gl_position = MVP*vec4(inVert, 1.0); vertcolour=incolour; } attribute 0 in Vert attribute 1 in Colour MVP calculated in app and passed to shader vertcolour passed to frag shader #version 150 in vec3 vertcolour; out vec4 outcolour; void main () { // set the fragment colour outcolour = vec4(vertcolour,1); }

85 Drawing // clear the screen and depth buffer glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); // build our transform stack ngl::transformation trans; // set the mouse rotation trans.setrotation(m_spinxface,m_spinyface,0); // set this in the TX stack m_transformstack.setglobal(trans); ngl::shaderlib *shader=ngl::shaderlib::instance(); (*shader)["colourshader"]->use(); ngl::matrix MVP; MVP=m_cam->getVPMatrix() * m_transformstack.getcurrandglobal().getmatrix(); shader->setshaderparamfrommatrix("mvp",mvp); m_vao->bind(); m_vao->draw(); m_vao->unbind();

86 Creating a vertex structure This example passes the following structure to the VAO class and creates a textured Sphere struct vertdata { GLfloat u; GLfloat v; GLfloat nx; GLfloat ny; GLfloat nz; GLfloat x; GLfloat y; GLfloat z; };

87 // first we grab an instance of our VOA class as a TRIANGLE_STRIP m_vaosphere= ngl::vertexarrayobject::createvoa(gl_triangle_strip); // next we bind it so it's active for setting data m_vaosphere->bind(); // the next part of the code calculates the P,N,UV of the sphere for tri_strips int buffsize; float theta1 = 0.0; float theta2 = 0.0; float theta3 = 0.0; float radius=1.0; float precision=80; // a std::vector to store our verts, remember vector packs contiguously so we can use it buffsize = (precision/2) * ((precision+1)*2); std::vector <vertdata> data(buffsize); // calculate how big our buffer is // Disallow a negative number for radius. if( radius < 0 ) { radius = -radius; } // Disallow a negative number for _precision. if( precision < 4 ) { precision = 4; } // now fill in a vertdata structure and add to the data list for our sphere vertdata d; unsigned int index=0; for( int i = 0; i < precision/2; ++i ) { theta1 = i * ngl::two_pi / precision - ngl::pi2; theta2 = (i + 1) * ngl::two_pi / precision - ngl::pi2; for( int j = 0; j <= precision; ++j ) { theta3 = j * ngl::two_pi / precision; d.nx = cosf(theta2) * cosf(theta3); d.ny = sinf(theta2); d.nz = cosf(theta2) * sinf(theta3); d.x = radius * d.nx; d.y = radius * d.ny; d.z = radius * d.nz; use a std::vector to store the data as we pre-calculate the size we can just allocate and treat as normal array loop and create the data values as a tri strip d.u d.v = (j/(float)precision); = 2*(i+1)/(float)precision; data[index++]=d; d.nx = cosf(theta1) * cosf(theta3); d.ny = sinf(theta1); d.nz = cosf(theta1) * sinf(theta3); d.x = radius * d.nx; d.y = radius * d.ny; d.z = radius * d.nz; d.u = (j/(float)precision); d.v = 2*i/(float)precision; data[index++]=d; } // end inner loop }// end outer loop

88 // now we have our data add it to the VAO, we need to tell the VAO the following // how much (in bytes) data we are copying // a pointer to the first element of data (in this case the address of the first element of the // std::vector m_vaosphere->setdata(buffsize*sizeof(vertdata),data[0].u); // in this case we have packed our data in interleaved format as follows // u,v,nx,ny,nz,x,y,z // If you look at the shader we have the following attributes being used // attribute vec3 invert; attribute 0 // attribute vec2 inuv; attribute 1 // attribute vec3 innormal; attribure 2 // so we need to set the vertexattributepointer so the correct size and type as follows // vertex is attribute 0 with x,y,z(3) parts of type GL_FLOAT, our complete packed data is // sizeof(vertdata) and the offset into the data structure for the first x component is 5 (u,v,nx,ny,nz)..x m_vaosphere->setvertexattributepointer(0,3,gl_float,sizeof(vertdata),5); // uv same as above but starts at 0 and is attrib 1 and only u,v so 2 m_vaosphere->setvertexattributepointer(1,2,gl_float,sizeof(vertdata),0); // normal same as vertex only starts at position 2 (u,v)-> nx m_vaosphere->setvertexattributepointer(2,3,gl_float,sizeof(vertdata),2); // now we have set the vertex attributes we tell the VAO class how many indices to draw when // gldrawarrays is called, in this case we use buffsize (but if we wished less of the sphere to be drawn we could // specify less (in steps of 3)) m_vaosphere->setnumindices(buffsize); // finally we have finished for now so time to unbind the VAO m_vaosphere->unbind();

89 example As the data stored in a std::vector is always contiguous we can use it to pass our data to the VAO We just need to pass the address of the first element in the structure In this case we can pre-calculate the size of the array needed which is quicker than using push_back

90 What Next We have used several deprecated features in this lecture but they serve to easily demonstrate the OpenGL process Next time we will investigate the OpenGL shading language and begin to learn some other elements of the pipeline We can then combine them to produce a full Core profile OpenGL application

91 references

92 References Segal M, Akeley K The OpenGL Graphics System: A Specification (Version 4.0 (Core Profile) - March 11, 2010) F S. Hill Computer Graphics Using Open GL (3rd Edition) Shreiner Et Al OpenGL Programming Guide: The Official Guide to Learning OpenGL Foley & van Dam Computer Graphics: Principles and Practice in C (2nd Edition) (Redbook online)

How OpenGL Works. Retained Mode. Immediate Mode. Introduction To OpenGL

How OpenGL Works. Retained Mode. Immediate Mode. Introduction To OpenGL How OpenGL Works Introduction To OpenGL OpenGL uses a series of matrices to control the position and way primitives are drawn OpenGL 1.x - 2.x allows these primitives to be drawn in two ways immediate

More information

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40) 11(40) Information Coding / Computer Graphics, ISY, LiTH OpenGL where it fits what it contains how you work with it 11(40) OpenGL The cross-platform graphics library Open = Open specification Runs everywhere

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

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

COMP371 COMPUTER GRAPHICS

COMP371 COMPUTER GRAPHICS COMP371 COMPUTER GRAPHICS SESSION 12 PROGRAMMABLE SHADERS Announcement Programming Assignment #2 deadline next week: Session #7 Review of project proposals 2 Lecture Overview GPU programming 3 GPU Pipeline

More information

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI) Computer Graphics CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Recall: OpenGL Skeleton void main(int argc, char** argv){ // First initialize

More information

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 2 Part 1 Primitives and Buffers Matt Burlick - Drexel University - CS 432 1 Rendering in OpenGL Ok, so now we want to actually draw stuff! OpenGL (like most

More information

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL CENG 477 Introduction to Computer Graphics Graphics Hardware and OpenGL Introduction Until now, we focused on graphic algorithms rather than hardware and implementation details But graphics, without using

More information

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University Graphics Programming Computer Graphics, VT 2016 Lecture 2, Chapter 2 Fredrik Nysjö Centre for Image analysis Uppsala University Graphics programming Typically deals with How to define a 3D scene with a

More information

CS475/CS675 - Computer Graphics. OpenGL Drawing

CS475/CS675 - Computer Graphics. OpenGL Drawing CS475/CS675 - Computer Graphics OpenGL Drawing What is OpenGL? Open Graphics Library API to specify geometric objects in 2D/3D and to control how they are rendered into the framebuffer. A software interface

More information

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1) Computer Graphics (CS 4731) Lecture 2: Introduction to OpenGL/GLUT(Part 1) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Recall: OpenGL GLBasics OpenGL s function Rendering

More information

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 CSE 167: Introduction to Computer Graphics Lecture #7: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 Announcements Project 2 due Friday 4/22 at 2pm Midterm #1 on

More information

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12 Announcement Homework 1 has been posted in dropbox and course website Due: 1:15 pm, Monday, September 12 Today s Agenda Primitives Programming with OpenGL OpenGL Primitives Polylines GL_POINTS GL_LINES

More information

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York API Background Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Graphics API history OpenGL API OpenGL function format Immediate Mode vs Retained Mode Examples The Programmer

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

Rendering Objects. Need to transform all geometry then

Rendering Objects. Need to transform all geometry then Intro to OpenGL Rendering Objects Object has internal geometry (Model) Object relative to other objects (World) Object relative to camera (View) Object relative to screen (Projection) Need to transform

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

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York Building Models Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Introduce simple data structures for building polygonal models - Vertex lists - Edge lists Deprecated

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

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 2 Part 2 Introduction to Shaders Matt Burlick - Drexel University - CS 432 1 Shaders To understand shaders, let s look at the graphics pipeline again The job

More information

This will give the installed location for the SDL libraries and include files and we can add this to either our Makefile or Qt project.

This will give the installed location for the SDL libraries and include files and we can add this to either our Makefile or Qt project. Using SDL The simple direct media layer or SDL is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.

More information

Geometry Shaders. And how to use them

Geometry Shaders. And how to use them Geometry Shaders And how to use them OpenGL Pipeline (part of it) Vertex data Vertex shader Vertices Primitives Geometry shader Primitives Fragments Fragment shader Color Depth Stencil Vertex Data Attributes

More information

GLSL Overview: Creating a Program

GLSL Overview: Creating a Program 1. Create the OpenGL application GLSL Overview: Creating a Program Primarily concerned with drawing Preferred approach uses buffer objects All drawing done in terms of vertex arrays Programming style differs

More information

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

WebGL A quick introduction. J. Madeira V. 0.2 September 2017 WebGL A quick introduction J. Madeira V. 0.2 September 2017 1 Interactive Computer Graphics Graphics library / package is intermediary between application and display hardware Application program maps

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

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders calls to load vertex data to vertex buffers calls to load

More information

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL Preview CS770/870 Spring 2017 Open GL Shader Language GLSL Review traditional graphics pipeline CPU/GPU mixed pipeline issues Shaders GLSL graphics pipeline Based on material from Angel and Shreiner, Interactive

More information

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL CS770/870 Spring 2017 Open GL Shader Language GLSL Based on material from Angel and Shreiner, Interactive Computer Graphics, 6 th Edition, Addison-Wesley, 2011 Bailey and Cunningham, Graphics Shaders 2

More information

CSE 167. Discussion 03 ft. Glynn 10/16/2017

CSE 167. Discussion 03 ft. Glynn 10/16/2017 CSE 167 Discussion 03 ft Glynn 10/16/2017 Announcements - Midterm next Tuesday(10/31) - Sample midterms are up - Project 1 late grading until this Friday - You will receive 75% of the points you ve earned

More information

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders Prateek Shrivastava CS12S008 shrvstv@cse.iitm.ac.in 1 GLSL Data types Scalar types: float, int, bool Vector

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

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

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

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

Sign up for crits! Announcments

Sign up for crits! Announcments Sign up for crits! Announcments Reading for Next Week FvD 16.1-16.3 local lighting models GL 5 lighting GL 9 (skim) texture mapping Modern Game Techniques CS248 Lecture Nov 13 Andrew Adams Overview The

More information

INTRODUCTION TO OPENGL PIPELINE

INTRODUCTION TO OPENGL PIPELINE CS580: Computer Graphics Min H. Kim KAIST School of Computing Foundations of Computer Graphics INTRODUCTION TO OPENGL PIPELINE 2 1 What is OpenGL? OpenGL = Open Graphics Library An open industry-standard

More information

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM Starting out with OpenGL ES 3.0 Jon Kirkham, Senior Software Engineer, ARM Agenda Some foundational work Instanced geometry rendering Uniform Buffers Transform feedback ETC2 Texture formats Occlusion Queries

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

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 2 Common Uses for Computer Graphics Applications for real-time 3D graphics range from interactive games

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

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

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

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1 Chapter 8 Three-Dimensional Object Representations 8-1 8.1 Overview The main goal of three-dimensional computer graphics is to generate two-dimensional images of a scene or of an object based on a a description

More information

Computer Graphics Seminar

Computer Graphics Seminar Computer Graphics Seminar MTAT.03.305 Spring 2018 Raimond Tunnel Computer Graphics Graphical illusion via the computer Displaying something meaningful (incl art) Math Computers are good at... computing.

More information

The Graphics Pipeline

The Graphics Pipeline The Graphics Pipeline Ray Tracing: Why Slow? Basic ray tracing: 1 ray/pixel Ray Tracing: Why Slow? Basic ray tracing: 1 ray/pixel But you really want shadows, reflections, global illumination, antialiasing

More information

Tutorial 1: Your First Triangle!

Tutorial 1: Your First Triangle! Tutorial 1: Your First Triangle! Summary For your first dabble in OpenGL, you are going to create the graphics programming equivalent of Hello World - outputting a single coloured triangle. It doesn t

More information

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov CSE 4431/5331.03M Advanced Topics in 3D Computer Graphics TA: Margarita Vinnikov mvinni@cse.yorku.ca Goals of any 3d application is speed. You should always limit the amount of polygons actually rendered

More information

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports Computação Gráfica Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre Chap. 4 Windows and Viewports Outline : Basic definitions in 2D: Global coordinates (scene domain): continuous domain

More information

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Shaders I Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Objectives Shader Programming Basics Simple Shaders Vertex shader Fragment shaders

More information

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives Geometry Primitives Sandro Spina Computer Graphics and Simulation Group Computer Science Department University of Malta 1 The Building Blocks of Geometry The objects in our virtual worlds are composed

More information

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE OPENGL STATE MACHINE OpenGL state system or state machine Has list of all current state values called state

More information

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer Best practices for effective OpenGL programming Dan Omachi OpenGL Development Engineer 2 What Is OpenGL? 3 OpenGL is a software interface to graphics hardware - OpenGL Specification 4 GPU accelerates rendering

More information

CS380: Computer Graphics Screen Space & World Space. Sung-Eui Yoon ( 윤성의 ) Course URL:

CS380: Computer Graphics Screen Space & World Space. Sung-Eui Yoon ( 윤성의 ) Course URL: CS380: Computer Graphics Screen Space & World Space Sung-Eui Yoon ( 윤성의 ) Course URL: http://sglab.kaist.ac.kr/~sungeui/cg Class Objectives Understand different spaces and basic OpenGL commands Understand

More information

CSC 8470 Computer Graphics. What is Computer Graphics?

CSC 8470 Computer Graphics. What is Computer Graphics? CSC 8470 Computer Graphics What is Computer Graphics? For us, it is primarily the study of how pictures can be generated using a computer. But it also includes: software tools used to make pictures hardware

More information

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1) Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) OpenGL/GLUT Installation OpenGL: Specific

More information

OpenGL Performances and Flexibility

OpenGL Performances and Flexibility OpenGL Performances and Flexibility Marco Di Benedetto Visual Computing Laboratory ISTI CNR, Italy OpenGL Roadmap 1.0 - Jan 1992 - First Version 1.1 - Jan 1997 - Vertex Arrays, Texture Objects 1.2 - Mar

More information

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm 6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm In this assignment, you will add an interactive preview of the scene and solid

More information

Vertex Buffer Objects

Vertex Buffer Objects 1 Vertex Buffer Objects This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License Mike Bailey mjb@cs.oregonstate.edu VertexBuffers.pptx Vertex Buffer

More information

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea 1 Vertex Buffer Objects This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License Mike Bailey mjb@cs.oregonstate.edu VertexBuffers.pptx Vertex Buffer

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

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy OpenGL Performances and Flexibility Visual Computing Laboratory ISTI CNR, Italy The Abstract Graphics Pipeline Application 1. The application specifies vertices & connectivity. Vertex Processing 2. The

More information

Assignment 1. Simple Graphics program using OpenGL

Assignment 1. Simple Graphics program using OpenGL Assignment 1 Simple Graphics program using OpenGL In this assignment we will use basic OpenGL functions to draw some basic graphical figures. Example: Consider following program to draw a point on screen.

More information

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects CSCI 420 Computer Graphics Lecture 4 Shaders Jernej Barbic University of Southern California Shading Languages GLSL Vertex Array Objects Vertex Shader Fragment Shader [Angel Ch. 1, 2, A] Introduction The

More information

EECS 487: Interactive Computer Graphics

EECS 487: Interactive Computer Graphics Integrating GLSL with OpenGL EECS 487: Interactive Computer Graphics Lecture 19: Integrating shaders with OpenGL program Vertex-array objects with shaders Miscellaneous shader related stuff Integrating

More information

Introduction to OpenGL

Introduction to OpenGL Introduction to OpenGL 1995-2015 Josef Pelikán & Alexander Wilkie CGG MFF UK Praha pepca@cgg.mff.cuni.cz http://cgg.mff.cuni.cz/~pepca/ 1 / 31 Advances in Hardware 3D acceleration is a common feature in

More information

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) OpenGL function format function name gluniform3f(x,y,z)

More information

CS452/552; EE465/505. Image Processing Frame Buffer Objects

CS452/552; EE465/505. Image Processing Frame Buffer Objects CS452/552; EE465/505 Image Processing Frame Buffer Objects 3-12 15 Outline! Image Processing: Examples! Render to Texture Read: Angel, Chapter 7, 7.10-7.13 Lab3 new due date: Friday, Mar. 13 th Project#1

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

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders Comp 410/510 Computer Graphics Spring 2018 Programming with OpenGL Part 3: Shaders Objectives Basic shaders - Vertex shader - Fragment shader Programming shaders with GLSL Finish first program void init(void)

More information

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015 WebGL and GLSL Basics CS559 Fall 2015 Lecture 10 October 6, 2015 Last time Hardware Rasterization For each point: Compute barycentric coords Decide if in or out.7,.7, -.4 1.1, 0, -.1.9,.05,.05.33,.33,.33

More information

object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates.

object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates. hello world 3d: basic approach object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates. object coordinates of vertices will be put in an OpenGL buffer

More information

Shaders. Slide credit to Prof. Zwicker

Shaders. Slide credit to Prof. Zwicker Shaders Slide credit to Prof. Zwicker 2 Today Shader programming 3 Complete model Blinn model with several light sources i diffuse specular ambient How is this implemented on the graphics processor (GPU)?

More information

OPENGL AND GLSL. Computer Graphics

OPENGL AND GLSL. Computer Graphics OPENGL AND GLSL Computer Graphics 1 OUTLINE I. Detecting GLSL Errors II. Drawing a (gasp) Triangle! III. (Simple) Animation 2 Interactive Computer Graphics, http://www.mechapen.com/projects.html WHAT IS

More information

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming SHADER PROGRAMMING Based on Jian Huang s lecture on Shader Programming What OpenGL 15 years ago could do http://www.neilturner.me.uk/shots/opengl-big.jpg What OpenGL can do now What s Changed? 15 years

More information

Introductory Seminar

Introductory Seminar EDAF80 Introduction to Computer Graphics Introductory Seminar OpenGL & C++ Michael Doggett 2017 C++ slides by Carl Johan Gribel, 2010-13 Today Lab info OpenGL C(++)rash course Labs overview 5 mandatory

More information

WebGL: Hands On. DevCon5 NYC Kenneth Russell Software Engineer, Google, Inc. Chair, WebGL Working Group

WebGL: Hands On. DevCon5 NYC Kenneth Russell Software Engineer, Google, Inc. Chair, WebGL Working Group WebGL: Hands On DevCon5 NYC 2011 Kenneth Russell Software Engineer, Google, Inc. Chair, WebGL Working Group Today's Agenda Introduce WebGL and its programming model. Show code for a complete example. Demonstrate

More information

Performance OpenGL Programming (for whatever reason)

Performance OpenGL Programming (for whatever reason) Performance OpenGL Programming (for whatever reason) Mike Bailey Oregon State University Performance Bottlenecks In general there are four places a graphics system can become bottlenecked: 1. The computer

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions Comp 410/510 Computer Graphics Spring 2018 Programming with OpenGL Part 4: Three Dimensions Objectives Develop a bit more sophisticated three-dimensional example - Rotating cube Introduce hidden-surface

More information

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics. About the Tutorial WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics. This tutorial starts with a basic introduction

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

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

Tutorial 04. Harshavardhan Kode. September 14, 2015

Tutorial 04. Harshavardhan Kode. September 14, 2015 Tutorial 04 Harshavardhan Kode September 14, 2015 1 About This tutorial an extension of the Tutorial 03. So you might see quite a lot similarities. The following things are new. A Plane is added underneath

More information

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer Real-Time Rendering (Echtzeitgraphik) Michael Wimmer wimmer@cg.tuwien.ac.at Walking down the graphics pipeline Application Geometry Rasterizer What for? Understanding the rendering pipeline is the key

More information

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

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015 Models and Architectures 1 Objectives Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for an interactive graphics system 2 Image Formation Revisited

More information

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2) Computer Graphics (CS 4731) Lecture 3: Introduction to OpenGL/GLUT (Part 2) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Triangulation Generally OpenGL breaks polygonsdownintotriangles

More information

Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013

Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013 Mali & OpenGL ES 3.0 Dave Shreiner Jon Kirkham ARM Game Developers Conference 27 March 2013 1 Agenda Some foundational work Instanced geometry rendering Transform feedback Occlusion Queries 2 What s New

More information

cs123 Lab 3 OpenGL Part One 1 Introduction 2 OpenGL Basics 2.2 The Rendering Pipeline 2.1 The CPU and the GPU 2.3 Basic Syntax of OpenGL commands

cs123 Lab 3 OpenGL Part One 1 Introduction 2 OpenGL Basics 2.2 The Rendering Pipeline 2.1 The CPU and the GPU 2.3 Basic Syntax of OpenGL commands cs123 Lab 3 OpenGL Part One Introduction to Computer Graphics 1 Introduction From now on, our weekly labs will focus on the use of OpenGL. While the lectures and projects will let you get a deeper understanding

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

The Application Stage. The Game Loop, Resource Management and Renderer Design

The Application Stage. The Game Loop, Resource Management and Renderer Design 1 The Application Stage The Game Loop, Resource Management and Renderer Design Application Stage Responsibilities 2 Set up the rendering pipeline Resource Management 3D meshes Textures etc. Prepare data

More information

Lecture 13: OpenGL Shading Language (GLSL)

Lecture 13: OpenGL Shading Language (GLSL) Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 18, 2018 1/56 Motivation } Last week, we discussed the many of the new tricks in Graphics require low-level access to the Graphics

More information

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 Objectives Simple Shaders - Vertex shader - Fragment shaders Programming shaders with

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

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3 CSCI 420 Computer Graphics Lecture 3 Interaction Jernej Barbic University of Southern California [Angel Ch. 2] Triangles (Clarification) Can be any shape or size Well-shaped triangles have advantages for

More information

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Building Models CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 1 Objectives Introduce simple data structures for building polygonal models - Vertex lists - Edge

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

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT Dr Franck P. Vidal 4 th September 2014 1 Contents Table of contents 2 List of figures 3 List of listings 3 1 Introduction 4

More information

Game Architecture. 2/19/16: Rasterization

Game Architecture. 2/19/16: Rasterization Game Architecture 2/19/16: Rasterization Viewing To render a scene, need to know Where am I and What am I looking at The view transform is the matrix that does this Maps a standard view space into world

More information

CS193P - Lecture 19. iphone Application Development. OpenGL ES

CS193P - Lecture 19. iphone Application Development. OpenGL ES CS193P - Lecture 19 iphone Application Development OpenGL ES 1 Announcements Final projects due in 7 days Tuesday, March 16th 11:59 pm Submit: Code Power-point/Keynote slides ReadMe file Final project

More information

What was removed? (1) OpenGL ES vs. OpenGL

What was removed? (1) OpenGL ES vs. OpenGL SLIDE 2 Outline What is? vs. OpenGL Profiles and versions EGL Surfaces on Windows CE and Symbian Implementations SLIDE 3 SLIDE 4 What is? Small-footprint subset of OpenGL OpenGL is too large for embedded

More information

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012 CS450/550 Pipeline Architecture Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012 0 Objectives Learn the basic components of a graphics system Introduce the OpenGL pipeline

More information