Cosc 5/4730 OpenGL ES.

Slides:



Advertisements
Similar presentations
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Advertisements

Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Lecture Fall 2001 Visibility Back-Face Culling Painter’s Algorithm.
CS378 - Mobile Computing 3D Graphics.
 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.
Cosc 5/4730 OpenGL ES An introduction. OpenGL ES GL was first developed by SGI as a priority graphics language – OpenGL was developed initially by SGI.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
OpenGL and WebGL Drawing Functions CSCI 440 Day Five.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
What is ? Open Graphics Library A cross-language, multi-platform API for rendering 2D and 3D computer graphics. The API is used to interact with a Graphics.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
1 Graphics CSCI 343, Fall 2015 Lecture 2 Introduction to HTML, JavaScript and WebGL.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Shader Study 이동현. Vision engine   Games Helldorado The Show Warlord.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Mobile & Casual Gaming OpenGL ES Intro. /red/chapter03.html.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Introduction to Computer Graphics
Visible Surface Detection
- Introduction - Graphics Pipeline
Week 7 - Monday CS361.
Week 2 - Friday CS361.
Introduction to OpenGL
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Lecture 13 Clipping & Scan Conversion
CS297 Graphics with Java and OpenGL
Introduction to OpenGL
Presentation transcript:

Cosc 5/4730 OpenGL ES

Introduction with android OpenGL Introduction with android

OpenGL ES GL was first developed by SGI as a priority graphics language OpenGL was developed initially by SGI and working group of other people in 1992. Open GL is used from games to supercomputers OpenGL and OpenGL ES are managed by a consortium, called the Khronos group. OpenGL ES (Embedded Systems) is a subset of OpenGL intended for devices like mobile phones.

Open GL ES (2) OpenGL ES 1.0 had much functionality stripped from the original OpenGL API and a little bit added. Two of the more significant differences between OpenGL ES and OpenGL are the removal of the glBegin ... glEnd calling semantics for primitive rendering (in favor of vertex arrays) and the introduction of fixed-point data types for vertex coordinates and attributes to better support the computational abilities of embedded processors, which often lack an FPU. OpenGL ES 1.1 adds to the OpenGL ES 1.0 functionality by introducing additional features such as mandatory support for multitexture, better multitexture support (with combiners and dot product texture operations), automatic mipmap generation, vertex buffer objects, state queries, user clip planes, and greater control over point rendering. OpenGL ES 2.0, publicly released in March 2007[1], eliminates most of the fixed-function rendering pipeline in favor of a programmable one. Almost all rendering features of the transform and lighting pipelines, such as the specification of materials and light parameters formerly specified by the fixed-function API, are replaced by shaders written by the graphics programmer. As a result, OpenGL ES 2.0 is not backwards compatible with OpenGL ES 1.1.

Android Device support. OpenGL ES 1.0 and 1.1 This API specification is supported by Android 1.0 and higher. OpenGL ES 2.0 This API specification is supported by Android 2.2 (API level 8) and higher. 2.0 is NOT backward compatible with 1.1 OpenGL ES 3.0 - This API specification is supported by Android 4.3 (API level 18) and higher. Backward compatible to 2.0 (and not to 1.1). ES 3.0 API requires a device implementation provided by manufacturer, Not all support 3.0+ To check the version see http://developer.android.com/guide/topics/graphics/opengl.html#version-check OpenGL ES 3.1 - This API specification is supported by Android 5.0 (API level 21) and higher.

This lecture Since openGL ES usages is the same across platforms, so even though we are covering android, this will basically work on IOS as well. This is also not a graphics course. To cover OpenGL requires a great deal of time, which is provided in the Graphics course, which spends the most of course covering OpenGL. I cover the basics later in the lecture.

Android Provides two ways to render OpenGL Based on API 1, extend a SurfaceView Start a OpenGL thread, where all OpenGL calls must be called initialize the EGL Initialize GL now start drawing This is actually how it is still done with the Blackberry. Based on API 5+ We’ll focus on this for android extend/instantiate a GLSurfaceView and extend /implement a GLSurfaceView.Rendener start drawing.

Example public class OpenGlDemo extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GLSurfaceView view = new GLSurfaceView(this); view.setRenderer(new OpenGLRenderer()); OpenGLRenderer is a class that implements Renderer setContentView(view); }

GLSurfaceView The API class in Android that helps you write OpenGL ES applications. Providing the glue code to connect OpenGL ES to the View system. Providing the glue code to make OpenGL ES work with the Activity life-cycle. Making it easy to choose an appropriate frame buffer pixel format. Creating and managing a separate rendering thread to enable smooth animation. Providing easy-to-use debugging tools for tracing OpenGL ES API calls and checking for errors.

Renderer GLSurfaceView.Renderer is a generic render interface. In your implementation of this renderer you should put all your calls to render a frame. There are three functions to implement: Called when the surface is created or recreated. public void onSurfaceCreated(GL10 gl, EGLConfig config) A place to setup things that don't change over rendering cycles Called to draw the current frame. public void onDrawFrame(GL10 gl) this is where the drawing actually takes place Called when the surface changed size. public void onSurfaceChanged(GL10 gl, int width, int height) called if the devices changes from landscape to portrait or back again.

