{"id":172,"date":"2018-10-01T11:55:54","date_gmt":"2018-10-01T02:55:54","guid":{"rendered":"https:\/\/www.dogrow.net\/android\/?p=172"},"modified":"2018-10-04T08:32:19","modified_gmt":"2018-10-03T23:32:19","slug":"blog10","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/android\/blog10\/","title":{"rendered":"(10) OpenGL ES\u306e\u30df\u30cb\u30de\u30e0\u5b9f\u88c5"},"content":{"rendered":"<h1 class=\"my_h\">1. \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>Android\u30a2\u30d7\u30ea\u306e\u753b\u9762\u63cf\u753b\u306b <a href=\"https:\/\/www.khronos.org\/opengles\/\" target=\"_blank\">OpenGL ES<\/a> \u3092\u4f7f\u7528\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>OpenGL\u3068\u306f\u3001\u8a00\u308f\u305a\u3068\u77e5\u308c\u305f\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30a2\u30af\u30bb\u30e9\u30ec\u30fc\u30bf\u3092\u99c6\u4f7f\u3057\u305f\u9ad8\u901f\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u3053\u3068\u3060\u3002<\/p>\n<p>\u3053\u308c\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u30b2\u30fc\u30e0\u4e0a\u306e\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u63cf\u753b\u51e6\u7406\u304c\u9ad8\u901f\u306b\u306a\u308a\u3001\u898b\u305f\u76ee\u304c\u30b9\u30e0\u30fc\u30ba\u306b\u306a\u308b\u306f\u305a\u3002<\/p>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b\uff01<\/h1>\n<h2 class=\"my_h\">(1) \u65b9\u91dd<\/h2>\n<p>\u4eca\u56de\u306f OpenGL ES\u3092\u4f7f\u3046\u7b2c 1\u56de\u76ee\u306a\u306e\u3067\u3001\u4f59\u8a08\u306a\u7269\u3092\u4e00\u5207\u53d6\u3063\u6255\u3063\u305f\u30df\u30cb\u30de\u30e0\u5b9f\u88c5\u3092\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>\u3059\u306a\u308f\u3061&#8230;<br \/>\nOpenGL\u306e Surface View\u3092\u4f5c\u308a\u3001Renderer\u3092\u5272\u308a\u4ed8\u3051\u3001\u76f4\u7dda\u3092\u5f15\u304f\u3060\u3051\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u51e6\u7406\u3092\u66f8\u3044\u3066\u307f\u308b\u3002<\/p>\n<p>\u571f\u53f0\u3055\u3048\u4f5c\u3063\u3066\u3057\u307e\u3048\u3070\u3001\u5f8c\u306f\u305d\u306e\u571f\u53f0\u306e\u4e0a\u3067\u52d5\u304f\u7269\u3092\u51dd\u308c\u3070\u3088\u3044\u3060\u3051\u3060\u3002<\/p>\n<h2 class=\"my_h\">(2) \u5b9f\u88c5<\/h2>\n<p>\u5b9f\u884c\u74b0\u5883\uff1a Android Studio 3.2<\/p>\n<p>Android Studio\u3067\u81ea\u52d5\u751f\u6210\u3057\u305f Empty Activity\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30fc\u30c9\u3092\u4ed8\u3051\u8db3\u3057\u305f\u3002<\/p>\n<p>18\u884c\u76ee : OpenGL\u306e View\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n19\u884c\u76ee : Renderer\uff08\u63cf\u753b\u5236\u5fa1\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\u3092\u751f\u6210\u3057\u3001OpenGL\u306e View\u306b\u5272\u308a\u4ed8\u3051\u308b\u3002<br \/>\n20\u884c\u76ee : Activity\u306b View\u3092\u5272\u308a\u4ed8\u3051\u308b\u3002<br \/>\n24\u884c\u76ee : Renderer\u30af\u30e9\u30b9\uff08\u63cf\u753b\u5236\u5fa1\u30af\u30e9\u30b9\uff09\u3092\u5b9f\u88c5\u3059\u308b\u3002<br \/>\n29\u884c\u76ee : \u753b\u9762\u3044\u3063\u3071\u3044\u3092\u30ad\u30e3\u30f3\u30d0\u30b9\u3068\u3059\u308b\u3002<br \/>\n30\u884c\u76ee : \u63cf\u753b\u306f 2D\u306e\u5e73\u9762\u6295\u5f71\u3068\u3059\u308b\u3002 <a href=\"https:\/\/www.khronos.org\/registry\/OpenGL-Refpages\/gl2.1\/xhtml\/gluOrtho2D.xml\" target=\"_blank\">\u3053\u3061\u3089\u3092\u53c2\u7167<\/a><br \/>\n31\u884c\u76ee : \u9802\u70b9\u914d\u5217\u306e\u4f7f\u7528\u3092\u5ba3\u8a00\u3059\u308b\u3002 <a href=\"https:\/\/www.khronos.org\/registry\/OpenGL-Refpages\/gl2.1\/xhtml\/glEnableClientState.xml\" target=\"_blank\">\u3053\u3061\u3089\u3092\u53c2\u7167<\/a><br \/>\n34\u884c\u76ee : int\u578b\u306e\u5ea7\u6a19\u6307\u5b9a\u306f 1 = 0x10000 \u3068\u306e\u3053\u3068\u3002<br \/>\n35\u884c\u76ee : \u76f4\u7dda\u306e\u70b9\u5ea7\u6a19\u3092\u5b9a\u7fa9\u3059\u308b\u3002<span class=\"my_fc_crimson\">OpenGL\u306e\u5ea7\u6a19\u7cfb\u306f\u753b\u9762\u306e\u5de6\u4e0b\u304c\u539f\u70b9\u3001\u53f3\u5411\u304d\u3001\u4e0a\u5411\u304d\u304c\u6b63\u65b9\u5411<\/span><br \/>\n41\u884c\u76ee : OpenGL\u63cf\u753b\u7528\u30d0\u30c3\u30d5\u30a1\u3092\u30af\u30ea\u30a2\u3059\u308b\u3002<br \/>\n44\u884c\u76ee : \u63cf\u753b\u30c7\u30fc\u30bf\u7528\u30d0\u30c3\u30d5\u30a1\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n48\u884c\u76ee : \u4f5c\u6210\u3057\u305f\u30d0\u30c3\u30d5\u30a1\u306b\u9802\u70b9\u5ea7\u6a19\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308b\u3002<br \/>\n51\u884c\u76ee : \u9802\u70b9\u5ea7\u6a19\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3057\u305f\u30d0\u30c3\u30d5\u30a1\u3092 OpenGL\u306b\u6e21\u3059\u3002<br \/>\n52\u884c\u76ee : Renderer\u306b\u3088\u308b\u63cf\u753b\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport android.opengl.GLSurfaceView;\r\nimport android.opengl.GLSurfaceView.Renderer;\r\nimport android.opengl.GLU;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\n\r\nimport java.nio.ByteBuffer;\r\nimport java.nio.ByteOrder;\r\nimport java.nio.IntBuffer;\r\n\r\nimport javax.microedition.khronos.egl.EGLConfig;\r\nimport javax.microedition.khronos.opengles.GL10;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n    @Override protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        \/\/ OpenGL View, Renderer\u3092\u751f\u6210\uff06\u30a2\u30bf\u30c3\u30c1\r\n        GLSurfaceView surfaceView = new GLSurfaceView(this);\r\n        surfaceView.setRenderer(new MyRenderer());\r\n        setContentView(surfaceView);\r\n    }\r\n\r\n    \/\/ \u753b\u9762\u63cf\u753b\u7528\u306eRenderer\u30af\u30e9\u30b9\r\n    public class MyRenderer implements Renderer {\r\n        @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) {\r\n            \/\/ \u4eca\u56de\u306f\u7279\u306b\u306a\u3057\u3002\r\n        }\r\n        @Override public void onSurfaceChanged(GL10 gl, int width, int height) {\r\n            gl.glViewport(0, 0, width, height);    \/\/ \u753b\u9762\u3044\u3063\u3071\u3044\u3092\u30ad\u30e3\u30f3\u30d0\u30b9\u3068\u3059\u308b\u3002\r\n            GLU.gluOrtho2D( gl, 0.0f, width, 0.0f, height );\r\n            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);    \/\/ \u9802\u70b9\u914d\u5217\u306e\u4f7f\u7528\u3092\u5ba3\u8a00\u3059\u308b\u3002\r\n        }\r\n        @Override public void onDrawFrame(GL10 gl) {\r\n            int one = 0x10000;    \/\/ \u4e0a\u4f4d16bit\u306f\u6574\u6570\u90e8\u3001\u4e0b\u4f4d16bit\u306f\u5c0f\u6570\u90e8\r\n            int vertex&#x5B;] = {\r\n                    100 * one, 100 * one,\r\n                    200 * one, 200 * one,\r\n                    300 * one, 250 * one,\r\n                    600 * one, 600 * one,\r\n            };\r\n            \/\/ \u63cf\u753b\u7528\u30d0\u30c3\u30d5\u30a1\u3092\u30af\u30ea\u30a2\r\n            gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);\r\n            \/\/ \u63cf\u753b\u30c7\u30fc\u30bf\u7528\u30d0\u30c3\u30d5\u30a1\u3092\u4f5c\u6210\u3059\u308b\u3002\r\n            ByteBuffer bytebuffer = ByteBuffer.allocateDirect( vertex.length * 4 );\r\n            bytebuffer.order(ByteOrder.nativeOrder());\r\n            IntBuffer intbuffer = bytebuffer.asIntBuffer();\r\n            \/\/ \u63cf\u753b\u30c7\u30fc\u30bf\u7528\u30d0\u30c3\u30d5\u30a1\u306b\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308b\u3002\r\n            intbuffer.put(vertex);\r\n            intbuffer.position(0);\r\n            \/\/ \u63cf\u753b\u5b9f\u884c\uff01\r\n            gl.glVertexPointer(2, GL10.GL_FIXED, 0, intbuffer);\r\n            gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, vertex.length \/ 2);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\u3067\u304d\u305f\uff01<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/android\/wp-content\/uploads\/2018\/10\/001.png\" alt=\"\" \/><\/p>\n<h1 class=\"my_h\">3. \u5fdc\u7528<\/h1>\n<h2 class=\"my_h\">(1) \u5fdc\u7528\u305d\u306e1<\/h2>\n<p>\u4ee5\u4e0b\u306e 2\u70b9\u3092\u5909\u3048\u3066\u307f\u308b\u3002<br \/>\n1) \u80cc\u666f\u8272\u3092\u9ed2\u304b\u3089\u30b0\u30ec\u30fc\u306b\u5909\u3048\u3066\u307f\u308b\u3002<br \/>\n2) \u7dda\u306e\u63cf\u753b\u8272\u3092\u767d\u304b\u3089\u9ec4\u8272\u306b\u5909\u3048\u3066\u307f\u308b\u3002<\/p>\n<p><span class=\"my_fc_crimson\">\u203b\u5404\u8272\u306e\u8f1d\u5ea6\u6307\u5b9a\u306f 0 ~ 255 \u3067\u306f\u306a\u304f 0.0 ~ 1.0 \u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3002<\/p>\n<p>1) <span class=\"my_fc_deeppink\">onSurfaceCreated<\/span> \u3067\u80cc\u666f\u8272\u3092\u6307\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n    @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) {\r\n        gl.glClearColor(0.5f,0.5f,0.5f,1.0f);\t\/\/\u80cc\u666f\u8272 50%\u30b0\u30ec\u30fc\r\n        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r\n    }\r\n<\/pre>\n<p>2) <span class=\"my_fc_deeppink\">onDrawFrame<\/span> \u3067\u7dda\u306e\u63cf\u753b\u8272\u3092\u6307\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n    \/\/ \u63cf\u753b\u5b9f\u884c\uff01\r\n    gl.glColor4f(1.0f,1.0f,0.0f, 1.0f);   \/\/ \u7dda\u306e\u63cf\u753b\u8272\u3092\u9ec4\u8272\u306b\u3059\u308b\u3002\r\n    gl.glVertexPointer(2, GL10.GL_FIXED, 0, intbuffer);\r\n    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, vertex.length \/ 2);\r\n<\/pre>\n<p>\u3067\u304d\u305f\uff01<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/android\/wp-content\/uploads\/2018\/10\/002.png\" alt=\"\" \/><\/p>\n<h1 class=\"my_h\">4. \u6240\u611f<\/h1>\n<p>\u30fbAndroid\u3067\u306e OpenGL\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f\u3001\u81ea\u5206\u304c\u524d\u306b\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u305f 2010\u5e74\u304b\u3089\u5909\u308f\u3063\u3066\u3044\u306a\u3044\u3088\u3046\u3060\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>1. \u3084\u308a\u305f\u3044\u3053\u3068 Android\u30a2\u30d7\u30ea\u306e\u753b\u9762\u63cf\u753b\u306b OpenGL ES \u3092\u4f7f\u7528\u3057\u3066\u307f\u308b\u3002 OpenGL\u3068\u306f\u3001\u8a00\u308f\u305a\u3068\u77e5\u308c\u305f\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30a2\u30af\u30bb\u30e9\u30ec\u30fc\u30bf\u3092\u99c6\u4f7f\u3057\u305f\u9ad8\u901f\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u3053\u3068\u3060\u3002 \u3053\u308c\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u30b2\u30fc\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/android\/blog10\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-opengl-es"],"views":4240,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":14,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts\/172\/revisions\/357"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}