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

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

CS475/CS675 - Computer Graphics. OpenGL Drawing

GLSL Overview: Creating a Program

Drawing with OpenGL. Chapter 3. Chapter Objectives

CS 432 Interactive Computer Graphics

Vertex Buffer Objects

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea

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

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

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

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

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

INTRODUCTION TO OPENGL PIPELINE

Objectives. Programming with WebGL Part 1: Background. Retained vs. Immediate Mode Graphics. Early History of APIs. PHIGS and X.

Programming with WebGL Part 1: Background. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

EECS 487: Interactive Computer Graphics

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

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

CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE

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

Tutorial 1: Your First Triangle!

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

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

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

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

CS452/552; EE465/505. Review & Examples

Interaction. CSCI 420 Computer Graphics Lecture 3

OpenGL Über Buffers Extension

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

6.S096 Lecture 9 Visualization

3 Meshes. Strips, Fans, Indexed Face Sets. Display Lists, Vertex Buffer Objects, Vertex Cache

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

Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader

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

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

COMP371 COMPUTER GRAPHICS

OpenGL and GLUT. COMP413 Computer Graphics. School of Computer Sci. & Eng. Kyungpook National University, Korea. Spring Semester, 2016

CS 432 Interactive Computer Graphics

Introduction to Computer Graphics. Hardware Acceleration Review

Introductory Seminar

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

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

The GLSL API. Mike Bailey. Oregon State University. Geometry Shader. Program. The GLSL Shader-creation Process. create. compile. Vertex.

Computer Graphics Seminar

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

CPSC 436D Video Game Programming

Modern OpenGL Guide. Alexander Overvoorde. May Introduction 3 Credits... 3 Prerequisites... 4

Shaders. Slide credit to Prof. Zwicker

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

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Methodology for Lecture

CS 548: COMPUTER GRAPHICS INTRODUCTION TO OPENGL AND GLUT SPRING 2015 DR. MICHAEL J. REALE

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

COMP3421. Modeling, Bezier Curves, L-Systems, VBOs

3d Programming I. Dr Anton Gerdelan

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

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

VU Entwurf und Programmierung einer Rendering-Engine. Optimization techniques for rendering engines

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

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

Mali Developer Resources. Kevin Ho ARM Taiwan FAE

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

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

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒

the gamedesigninitiative at cornell university Lecture 12 Scene Graphs

Tutorial 04. Harshavardhan Kode. September 14, 2015

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

An Overview GLUT GLSL GLEW

Lecture 31 Sections 9.1, 9.2, 9.3. Mon, Nov 23, 2009

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists

A Review of OpenGL Compute Shaders

C++ - OpenGL - Setting up Visual Studio

Discussion 3. PPM loading Texture rendering in OpenGL

Due: Thursday, February 6 th, 11:59 pm TA: Mason Remy

Building Models. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

OpenGL ES for iphone Games. Erik M. Buck

Lectures Display List

Tutorial 12: Real-Time Lighting B

LECTURE 02 OPENGL API

Introduction to OpenGL/GLSL and WebGL GLSL

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

To Do. Review of Last Demo. Methodology for Lecture. Geometry Basic Setup. Outline. Foundations of Computer Graphics (Fall 2012)

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

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

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

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

BABLEFISH. Create a custom VR Engine

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

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

Lighting and Texturing

Computer Graphics. Prof. Feng Liu. Fall /14/2016

GPU Programming EE Final Examination

Computer Graphics. Bing-Yu Chen National Taiwan University

3D Modeling. 3D Modeling 1

Building Models. Objectives Introduce simple data structures for building polygonal models. Vertex lists Edge lists

Learn OpenGL. An offline transcript of learnopengl.com. Joey de Vries

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

Setting up the Assimp library Creating the Mesh class and Model class How to load models in the game world using the Model class

COSC342: Computer Graphics

OpenCL / OpenGL Vertex Buffer Interoperability: A Particle System Case Study

Transcription:

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 by sorting, culling, or level-of-detail algorithms. when all else fails Vertex Arrays are one good way to do that, Vertex Buffer Objects works just like vertex arrays, except that it loads the data into the graphics card's high-performance memory, significantly lowering rendering time The extension being relatively new, not all cards will support it Either use ARB Glew library

Setup Glew and FreeImage Download Glew from http://glew.sourceforge.net/ Free Image from http://freeimage.sourceforge.net/download.html Open your project folder and manually create a new folder named libraries Copy GLEW and FreeImage this folder. In VS now, select Properties. From the Configuration Properties-> C/C++ > General-> Additional Include Directories Click on Additional Include Directories and select Edit. A new menu will pop that will allow you to insert the locations of the header files, press the New Line button and browse for the location of GLEW, click on the library folder and select include. Repeat for FreeImage. Now, select Linker > General > Additional Library Directories, chose Edit and add, like before, the location of the binary libraries for GLEW and FreeImage. Select Linker > Input > Additional Dependencies, chose Edit and add the names of the three binary libraries, one per lines: glew32.lib, FreeImage.lib Windows opengl32.lib. You could press the F7 key or select BUILD > Build Solution. If you ve correctly executed the above steps the build should be successful. Copy FreeImage.dll and glew32.dll in the Debug folder from your project folder. From http://solarianprogrammer.com/2013/05/10/opengl-101-windows-osx-linux-gettingstarted

Glew (usage) #include <GL/glew.h> #include <GLUT/glut.h> // not glew should be first In main add the following: glutinit(&argc, argv); glutcreatewindow("glew Test"); GLenum err = glewinit(); if (GLEW_OK!= err) { /* Problem: glewinit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewgeterrorstring(err));... } fprintf(stdout, "Status: Using GLEW %s\n", glewgetstring(glew_version));

Memory buffer containing geometry data that is managed by the driver Providing the benefits of vertex array, while avoiding downsides of their implementations Vertex array Pro: reduces the number of function calls Con: redundant usage of the shared vertices functions are in the CPU and the data in the arrays must be re-sent to the server each time when it is referenced. Vertex buffer object can be read and updated by mapping the buffer into client's memory space Allows vertex array data to be stored in highperformance graphics memory on the server side Creates "buffer objects" for vertex attributes Provides same access functions to reference the arrays, which are used in vertex arrays, such as glvertexpointer(), glnormalpointer(), gltexcoordpointer(), etc.

Declarations Same as before //Vertices of a triangle float data[] = {1.0, 0.0, 1.0, 0.0, 0.0, -1.0, -1.0, 0.0, 1.0}; Plus VBO reference GLuint trianglevbo;

Creating VBO Creating a VBO requires 3 steps (usually in init() after glew initialization. 1. Generate a new buffer object with glgenbuffers(). 2. Bind the buffer object with glbindbuffer(). 3. Copy vertex data to the buffer object with glbufferdata().

Example Initialization: //Create a new VBO and use the variable id to store the VBO id glgenbuffers(1, &trianglevbo); //Make the new VBO active glbindbuffer(gl_array_buffer, trianglevbo); //Upload vertex data to the video device glbufferdata(gl_array_buffer, sizeof(data), data, GL_STATIC_DRAW); Clearing the memory: // it is safe to delete after copying data to VBO delete [] vertices; // deactivate VBO active glbindbuffer(gl_array_buffer, 0); // delete VBO when program terminated gldeletebuffers(1, &vboid);

glgenbuffers() void glgenbuffers( GLsizei n, GLuint* ids) Creates buffer objects and returns the identifiers of the buffer objects. 2 parameters: number of buffer objects to create the address of a GLuint variable or array to store a single ID or multiple IDs. gldeletebuffers() void gldeletebuffers(glsizei n, const GLuint* ids) Can delete a single VBO multiple VBOs After a buffer object is deleted, its contents will be lost.

glbindbuffer() void glbindbuffer(glenum target, GLuint id) Connects the buffer object with the corresponding ID VBO initializes the buffer with a zero-sized memory buffer and set the initial VBO states, such as usage and access properties. Takes 2 parameters: Target - tells VBO whether this buffer object will store vertex array data or index array data: GL_ARRAY_BUFFER Any vertex attributes, such as vertex coordinates, texture coordinates, normals and color component arrays GL_ELEMENT_ARRAY_BUFFER Index array which is used for gldraw[range]elements() ID the Id generated by glgenbuffers()

glbufferdata() void glbufferdata(glenum target, GLsizei size, const void* data, GLenum usage) Copys the data into the buffer object Takes two parameters target would be GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER. Size is the number of bytes of data to transfer. Pointer to the array of source data. If data is NULL pointer, then VBO reserves only memory space with the given data size. Usage flag hints for VBO to provide how the buffer object is going to be used: static, dynamic or stream, and read, copy or draw. VBO specifies 9 enumerated values for usage flags; GL_STATIC_DRAW - GL_STATIC_READ - GL_STATIC_COPY GL_DYNAMIC_DRAW - GL_DYNAMIC_READ - GL_DYNAMIC_COPY GL_STREAM_DRAW - GL_STREAM_READ - GL_STREAM_COPY

glbuffersubdata() void glbuffersubdata(glenum target, GLint offset, GLsizei size, void* data) Like glbufferdata(), glbuffersubdata() is used to copy data into VBO, but it only replaces a range of data into the existing buffer, starting from the given offset.

Example (Drawing and Updating) // bind VBOs for vertex array and index array glbindbuffer(gl_array_buffer, vboid);// for vertex coordinates glbindbuffer(gl_element_array_buffer, vboid1);// for indices (Don t forget to set it appropriately before hand) // do same as vertex array except pointer glenableclientstate(gl_vertex_array); // activate vertex coords array glvertexpointer(3, GL_FLOAT, 0, 0);// last param is offset, not ptr // draw //Actually draw the triangle, giving the number of vertices provided gldrawarrays(gl_triangles, 0, sizeof(data) / sizeof(float) / 3); gldrawelements( ); gldisableclientstate(gl_vertex_array); // deactivate vertex array - bind with 0, so, switch back to normal pointer operation glbindbuffer(gl_array_buffer, 0); glbindbuffer(gl_element_array_buffer, 0);

Updating VBO To update VBO Copy new data into the bound VBO with glbufferdata() or glbuffersubdataarb() should have a valid vertex array all the time Map the buffer object into client's memory, and the client can update data with the pointer to the mapped buffer.

glmapbufferarb() void* glmapbufferglenum( target, GLenum access) Maps the buffer object into client's memory. If succesful glmapbuffer() returns the pointer to the buffer. Otherwise it returns NULL. Takes two parameters target is mentioned earlier at glbindbuffer() access flag specifies what to do with the mapped data: read, write or both. GL_READ_ONLY_ARB GL_WRITE_ONLY_ARB GL_READ_WRITE_ARB

glunmapbuffer() GLboolean glunmapbuffer(glenum target) Unmappes the buffer object from the client's memory. returns GL_TRUE if success GL_FALSE if the contents of VBO was corrupted while the buffer was mapped.

Example // bind then map the VBO glbindbufferarb(gl_array_buffer_arb, vboid); float* ptr = (float*)glmapbufferarb(gl_array_buffer_arb,gl_write_only_arb); // if the pointer is valid(mapped), update VBO if(ptr) { // modify buffer data updatemyvbo(ptr,...); // unmap it after use glunmapbufferarb(gl_array_buffer_arb); } // you can draw the updated VBO...

VBO Note the current Frame Rate for your application Modify your code for vertex array to use VBO Use glew or ARB extensions (see complementary instruction) Note the new Frame Rate for your application

Declaration GLfloat texture_coord[6] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0}; We could store the texture_coord in the same VBO that stores the vertex_position array: glbuffersubdata(gl_array_buffer, sizeof(vertices_position), sizeof(texture_coord), texture_coord); Also use gltexcoordpointer(2,gl_float,0,null); glenableclientstate(gl_texture_coord_array);

Add texture to your figure Use FreeImage and provided texture wrapper Make sure you use VBO Bonus: Add multiple texture, toggle textures, blend textures.

Light on and off Add ambient light to the scene Add material to your figures Allow to toggle the light on and off with the L key Bonus: Rotate light source Make fancy light different colors from different directions Look for help: http://www.videotutorialsrock.com/opengl_tutorial/lighting /text.php http://sjbaker.org/steve/omniv/opengl_lighting.html

Links http://www.songho.ca/opengl/gl_vbo.html http://oss.sgi.com/projects/ogl-sample/registry/arb/vertex_buffer_object.txt http://en.wikipedia.org/wiki/vertex_buffer_object

Write you name and student number in comments at the top of your code Submit your entire project code as follows: submit 4431 lab2 filename(s)