OpenGL 2.0 Works very much the same (except not compatible with 1.1) Get the GLSurfaceView (or extend it) setEGLContextClientVersion(2); Create a render import android.opengl.GLES20; The variable/parameters GL10 are unused and switch to GLES20. It just exists, instead of being passed to the methods. Now use the 2.0 methods and the GLES20 variable.

Events Touch/key events. Make sure these are all handled in the GLSurfaceView Instead of the activity.

See the Demos OpenGl 1.1 OpenGl 2.0 OpenGL 3.0 OpenGLDemo OpenGL Very basic framework. Draws a Square. OpenGL Demo showing Triangle, cube, lighting. Vortex Triangles, with touch events. Extends the GLSurfaceView instead of implements. OpenGl 2.0 HelloOpenGLES20 is the basic framework with touch events. Opengl2ex1 is has render class it sends to default GLSurfaceView OpenGL 3.0 helloOpenGLES30, Opengl3ex1, and Opengl3ex2 are updated from 2.0 to 3.0, since it is backward compatible. Opengl3ex3 is native GL ES 3.0 code.

References Tutorials: JavaDocs http://en.wikipedia.org/wiki/OpenGL_ES General OpenGL ES tutorials (25 parts) A great OpenGL ES Tutorial for Android (5 parts) http://blog.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/ http://www.droidnova.com/android-3d-game-tutorial-part-i,312.html (7 parts) http://docs.blackberry.com/en/developers/deliverables/11942/Creating_2-D_and_3-D_graphics_using_OpenGL_ES_944406_11.jsp JavaDocs http://java.sun.com/javame/reference/apis/jsr239/ http://developer.android.com/intl/zh-CN/reference/javax/microedition/khronos/opengles/package-summary.html http://www.blackberry.com/developers/docs/5.0.0api/index.html click on the javax.microedition.khronos.opengls. This has much better descriptions of the methods, then android. http://en.wikipedia.org/wiki/OpenGL_ES http://www.khronos.org/opengles/ OpenGL ES Game Development book.

References (2) http://developer.android.com/guide/topics/graphics/opengl.html is pretty good at the basics (combined with the same code) OpenGl 2.0 http://www.learnopengles.com/android-lesson-one-getting-started/ is a pretty good site and lessons. All examples are in github, so easy to look at and use. https://github.com/learnopengles/Learn-OpenGLES-Tutorials.git http://androidblog.reindustries.com/a-real-open-gl-es-2-0-2d-tutorial-part-1/ useful site for examples. http://developer.android.com/training/graphics/opengl/index.html googles developer training site. Helpful in some cases.

Last Note OpenGl 1.1 examples will run the emulators OpenGl 2.0 examples are supposed to run in the emulators, but even following googles directions, they crash. Several fixes have been added and they mostly work, but may still crash now and again. You will likely need to test on a device.

Opengles the basics

Basics First our program describes some geometry and information on handling lighting, colors, materials, and textures. This data goes into the pipeline

Basics (2) Next the data is moved, scaled, and rotated. Then for each object lighting is calculated and stored. Example: A solar system we may move, rotate and scale the model (not the planets, that’s the animation) Based on our viewpoint, which is based on “rectangular cone” that is limits the scene to a manageable level.

Basics (3) Next the scene is clipped, so that only the objects that are likely to be visible are processed. Culling out objects as soon as possible saves processing time. Continuing the example, if the moon is behind the earth, then we don’t process the moon. Other planets and moons would also be culled as needed. This also includes “backsides” and “insides” of objects that can be seen as well.

Basics (4) Next the remaining objects are now “projected” against the “viewport” The viewport again is cone Now rasterization takes place, which creates fragments that could be single pixels. Fragments can have textures and fog effects More culling may take place for fog that obscures objects.

Basics (5) And finally any surviving fragments are written to the frame buffer. Some last minute operations take place as well Fragment’s values are applied for translucency Depth tests to ensure closer fragments are written “in front” of further ones And now you “see” the data.

2D Well start with 2D drawing Later on we get to 3D objects.

Geometry and describing objects Let’s start simple and describe a square. First we describe the object around center point of 0,0 float vertices[] = { -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, };

Primitives to render OpenGL has a lot more primitives, but ES only has the following. GL_POINTS Draw individual points to the screen. GL_LINE_STRIP Series of connected line segments Same, with a segment added first and last vertices

Primitives to render (2) GL_LINES Pears of vertices are interpreted as Individual line segments GL_TRIANGLES Triples of vertices interpreted as triangles.

Primitives to render (3) GL_TRIANGLE_STRIP Draws a series of triangles (three-sided polygons) using vertices v0, v1, v2, then v2, v1, v3 (note the order), then v2, v3, v4, and so on. The ordering is to ensure that the triangles are all drawn with the same orientation so that the strip can correctly form part of a surface.

Primitives to render (4) GL_TRIANGLE_FAN Same as GL_TRIANGLE_STRIP, except that the vertices are drawn v0, v1, v2, then v0, v2, v3, then v0, v3, v4, and so on.

