Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. -- on gl surface creation --
  2.  
  3. GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  4.  
  5. GLES20.glFrontFace(GLES20.GL_CW);
  6. GLES20.glCullFace(GLES20.GL_BACK);
  7. GLES20.glEnable(GLES20.GL_CULL_FACE);
  8.  
  9. GLES20.glDepthFunc(GLES20.GL_LEQUAL);
  10. GLES20.glEnable(GLES20.GL_DEPTH_TEST);
  11.  
  12. GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
  13. GLES20.glEnable(GLES20.GL_BLEND);
  14.  
  15. -- on gl surface changed --
  16.  
  17. GLES20.glViewport(0, 0, width, height);
  18.  
  19. -- activating 'material' before draw --
  20.  
  21. GLES20.glUseProgram(shaderId);
  22. checkGlError("glUseProgram");
  23.  
  24. GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  25. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
  26.  
  27. -- on draw --
  28.  
  29. alphaHandle = GLES20.glGetAttribLocation(material.getShader(), "aAlpha");
  30. checkGlError("glGetAttribLocation aAlpha");
  31. if (alphaHandle == GL_ERROR)
  32. {
  33.     throw new RuntimeException("Could not get attribute location for aAlpha");
  34. }
  35.  
  36. GLES20.glVertexAttrib1f(alphaHandle, alpha);
  37. checkGlError("glVertexAttrib1f alphaHandle");
  38.  
  39. /*
  40.  * GRID POSITION
  41.  */
  42.  
  43. positionHandle = GLES20.glGetAttribLocation(material.getShader(), "aPosition");
  44. checkGlError("glGetAttribLocation aPosition");
  45. if (positionHandle == GL_ERROR)
  46. {
  47.     throw new RuntimeException("Could not get attribute location for uPosition");
  48. }
  49.  
  50. GLES20.glVertexAttrib3f(positionHandle, position.x, position.y, position.z);
  51. checkGlError("glVertexAttrib3f positionHandle");
  52.  
  53. /*
  54.  * VERTICES
  55.  */
  56.  
  57. vertexHandle = GLES20.glGetAttribLocation(material.getShader(), "aVertex");
  58. checkGlError("glGetAttribLocation aVertex");
  59. if (vertexHandle == GL_ERROR)
  60. {
  61.     throw new RuntimeException("Could not get attrib location for aVertex");
  62. }
  63.  
  64. GLES20.glEnableVertexAttribArray(vertexHandle);
  65. checkGlError("glEnableVertexAttribArray vertexHandle");
  66.  
  67. mesh.getVertexBuffer().position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
  68. GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mesh.getVertexBuffer());
  69. checkGlError("glVertexAttribPointer vertexHandle");
  70.  
  71. /*
  72.  * TEXTURE COORDS
  73.  */
  74.  
  75. textureHandle = GLES20.glGetAttribLocation(material.getShader(), "aTextureCoord");
  76. checkGlError("glGetAttribLocation aTextureCoord");
  77. if (textureHandle == GL_ERROR)
  78. {
  79.     throw new RuntimeException("Could not get attrib location for aTextureCoord");
  80. }
  81.  
  82. GLES20.glEnableVertexAttribArray(textureHandle);
  83. checkGlError("glEnableVertexAttribArray textureHandle");
  84.  
  85. mesh.getVertexBuffer().position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
  86. GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mesh.getVertexBuffer());
  87. checkGlError("glVertexAttribPointer textureHandle");
  88.  
  89. /*
  90.  * MATRICES
  91.  */
  92.  
  93. mvpMatrixHandle = GLES20.glGetUniformLocation(material.getShader(), "uMVPMatrix");
  94. checkGlError("glGetUniformLocation uMVPMatrix");
  95. if (mvpMatrixHandle == GL_ERROR)
  96. {
  97.     throw new RuntimeException("Could not get attrib location for uMVPMatrix");
  98. }
  99.  
  100. Matrix.setIdentityM(mMatrix, 0);
  101.  
  102. GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, DroidGL.getActiveCamera().getModelViewProjectionMatrix(mMatrix), 0);
  103.  
  104. /*
  105.  * DRAW
  106.  */
  107.  
  108. GLES20.glDrawElements(GLES20.GL_TRIANGLES, mesh.getNumIndices(), GLES20.GL_UNSIGNED_SHORT, mesh.getIndexBuffer());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement