{"id":653,"date":"2011-10-03T09:04:00","date_gmt":"2011-10-03T09:04:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/android-game-development-displaying-graphical-elements-primitives-with-opengl-es.html"},"modified":"2012-10-21T20:33:24","modified_gmt":"2012-10-21T20:33:24","slug":"android-game-development-displaying","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html","title":{"rendered":"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">This is part 2 of the android OpenGL ES series. In the <a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-switching-from.html\">previous<\/a> article  we looked at how to set up the android project to use the provided OpenGL view with our renderer. You can use the project from that article as a template for this.<\/p>\n<p>Before we start displaying things, we must know a few basic concepts of 3D programming and also familiarise ourselves with the terminology. I\u2019s basic geometry really.<\/p>\n<p>3D graphics happens in the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cartesian_coordinate_system#Cartesian_coordinates_in_three_dimensions\">Cartesian Coordinate System<\/a>.<\/p>\n<p>That means that the coordinate system used has three dimensions. <strong>X<\/strong>, <strong>Y<\/strong> and <strong>Z<\/strong>.<\/p>\n<p>Traditionally <strong>X<\/strong> goes from left to right, <strong>Y<\/strong> from bottom to top, and <strong>Z<\/strong> from me into the screen so to speak.<\/p>\n<p>While we deal with objects to display (a robot for example or a car) OpenGL deals with components of these objects. Each object is created from <strong>primitives<\/strong> which in the case of OpenGL is a <strong>triangle<\/strong>. Every <strong>triangle<\/strong> has a <strong>face<\/strong> and a <strong>backface<\/strong>.<\/p>\n<p>A triangle is defined by 3 points in space. A point is called a <strong>vertex<\/strong> (<strong>vertices<\/strong> plural).<\/p>\n<p>The following diagram shows 2 vertices. <strong>A<\/strong> and <strong>B<\/strong>.<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto;margin-right: auto;text-align: center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Vertices.png\"><img decoding=\"async\" border=\"0\" height=\"238\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Vertices.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center\"><span class=\"Apple-style-span\" style=\"font-size: small\">Vertices<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I drew this diagram to show how we will differentiate between 2D and 3D. A vertex is defined by its X, Y and Z coordinates. If we use 0 for the Z component all the time, we have 2D. You can see vertex <strong>A<\/strong> is part of the plane defined by X and Y. Vertex <strong>B<\/strong> is farther in on the Z coordinate. If you think of Z as a line being perpendicular to the screen, we wouldn\u2019t even see <strong>B<\/strong>.<\/p>\n<p>A <strong>triangle<\/strong> is called a <strong>primitive<\/strong>. A primitive is the simplest type OpenGL understands and is able to graphically represent.<\/p>\n<p>It is very simple. 3 vertices define a triangle. There are other primitives as well, like quads but we\u2019ll stick to the basics. Every shape can be broken down into triangles.<\/p>\n<p>We mentioned the <strong>face<\/strong> of the triangle before.<\/p>\n<p>Why is it important? In 3D you will have objects with parts facing towards you, the player and parts facing away from you. In order to make the drawing efficient, OpenGL will not draw the triangles facing away from you as it is not necessary because they will be hidden by the triangles facing towards you anyway. This is called <strong>backface culling<\/strong>.<\/p>\n<p>How does OpenGL determine this? This is determined by the order of the vertices when drawing the triangle. If the order is <em>counter clockwise<\/em> then it is a <em>face<\/em> (green triangle). <em>Clockwise<\/em> order of the vertices means it is a <em>backface<\/em> (the red triangle). This is the default setting but it can be changed of course. The following diagram illustrates just that.<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto;margin-right: auto;text-align: center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Faces.png\"><img decoding=\"async\" border=\"0\" height=\"304\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Faces.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center\"><span class=\"Apple-style-span\" style=\"font-size: small\">Backface Culling<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The red triangle won\u2019t be drawn.<\/p>\n<h2>  Creating and Drawing a Triangle<\/h2>\n<p>With all the theory understood, let\u2019s create a triangle and draw it.<\/p>\n<p>A triangle is defined by 3 vertices. The coordinates of the vertices is not measured in pixels. We will use <strong>float<\/strong> to represent the values and they will be relative to each other.<\/p>\n<p>If a side\u2019s length is <strong>1.0f<\/strong> and an other side\u2019s length is <strong>0.5f<\/strong>, then it means that the second side is half the length of the first side\u2019s length. How big it will be displayed depends on how the viewport is set up. Imagine the viewport as a camera. When we use 2D then it means that the camera is orthogonal to the screen. If the camera is very close, the triangle will appear big, if it\u2019s far, then the triangle will be small.<\/p>\n<p>Let\u2019s create the <strong>Triangle<\/strong> class.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush: java;\">package net.obviam.opengl;\r\n \r\nimport java.nio.ByteBuffer;\r\nimport java.nio.ByteOrder;\r\nimport java.nio.FloatBuffer;\r\n \r\nimport javax.microedition.khronos.opengles.GL10;\r\n \r\npublic class Triangle {\r\n \r\n\tprivate FloatBuffer vertexBuffer;\t\/\/ buffer holding the vertices\r\n \r\n\tprivate float vertices[] = {\r\n\t\t\t-0.5f, -0.5f,  0.0f,\t\t\/\/ V1 - first vertex (x,y,z)\r\n\t\t\t 0.5f, -0.5f,  0.0f,\t\t\/\/ V2 - second vertex\r\n\t\t\t 0.0f,  0.5f,  0.0f\t\t\t\/\/ V3 - third vertex\r\n\t};\r\n \r\n\tpublic Triangle() {\r\n\t\t\/\/ a float has 4 bytes so we allocate for each coordinate 4 bytes\r\n\t\tByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);\r\n\t\tvertexByteBuffer.order(ByteOrder.nativeOrder());\r\n \r\n\t\t\/\/ allocates the memory from the byte buffer\r\n\t\tvertexBuffer = vertexByteBuffer.asFloatBuffer();\r\n \r\n\t\t\/\/ fill the vertexBuffer with the vertices\r\n\t\tvertexBuffer.put(vertices);\r\n \r\n\t\t\/\/ set the cursor position to the beginning of the buffer\r\n\t\tvertexBuffer.position(0);\r\n\t}\r\n}\r\n<\/pre>\n<p>Line <em>11<\/em> defines a <strong>FloatBuffer<\/strong> that will hold the vertices for our triangle. We need to use the java.nio package as it is very intensive input output.<\/p>\n<p>The <strong>vertices[]<\/strong> array holds the actual coordinates for the vertices.<\/p>\n<p>The triangle we will draw is represented in the following diagram. We calculate everything from the origin.<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto;margin-right: auto;text-align: center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Triangle.png\"><img decoding=\"async\" border=\"0\" height=\"251\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Triangle.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center\"><span class=\"Apple-style-span\" style=\"font-size: small\">Triangle<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In the constructor we initialise the triangle from this <strong>vertices[]<\/strong> array.<\/p>\n<p>What we do is, we fill the <strong>vertexBuffer<\/strong> with the coordinates and set the cursor\u2019s position to the beginning of the buffer. We will be using this buffer in the OpenGL call to display triangle strips. We currently have just one.<\/p>\n<p>Let\u2019s take a look at the renderer. The <strong>GlRenderer<\/strong><\/p>\n<pre class=\"brush: java;\">package net.obviam.opengl;\r\n \r\nimport javax.microedition.khronos.egl.EGLConfig;\r\nimport javax.microedition.khronos.opengles.GL10;\r\n \r\nimport android.opengl.GLU;\r\nimport android.opengl.GLSurfaceView.Renderer;\r\n \r\npublic class GlRenderer implements Renderer {\r\n \r\n\tprivate Triangle \ttriangle;\t\/\/ the triangle to be drawn\r\n \r\n\t\/** Constructor *\/\r\n\tpublic GlRenderer() {\r\n\t\tthis.triangle = new Triangle();\r\n\t}\r\n \r\n\t@Override\r\n\tpublic void onDrawFrame(GL10 gl) {\r\n\t\t\/\/ clear Screen and Depth Buffer\r\n\t\tgl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);\r\n \r\n\t\t\/\/ Reset the Modelview Matrix\r\n\t\tgl.glLoadIdentity();\r\n \r\n\t\t\/\/ Drawing\r\n\t\tgl.glTranslatef(0.0f, 0.0f, -5.0f);\t\t\/\/ move 5 units INTO the screen\r\n\t\t\t\t\t\t\t\t\t\t\t\t\/\/ is the same as moving the camera 5 units away\r\n\t\ttriangle.draw(gl);\t\t\t\t\t\t\/\/ Draw the triangle\r\n \r\n\t}\r\n \r\n\t@Override\r\n\tpublic void onSurfaceChanged(GL10 gl, int width, int height) {\r\n\t\tif(height == 0) { \t\t\t\t\t\t\/\/Prevent A Divide By Zero By\r\n\t\t\theight = 1; \t\t\t\t\t\t\/\/Making Height Equal One\r\n\t\t}\r\n \r\n\t\tgl.glViewport(0, 0, width, height); \t\/\/Reset The Current Viewport\r\n\t\tgl.glMatrixMode(GL10.GL_PROJECTION); \t\/\/Select The Projection Matrix\r\n\t\tgl.glLoadIdentity(); \t\t\t\t\t\/\/Reset The Projection Matrix\r\n \r\n\t\t\/\/Calculate The Aspect Ratio Of The Window\r\n\t\tGLU.gluPerspective(gl, 45.0f, (float)width \/ (float)height, 0.1f, 100.0f);\r\n \r\n\t\tgl.glMatrixMode(GL10.GL_MODELVIEW); \t\/\/Select The Modelview Matrix\r\n\t\tgl.glLoadIdentity(); \t\t\t\t\t\/\/Reset The Modelview Matrix\r\n\t}\r\n \r\n\t@Override\r\n\tpublic void onSurfaceCreated(GL10 gl, EGLConfig config) {\r\n\t}\r\n}\r\n<\/pre>\n<p>We create the triangle in the constructor.<\/p>\n<p>The <strong>onDrawFrame(GL10 gl)<\/strong> is of the most interest for us.<\/p>\n<p>OpenGL works with state variables. Every method we call on the OpenGL context changes its internal state.<\/p>\n<p>Following the <strong> onDrawFrame<\/strong> method we see that every time a frame is drawn, the buffers get cleared, the ModelView matrix is reloaded (don\u2019t worry if you don\u2019t understand this at the moment), the camera is moved away 5 units (we\u2019re dealing with units here, not pixels) and the triangle\u2019s <strong>draw()<\/strong> method is called.<\/p>\n<p>The <strong>onSurfaceChanged<\/strong> on the other hand, transitions the OpenGL context between a few states. First it sets the viewport to the current width and height of the surface (so it works with the <em>GL_PROJECTION<\/em> state), then it transitions the state to the <em>GL_MODELVIEW<\/em> so we can work with our models \u2013 the triangle in our case. It will make sense later on, don\u2019t worry.<\/p>\n<p>Let\u2019s check out the <strong>draw<\/strong> method for the triangle:<\/p>\n<pre class=\"brush: java;\">\tpublic void draw(GL10 gl) {\r\n\t\tgl.glEnableClientState(GL10.GL_VERTEX_ARRAY);\r\n \r\n\t\t\/\/ set the colour for the triangle\r\n\t\tgl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);\r\n \r\n\t\t\/\/ Point to our vertex buffer\r\n\t\tgl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);\r\n \r\n\t\t\/\/ Draw the vertices as triangle strip\r\n\t\tgl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length \/ 3);\r\n \r\n\t\t\/\/Disable the client state before leaving\r\n\t\tgl.glDisableClientState(GL10.GL_VERTEX_ARRAY);\r\n\t}\r\n<\/pre>\n<p>Because we store the triangle\u2019s vertices\u2019 coordinates in a <strong>FloatBuffer<\/strong> we need to enable OpenGL to read from it and understand that is a triangle there. Line <em>02<\/em> does just that.<\/p>\n<p>Line <em>05<\/em> sets the colour for the entity (triangle in our case) that will be drawn. Note that the values of the rgb are floats and are between 0.0 and 1.0. <\/p>\n<p><strong>gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);<\/strong> will tell OpenGL to use the <strong>vertexBuffer<\/strong> to extract the vertices from.<\/p>\n<p>The first parameter (value = 3) represents the number of vertices in the buffer. The second lets OpenGL know what type the data the buffer holds.<\/p>\n<p>The third parameter is the offset in the array used for the vertices. Because we don\u2019t store extra data, our vertices follow each other and there is no offset.<\/p>\n<p>Finally the last parameter is our buffer containing the vertices.<\/p>\n<p><strong>gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length \/ 3);<\/strong> tells OpenGL to draw triangle strips found in the buffer provided earlier, starting with the first element. It also lets it know how many vertices there are. <\/p>\n<p>That is it. Run the project and you should be able to see your first accelerated triangle. Just like this:<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Screen-shot-2011-01-23-at-02.39.11.png\"><img decoding=\"async\" border=\"0\" height=\"320\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2011\/01\/Screen-shot-2011-01-23-at-02.39.11.png\" width=\"222\" \/><\/a><\/div>\n<p>Download the source <a href=\"http:\/\/obviam.net\/source_code\/obviam.opengl.p02.tgz\">here (obviam.opengl.p02.tgz)<\/a>:<\/p>\n<p>I was inspired by code from the <a href=\"http:\/\/insanitydesign.com\/wp\/projects\/nehe-android-ports\/\">nehe android ports<\/a>. To learn the guts of OpenGL I warmly recommend the <a href=\"http:\/\/nehe.gamedev.net\/\">nehe tutorials<\/a>.<\/p>\n<p>Next we will see how we can create basic 3D objects and rotate them. We will also find out how we can use textures on elements.<\/p>\n<p><strong>Reference:<\/strong>&nbsp;<a href=\"http:\/\/obviam.net\/index.php\/opengl-es-android-displaying-graphical-elements-primitives\/\">OpenGL ES Android \u2013 Displaying Graphical Elements (Primitives)<\/a>&nbsp;from our&nbsp;<a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG<\/a>&nbsp;partner Tamas Jano&nbsp;from &#8220;<a href=\"http:\/\/obviam.net\/\">Against The Grain<\/a>&#8221; blog.<\/p>\n<div style=\"margin: 0px\">Do not forget to check out our new <strong><i>Android Game<\/i><\/strong> <strong><i><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/jcg-studios-arkdroid-official-launch.html\">ArkDroid<\/a>&nbsp;<span class=\"Apple-style-span\" style=\"font-weight: normal\"><span class=\"Apple-style-span\" style=\"font-style: normal\">(screenshots below)<\/span><\/span><\/i><\/strong>. You feedback will be more than helpful!<\/div>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/1.bp.blogspot.com\/-sEqMxR7YZnY\/ThBGdHcIYnI\/AAAAAAAAABs\/S6iKs2lycyk\/s1600\/multiple_sticky.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/1.bp.blogspot.com\/-sEqMxR7YZnY\/ThBGdHcIYnI\/AAAAAAAAABs\/S6iKs2lycyk\/s200\/multiple_sticky.jpg\" width=\"133\" \/><\/a><a href=\"http:\/\/3.bp.blogspot.com\/-n99pqdxWzqM\/ThBFy-5CGmI\/AAAAAAAAABg\/LfSrtmW-RaQ\/s1600\/multiple_laser.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/3.bp.blogspot.com\/-n99pqdxWzqM\/ThBFy-5CGmI\/AAAAAAAAABg\/LfSrtmW-RaQ\/s200\/multiple_laser.jpg\" width=\"133\" \/><\/a><a href=\"http:\/\/1.bp.blogspot.com\/-0dr410FpxAA\/TgdJc44bfvI\/AAAAAAAAADg\/GyMLvayT_rc\/s1600\/arkdroid_ingame.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/1.bp.blogspot.com\/-0dr410FpxAA\/TgdJc44bfvI\/AAAAAAAAADg\/GyMLvayT_rc\/s200\/arkdroid_ingame.jpg\" width=\"133\" \/><\/a><\/div>\n<div style=\"margin: 0px\"><strong>Related Articles:<\/strong><\/div>\n<ul style=\"text-align: left\">\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/android-game-development-tutorials.html\">Android Game Development Tutorials Introduction<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-idea.html\">Android Game Development &#8211; The Game Idea<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-create-project.html\">Android Game Development &#8211; Create The Project<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game.html\">Android Game Development &#8211; A Basic Game Architecture<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game_05.html\">Android Game Development &#8211; A Basic Game Loop<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html\">Android Game Development &#8211; Displaying Images with Android<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-moving-images.html\">Android Game Development &#8211; Moving Images on Screen<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-loop.html\">Android Game Development &#8211; The Game Loop<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-measuring-fps.html\">Android Game Development &#8211; Measuring FPS<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html\">Android Game Development &#8211; Sprite Animation<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/android-game-development-particle.html\">Android Game Development &#8211; Particle Explosion<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/android-game-development-design-in-game.html\">Android Game Development &#8211; Design In-game Entities &#8211; The Strategy Pattern<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-using-bitmap.html\">Android Game Development &#8211; Using Bitmap Fonts<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-switching-from.html\">Android Game Development &#8211; Switching from Canvas to OpenGL ES<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-opengl-texture.html\">Android Game Development \u2013 OpenGL Texture Mapping<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-design-in-game.html\">Android Game Development \u2013 Design In-game Entities \u2013 The State Pattern<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/?tag=android-games\">Android Games Article Series<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view with our renderer. You can use the project from that article as a template for this. Before we start displaying things, we must know a &hellip;<\/p>\n","protected":false},"author":27,"featured_media":46,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-games"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-10-03T09:04:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:33:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Impaler\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Impaler\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html\"},\"author\":{\"name\":\"Impaler\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bad1a2db4fb0129703629617c049f8c\"},\"headline\":\"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES\",\"datePublished\":\"2011-10-03T09:04:00+00:00\",\"dateModified\":\"2012-10-21T20:33:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html\"},\"wordCount\":1318,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"articleSection\":[\"Android Games\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html\",\"name\":\"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"datePublished\":\"2011-10-03T09:04:00+00:00\",\"dateModified\":\"2012-10-21T20:33:24+00:00\",\"description\":\"This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/android-game-development-displaying.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Android Games\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\\\/android-games\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bad1a2db4fb0129703629617c049f8c\",\"name\":\"Impaler\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"caption\":\"Impaler\"},\"sameAs\":[\"http:\\\/\\\/obviam.net\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Impaler\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES - Java Code Geeks","description":"This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html","og_locale":"en_US","og_type":"article","og_title":"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES - Java Code Geeks","og_description":"This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view","og_url":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-10-03T09:04:00+00:00","article_modified_time":"2012-10-21T20:33:24+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","type":"image\/jpeg"}],"author":"Impaler","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Impaler","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html"},"author":{"name":"Impaler","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bad1a2db4fb0129703629617c049f8c"},"headline":"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES","datePublished":"2011-10-03T09:04:00+00:00","dateModified":"2012-10-21T20:33:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html"},"wordCount":1318,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","articleSection":["Android Games"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html","url":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html","name":"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","datePublished":"2011-10-03T09:04:00+00:00","dateModified":"2012-10-21T20:33:24+00:00","description":"This is part 2 of the android OpenGL ES series. In the previous article we looked at how to set up the android project to use the provided OpenGL view","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/www.javacodegeeks.com\/category\/android"},{"@type":"ListItem","position":3,"name":"Android Games","item":"https:\/\/www.javacodegeeks.com\/category\/android\/android-games"},{"@type":"ListItem","position":4,"name":"Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bad1a2db4fb0129703629617c049f8c","name":"Impaler","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","caption":"Impaler"},"sameAs":["http:\/\/obviam.net\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Impaler"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=653"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/653\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/46"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}