Geometry and describing objects (2) I want a colored square, so I’m going to use GL_TRIANGLES So we need to match up the vertices in triples. private short[] indices = { 0, 1, 2, 0, 2, 3 };

Geometry and describing objects (3) Order also matters, normally you should describe the object in counter clockwise (or clockwise, but always the same direction) for performance reasons and facing

Add some color. there are four components: red, green, blue, and alpha (transparency) These map directory to our 4 vertices in the square. In this case, I’ll make it red and opiate. byte colors[] = { 255, 0, 0, 255, 255, 0,0, 255, 255,0,0,255, 255,0,0,255 }; In OpenGLDemo1, you can play with color or use very colorful square as well.

Lastly Now matches up everything, converts their internal java formats to the OpenGL mainly makes sure the ordering of the bytes is correctly, otherwise depending on hardware, they might get reversed. mFVertexBuffer = vbb.asFloatBuffer(); mFVertexBuffer.put(vertices); mFVertexBuffer.position(0); mColorBuffer = ByteBuffer.allocateDirect(colors.length); mColorBuffer.put(colors); mColorBuffer.position(0); mIndexBuffer = ByteBuffer.allocateDirect(indices.length); mIndexBuffer.put(indices); mIndexBuffer.position(0);

Drawing tell openGL how the vertices are ordering their faces. This is both for efficiently so openGL can ignore the "backside" and not attempt to draw it. gl.glFrontFace(GL11.GL_CCW); //counter clockwise, so any clockwise triangles are ignored. send the buffers to the renderer. specify the number of elements per vertex, which there are 2. gl.glVertexPointer(2, GL11.GL_FLOAT, 0, mFVertexBuffer); color buffer is added, with the size of the 4 elements gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); finally draw the element, we the connectivity array, using triangles could also be triangle lists, points or lines gl.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_BYTE, mIndexBuffer); return the openGL back to the default value, we didn’t change it from default, but a good idea none the less. gl.glFrontFace(GL11.GL_CCW);

Example In the OpenGLDemo1.zip Includes the above code It also makes the square move. It uses a glTranslatef method to move where the triangle will be drawn. This is done the SquareRender in the onDrawFrame method.

Circles? Say we wanted to draw a circle. How? A circle outline Likely use a GL_LINE_STRIP Shaded circle Use a GL_TRIANGLE_FAN Include the first vertex again as the last vertex

Some more complex Let try a simple stick figure.

3D Adding another dimension. Note: OpenGL coordinates 0,0,0 is in the “middle” +y goes up, +x goes right +z is pointing toward you

Viewing Frustum and Projection Matrix

Cube Using the square from before, now we need to add a z space to it, creating a cube. Plus add the another plane. float vertices[] = { -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f,-1.0f, 1.0f, -1.0f,-1.0f }; We also need to add to the extra plane to the color matrix as well.

connecting the vertices We can use a two triangle fans to connect everything. byte tfan1[] = { byte tfan2[] = { 1,0,3, 7,4,5, 1,3,2, 7,5,6, 1,2,6, 7,6,2, 1,6,5, 7,2,3, 1,5,4, 7,3,0, 1,4,0 7,0,4 }; }; The first incorporates the front, right, and top faces, while the second incorporates the back, bottom, and left faces

drawing gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer); gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); draw the fan, 6*3 is 6 fans of 3 triangles gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan1); gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan2);

onDrawFrame The onDrawFrame is basically unchanged. We call mCube.draw Also the example has a glClearColor(0.0f,0.5f,0.5f,1.0f); So the background will be teal blue.

frustum code We need to add code for the frustum information float aspectRatio; float zNear =.1f; float zFar =1000; //The field of 30 degrees is converted to radians as the Java Math libraries require float fieldOfView = 30.0f/57.3f; float size; gl.glEnable(GL10.GL_NORMALIZE); //ensure the aspect raitio is correct, otherwise the objects will look squashed aspectRatio=(float)width/(float)height;

frustum code (2) gl.glMatrixMode(GL10.GL_PROJECTION); calculating a size value needed to specify the left/right and top/bottom limits of the viewing volume size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f))); feed those numbers into gl.glFrustum(), gl.glFrustumf(-size, size, -size /aspectRatio, size /aspectRatio, zNear, zFar);

BouncyCube example. BouncyCube.zip is code from the previous example. The comments are pretty much missing in the example code Which comes from the Apress book listed in the reference section of the lecture.

Solar System example There is also a solarSystem.zip example from the apress book. It has a bouncing ball that rotates. You may want to take a look at the code.

References Much of this lecture and examples are taken from Apress, Pro OpenGL ES for Android, 2012 http://blog.jayway.com/2009/12/04/opengl-es-tutorial-for-android-%E2%80%93-part-ii-building-a-polygon/

Transformations A good look at transformations with lots of pictures and diagrams can be found here. how to understand the coordinate system moving, scaling, and rotating. http://blog.jayway.com/2010/01/01/opengl-es-tutorial-for-android-%E2%80%93-part-iii-%E2%80%93-transformations/ Part IV is about colors, which is also a very good read.

Q A &