 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.

Slides:



Advertisements
Similar presentations
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Advertisements

Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
The View Frustum and the Camera Lecture 19 Fri, Oct 10, 2003.
Basics. OpenGL. “Hello world” George Georgiev Telerik Corporation
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
OpenGL (II). How to Draw a 3-D object on Screen?
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
Geometric Objects and Transformations. Coordinate systems rial.html.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Week 2 - Wednesday CS361.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
CSE Real Time Rendering Week 2. Graphics Processing 2.
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.
Exam Review Questions. Problem: A cube has vertices with world coordinates: (1, 0, 0) (2, 0, 0) (1, 1, 0) (2, 1, 0) (1, 0, 1) (2, 0, 1) (1, 1, 1) (2,
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
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.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
Honours Graphics 2008 Session 3. Today’s focus Perspective and orthogonal projection Quaternions Graphics camera.
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.
OpenGL Shading Language
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
Mobile & Casual Gaming OpenGL ES Intro. /red/chapter03.html.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
OpenGL LAB III.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
- Introduction - Graphics Pipeline
CS451Real-time Rendering Pipeline
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Programming 3D Graphics
Chapter VI OpenGL ES and Shader
Projection in 3-D Glenn G. Chappell
ICG 2018 Fall Homework1 Guidance
Programming with OpenGL Part 3: Shaders
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CS 480/680 Computer Graphics GLSL Overview.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame so that the triangles will MOVE!!

 onCreate: each time you run the program, this function must execute first /** Hold a reference to our GLSurfaceView */ private GLSurfaceView mGLSurfaceView; mGLSurfaceView = new GLSurfaceView(this); GLSurfaceView manages OpenGL surfaces for us and draws it into the Android view system. Call constructor.

 Check if system supports OpenGL ES 2.0 final ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVI TY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); After the above code, the OpenGL ES configuration information is in configurationInfo.reqGlEsVersion

 Check if system supports OpenGL ES 2.0 final boolean supportsEs2 = true; //configurationInfo.reqGlEsVersion >= 0x20000; If you want to run the code in Android Emulator, you must let the code like above ( that is, let the check passes ), or the emulation would fails !!!

 If it supports, set the context and the renderer. if (supportsEs2) { // Request an OpenGL ES 2.0 compatible context. mGLSurfaceView.setEGLContextClientVersion(2); // Set the renderer mGLSurfaceView.setRenderer(new LessonOneRenderer()); }

 Some activity functions that can be defined protected void onResume() //resume the saved data protected void onPause() //execute in idle mode, it will save the data

Activity starts onCreate() onStart() onResume() Activity Is running onRestart() onStop() Activity comes to the foreground Activity comes to the foreground Use navigates back to the Activity Other applications need memory Shut down Activity onPause() Activity is invisible New Activity is started Process is killed onDestroy()

 Let’s start with triangles. /** Store our model data in a float buffer. */ private final FloatBuffer mTriangle1Vertices; private final FloatBuffer mTriangle2Vertices; private final FloatBuffer mTriangle3Vertices; In OpenGL ES 2.0, the vertices become a data that store in the buffer first, so declare the buffers for the triangles.

 In constructor MyLessonOneRender() final float[] triangle1VerticesData = { // X, Y, Z, // R, G, B, A -0.5f, -0.25f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.5f, -0.25f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}; Initialize the position and color of the vertices

Geometry Position / vertex normals / vertex colors / texture coordinates Topology Primitive Lines / triangles / surfaces / … Geometry Data

 In constructor MyLessonOneRender() mTriangle1Vertices = ByteBuffer.allocateDirect(triangle1VerticesData.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer(); mTriangle1Vertices.put(triangle1VerticesData).position(0); We need to copy the data in another buffer which will be passed to OpenGL ES API. We must convert our data into a FloatBuffer so that we can use it to hold floating-point data.

 Second, the matrices for projecting the objects onto the view space. Three Matrices  Model Matrix M  View Matrix V  Projection Matrix P Putting them together: P V M (model vertices) eye View frustum

 The object has its orientation. When you put the object in the scene.  Model Matrix represents the transformation from object space to world space.

 Can use the Matrix helper class to help us  Matrix.setIdentityM(mModelMatrix, 0);  Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);  Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f); long time = SystemClock.uptimeMillis() % 10000L; //system time float angleInDegrees = (360.0f / f) * ((int) time); //varies based on time Initialize the model matrix Perform simple rotation Perform simple translation

Object Space X Z World Space Z X Camera X Z X Z Z X X Z X Z View Space Apply model matrix Apply view matrix

 The camera also has its space  The view matrix represent the transforms from world space to camera space.

private float[] mViewMatrix = new float[16]; public void onSurfaceCreated(GL10 glUnused, EGLConfig config){ … Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);

eyeX, eyeY, eyeZ: eye position lookX, lookY, lookZ: look vector upX, upY, upZ: up vector

X Z X Z View Space X Z X Z Projection Space Far clipping plane Near clipping plane Z-axis direction: camera view direction

22 Camera 3D Models Lights Projection Plane Board A 3D Scene Projection Matrix The projection matrix specifies near and far view distance, angle of the view of the camera and the screen resolution proportion.

 Set Projection Matrix in OpenGL ES Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);  Combine the above matrix together private float[] mMVPMatrix = new float[16]; //MVPMatrix = Model * View * Projection //( “*” means matrix multiplication)

 In openGL ES 2.0, you can define your own vertex shader and fragment shader!!!  Vertex Shader Modify/create/ignore attributes of vertex, such as position, color, normal, texture coordinates  Fragment(Pixel) Shader Per-pixel lighting, allowing complex shading equation to be evaluated per pixel.

 Shader coding process in OpenGL ES Edit the shaders Load the shaders Link the shaders into a program

final String vertexShader = "uniform mat4 u_MVPMatrix; \n“ + "attribute vec4 a_Position; \n“ + "attribute vec4 a_Color; \n“ + "varying vec4 v_Color; \n" + "void main() \n" + "{ \n" + " v_Color = a_Color; \n“ + " gl_Position = u_MVPMatrix \n" + " * a_Position; \n" + "} \n"; The combined model/view/projection matrix. The final color that will be passed to fragment shader. Pass the color. Shader will help us do triangle interpolation. Multiply the vertex by the matrix to get the final point(gl_Position).

final String fragmentShader = "precision mediump float; \n“ + "varying vec4 v_Color; \n" + "void main() \n“ + "{ \n" + " gl_FragColor = v_Color; \n“ + "} \n"; Pass the color through the pipeline.

 Load the shaders int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); // Pass in the shader source. GLES20.glShaderSource(vertexShaderHandle, vertexShader); // Compile the shader. GLES20.glCompileShader(vertexShaderHandle); // Get the compilation status. final int[] compileStatus = new int[1]; GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

 Load the shaders // If the compilation failed, delete the shader. if (compileStatus[0] == 0) { GLES20.glDeleteShader(vertexShaderHandle); vertexShaderHandle = 0; }  Similarly, we can load the fragment shaders.

 Link the shaders into a program Before we can use our vertex and fragment shader, we need to bind them together into a program. The process of link the shaders  Create a new program object  If that succeeded, we then attach our shaders  Bind the attributes in the shader code  Link the program

 Link the shaders into a program int programHandle = GLES20.glCreateProgram(); // Bind the vertex shader to the program. GLES20.glAttachShader(programHandle, vertexShaderHandle); // Bind the fragment shader to the program. GLES20.glAttachShader(programHandle, fragmentShaderHandle); // Bind attributes GLES20.glBindAttribLocation(programHandle, 0, "a_Position"); GLES20.glBindAttribLocation(programHandle, 1, "a_Color"); // Link the two shaders together into a program. GLES20.glLinkProgram(programHandle);

 After linking, we can… Pass data into the program mMVPMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVPMatrix"); mPositionHandle = GLES20.glGetAttribLocation(programHandle, "a_Position"); mColorHandle = GLES20.glGetAttribLocation(programHandle, "a_Color"); Tell OpenGL to use this program for rendering. GLES20.glUseProgram(programHandle);

 In the example, we define drawTriangle function to handle the drawing part.  The process of drawTriangle Pass in the position information Pass in the color information Pass in the final matrix to the vertex shader using GLES20.glUniformMatrix4fv(). Converts the points into a triangle and draws it on the screen using GLES20.glDrawArrays().

 Can you draw a program to display more triangles?

 Learn OpenGL ES  OpenGL Transformation rm.html rm.html  World, View and Projection Matrix Unveiled view-projection-matrix-unveiled/ view-projection-matrix-unveiled/