Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static FloatBuffer triangleVertices = allocateFloatBuffer(9 * 16384);
- private static ByteBuffer triangleColors = allocateByteBuffer(12 * 16384);
- public static void render() {
- drawTriangles();
- GLTexture.drawGLTextures();
- try {
- instance.swapBuffers();
- } catch (Exception e) {
- e.printStackTrace();
- }
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
- public static boolean drawTriangle(int x1, int y1, int z1, int x2, int y2, int z2,
- int x3, int y3, int z3, byte r1, byte g1, byte b1, byte a1,
- byte r2, byte g2, byte b2, byte a2, byte r3, byte g3, byte b3, byte a3) {
- if (!USING_DEPTH_BUFFER) {
- GLTexture.drawGLTextures();
- }
- if (triangleColors.position() + 12 >= triangleColors.limit()) {
- drawTriangles();
- }
- triangleColors.put(r1).put(g1).put(b1).put(a1).put(r2).put(g2).put(b2).put(a2)
- .put(r3).put(g3).put(b3).put(a3);
- triangleVertices.put(x1).put(y1).put(z1).put(x2).put(y2).put(z2)
- .put(x3).put(y3).put(z3);
- triangleVertexCount += 3;
- return true;
- }
- public static boolean drawTexturedTriangle(int x1, int y1, int z1, int x2, int y2, int z2,
- int x3, int y3, int z3, int c1, int c2, int c3, int textureID, int[] texturePixels,
- FloatBuffer uvCoords) {
- if (!USING_DEPTH_BUFFER) {
- drawTriangles();
- }
- if (uvCoords == null) {
- uvCoords = GLModel.getDefaultUVCoords();
- }
- GLTexture texture = GLTexture.getGLTexture(textureID, texturePixels);
- texture.getTriangleColors().put(hsbToR[c1]).put(hsbToG[c1]).put(hsbToB[c1])
- .put(hsbToR[c2]).put(hsbToG[c2]).put(hsbToB[c2])
- .put(hsbToR[c3]).put(hsbToG[c3]).put(hsbToB[c3]);
- texture.getTriangleUVs().put(uvCoords.get()).put(uvCoords.get()).put(uvCoords.get())
- .put(uvCoords.get()).put(uvCoords.get()).put(uvCoords.get());
- texture.getTriangleVertices().put(x1).put(y1).put(z1)
- .put(x2).put(y2).put(z2)
- .put(x3).put(y3).put(z3);
- texture.incrimentTriangles();
- return true;
- }
- public static void drawTriangles() {
- if (triangleVertices.position() == 0) {
- return;
- }
- if (!USING_DEPTH_BUFFER) {
- GLTexture.unbindGLTexture();
- }
- triangleColors.flip();
- triangleVertices.flip();
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, triangleColors);
- glVertexPointer(3, 0, triangleVertices);
- glDrawArrays(GL_TRIANGLES, 0, triangleVertexCount);
- triangleColors.clear();
- triangleVertices.clear();
- triangleVertexCount = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement