Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. private static FloatBuffer triangleVertices = allocateFloatBuffer(9 * 16384);
  2. private static ByteBuffer triangleColors = allocateByteBuffer(12 * 16384);
  3.  
  4. public static void render() {
  5. drawTriangles();
  6. GLTexture.drawGLTextures();
  7. try {
  8. instance.swapBuffers();
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }
  12. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  13. }
  14.  
  15. public static boolean drawTriangle(int x1, int y1, int z1, int x2, int y2, int z2,
  16. int x3, int y3, int z3, byte r1, byte g1, byte b1, byte a1,
  17. byte r2, byte g2, byte b2, byte a2, byte r3, byte g3, byte b3, byte a3) {
  18. if (!USING_DEPTH_BUFFER) {
  19. GLTexture.drawGLTextures();
  20. }
  21. if (triangleColors.position() + 12 >= triangleColors.limit()) {
  22. drawTriangles();
  23. }
  24. triangleColors.put(r1).put(g1).put(b1).put(a1).put(r2).put(g2).put(b2).put(a2)
  25. .put(r3).put(g3).put(b3).put(a3);
  26. triangleVertices.put(x1).put(y1).put(z1).put(x2).put(y2).put(z2)
  27. .put(x3).put(y3).put(z3);
  28. triangleVertexCount += 3;
  29. return true;
  30. }
  31.  
  32. public static boolean drawTexturedTriangle(int x1, int y1, int z1, int x2, int y2, int z2,
  33. int x3, int y3, int z3, int c1, int c2, int c3, int textureID, int[] texturePixels,
  34. FloatBuffer uvCoords) {
  35. if (!USING_DEPTH_BUFFER) {
  36. drawTriangles();
  37. }
  38. if (uvCoords == null) {
  39. uvCoords = GLModel.getDefaultUVCoords();
  40. }
  41. GLTexture texture = GLTexture.getGLTexture(textureID, texturePixels);
  42. texture.getTriangleColors().put(hsbToR[c1]).put(hsbToG[c1]).put(hsbToB[c1])
  43. .put(hsbToR[c2]).put(hsbToG[c2]).put(hsbToB[c2])
  44. .put(hsbToR[c3]).put(hsbToG[c3]).put(hsbToB[c3]);
  45. texture.getTriangleUVs().put(uvCoords.get()).put(uvCoords.get()).put(uvCoords.get())
  46. .put(uvCoords.get()).put(uvCoords.get()).put(uvCoords.get());
  47. texture.getTriangleVertices().put(x1).put(y1).put(z1)
  48. .put(x2).put(y2).put(z2)
  49. .put(x3).put(y3).put(z3);
  50. texture.incrimentTriangles();
  51. return true;
  52. }
  53.  
  54. public static void drawTriangles() {
  55. if (triangleVertices.position() == 0) {
  56. return;
  57. }
  58. if (!USING_DEPTH_BUFFER) {
  59. GLTexture.unbindGLTexture();
  60. }
  61. triangleColors.flip();
  62. triangleVertices.flip();
  63. glColorPointer(4, GL_UNSIGNED_BYTE, 0, triangleColors);
  64. glVertexPointer(3, 0, triangleVertices);
  65. glDrawArrays(GL_TRIANGLES, 0, triangleVertexCount);
  66. triangleColors.clear();
  67. triangleVertices.clear();
  68. triangleVertexCount = 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement