1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.

Slides:



Advertisements
Similar presentations
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Chapter 2: Graphics Programming
Pemrograman OpenGL Dasar
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
OpenGL and Projections
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
Programming with OpenGL Part 0: 3D API March 1, 2007.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Open Graphics Library (OpenGL)
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Programming with OpenGL Part 1: Background
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to OpenGL Week 1 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico CS.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 1: Background Ed Angel Professor Emeritus.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 Computer Graphics Programming with OpenGL I.
GLSL OpenGL Programming and Reference Guides, other sources
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Ed Angel Professor Emeritus of Computer Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 6: Three Dimensions Ed Angel Professor.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Introduction to Graphics Programming. Graphics API.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Hank Childs, University of Oregon Oct. 28th, 2016 CIS 441/541: Introduction to Computer Graphics Lecture 16: textures.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 3: Three Dimensions
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 6: Three Dimensions
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 3: Three Dimensions
Presentation transcript:

1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico

2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Objectives Build a complete first program ­Introduce shaders ­Introduce a standard program structure Simple viewing ­Two-dimensional viewing as a special case of three-dimensional viewing Initialization steps and program structure

3 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Program Structure Most OpenGL programs have a similar structure that consists of the following functions ­main() : specifies the callback functions opens one or more windows with the required properties enters event loop (last executable statement) ­init() : sets the state variables Viewing Attributes ­initShader(): read, compile and link shaders ­callbacks Display function Input and window functions

4 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 simple.c revisited main() function similar to last lecture ­Mostly GLUT functions init() will allow more flexible colors initShader() will hides details of setting up shaders for now Key issue is that we must form a data array to send to GPU and then render it

5 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 main.c #include int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glewInit(); init(); glutMainLoop(); } includes gl.h specify window properties set OpenGL state and initialize shaders enter event loop display callback

6 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window (the rendering context) ­RGB color ­Single buffering ­Properties logically ORed together glutWindowSize in pixels glutWindowPosition from top-left corner of display glutCreateWindow create window with title “simple” glutDisplayFunc display callback glutMainLoop enter infinite event loop

Immediate Mode Graphics Geometry specified by vertices ­Locations in space( 2 or 3 dimensional) ­Points, lines, circles, polygons, curves, surfaces Immediate mode ­Each time a vertex is specified in application, its location is sent to the GPU ­Old style uses glVertex ­Creates bottleneck between CPU and GPU ­Removed from OpenGL E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Retained Mode Graphics Put all vertex and attribute data in array Send array to GPU to be rendered immediately Almost OK but problem is we would have to send array over each time we need another render of it Better to send array over and store on GPU for multiple renderings 8 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Display Callback Once we get data to GLU, we can initiate the rendering with a simple callback Arrays are buffer objects that contain vertex arrays 9 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 void mydisplay() { glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); glFlush(); }

Vertex Arrays Vertices can have many attributes ­Position ­Color ­Texture Coordinates ­Application data A vertex array holds these data Using types in vec.h 10 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 point2 vertices[3] = {point2(0.0, 0.0), point2( 0.0, 1.0), point2(1.0, 1.0)};

Vertex Array Object Bundles all vertex data (positions, colors,..,) Get name for buffer then bind At this point we have a current vertex array but no contents Use of glBindVertexArray lets us switch between VBOs 11 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Glunit abuffer; glGenVertexArrays(1, &abuffer); glBindVertexArray(abuffer);

Buffer Object Buffers objects allow us to transfer large amounts of data to the GPU Need to create, bind and identify data Data in current vertex array is sent to GPU 12 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Gluint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(points), points);

Initialization Vertex array objects and buffer objects can be set up on init() Also set clear color and other OpeGL parameters Also set up shaders as part of initialization ­Read ­Compile ­Link First let’s consider a few other issues 13 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

14 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Coordinate Systems The units in points are determined by the application and are called object, world, model or problem coordinates Viewing specifications usually are also in object coordinates Eventually pixels will be produced in window coordinates OpenGL also uses some internal representations that usually are not visible to the application but are important in the shaders

15 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 OpenGL Camera OpenGL places a camera at the origin in object space pointing in the negative z direction The default viewing volume is a box centered at the origin with sides of length 2

16 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Orthographic Viewing z=0 In the default orthographic view, points are projected forward along the z axis onto the plane z=0

17 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Viewports Do not have use the entire window for the image: glViewport(x,y,w,h) Values in pixels (window coordinates)

18 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Transformations and Viewing In OpenGL, projection is carried out by a projection matrix (transformation) Transformation functions are also used for changes in coordinate systems Pre 3.0 OpenGL had a set of transformation functions which have been deprecated Three choices ­Application code ­GLSL functions ­vec.h and mat.h