diff --git a/core/src/com/etheller/warsmash/WarsmashGdxGame.java b/core/src/com/etheller/warsmash/WarsmashGdxGame.java index 2e72845..2099f18 100644 --- a/core/src/com/etheller/warsmash/WarsmashGdxGame.java +++ b/core/src/com/etheller/warsmash/WarsmashGdxGame.java @@ -1,5 +1,8 @@ package com.etheller.warsmash; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.IntBuffer; import java.util.Arrays; import com.badlogic.gdx.ApplicationAdapter; @@ -26,9 +29,20 @@ public class WarsmashGdxGame extends ApplicationAdapter implements CanvasProvide private ModelViewer viewer; private MdxModel model; private CameraManager cameraManager; + private static int VAO; @Override public void create() { + + final ByteBuffer tempByteBuffer = ByteBuffer.allocateDirect(4); + tempByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + final IntBuffer temp = tempByteBuffer.asIntBuffer(); +// + Gdx.gl30.glGenVertexArrays(1, temp); + VAO = temp.get(0); + + Gdx.gl30.glBindVertexArray(VAO); + final String renderer = Gdx.gl.glGetString(GL20.GL_RENDERER); System.err.println("Renderer: " + renderer); @@ -46,8 +60,8 @@ public class WarsmashGdxGame extends ApplicationAdapter implements CanvasProvide this.cameraManager = new CameraManager(); this.cameraManager.setupCamera(scene); -// this.model = (MdxModel) this.viewer.load("units\\human\\footman\\footman.mdx", new PathSolver() { - this.model = (MdxModel) this.viewer.load("Cube.mdx", new PathSolver() { + this.model = (MdxModel) this.viewer.load("units\\human\\footman\\footman.mdx", new PathSolver() { +// this.model = (MdxModel) this.viewer.load("Cube.mdx", new PathSolver() { @Override public SolvedPath solve(final String src, final Object solverParams) { return new SolvedPath(src, src.substring(src.lastIndexOf('.')), true); @@ -62,10 +76,25 @@ public class WarsmashGdxGame extends ApplicationAdapter implements CanvasProvide // // instance.setSequenceLoopMode(2); + System.out.println("Loaded"); +// Gdx.gl30.glClearColor(0.5f, 0.5f, 0.5f, 1); // TODO remove white background + } + + public static void bindDefaultVertexArray() { + Gdx.gl30.glBindVertexArray(VAO); } @Override public void render() { +// this.cameraManager.verticalAngle += 0.01; +// if (this.cameraManager.verticalAngle >= (Math.PI)) { +// this.cameraManager.verticalAngle = 0; +// } + this.cameraManager.horizontalAngle += 0.01; + if (this.cameraManager.horizontalAngle > (2 * Math.PI)) { + this.cameraManager.horizontalAngle = 0; + } + this.cameraManager.updateCamera(); this.viewer.updateAndRender(); // gl.glDrawElements(GL20.GL_TRIANGLES, this.elements, GL20.GL_UNSIGNED_SHORT, this.faceOffset); @@ -114,7 +143,7 @@ public class WarsmashGdxGame extends ApplicationAdapter implements CanvasProvide this.zoomFactor = 0.1f; this.horizontalAngle = (float) (Math.PI / 2); this.verticalAngle = (float) (Math.PI / 4); - this.distance = 500; + this.distance = 5; this.position = new Vector3(); this.target = new Vector3(); this.worldUp = new Vector3(0, 0, 1); diff --git a/core/src/com/etheller/warsmash/WarsmashTestGame.java b/core/src/com/etheller/warsmash/WarsmashTestGame.java new file mode 100644 index 0000000..635aac1 --- /dev/null +++ b/core/src/com/etheller/warsmash/WarsmashTestGame.java @@ -0,0 +1,113 @@ +package com.etheller.warsmash; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.glutils.ShaderProgram; + +public class WarsmashTestGame extends ApplicationAdapter { + private int arrayBuffer; + private int elementBuffer; + private int VAO; + + @Override + public void create() { + Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // colour to use when clearing + + final ByteBuffer tempByteBuffer = ByteBuffer.allocateDirect(4); + tempByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + final IntBuffer temp = tempByteBuffer.asIntBuffer(); + + Gdx.gl30.glGenVertexArrays(1, temp); + this.VAO = temp.get(0); + + Gdx.gl30.glBindVertexArray(this.VAO); + + this.shaderProgram = new ShaderProgram(vsSimple, fsSimple); + if (!this.shaderProgram.isCompiled()) { + throw new IllegalStateException(this.shaderProgram.getLog()); + } + + this.arrayBuffer = Gdx.gl.glGenBuffer(); + this.elementBuffer = Gdx.gl.glGenBuffer(); + System.out.println("arrayBuffer: " + this.arrayBuffer + ", elementBuffer: " + this.elementBuffer); + + Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.arrayBuffer); + + this.shaderProgram.enableVertexAttribute("a_position"); + this.shaderProgram.setVertexAttribute("a_position", 3, GL20.GL_FLOAT, false, 0, 0); + + Gdx.gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, this.elementBuffer); + + final ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(4 * 9); + vertexByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + this.vertexBuffer = vertexByteBuffer.asFloatBuffer(); + + this.vertexBuffer.put(0, -1f); + this.vertexBuffer.put(1, -1f); + this.vertexBuffer.put(2, 0); + this.vertexBuffer.put(3, 1f); + this.vertexBuffer.put(4, -1f); + this.vertexBuffer.put(5, 0); + this.vertexBuffer.put(6, 0f); + this.vertexBuffer.put(7, 1f); + this.vertexBuffer.put(8, 0); + + Gdx.gl.glBufferData(GL20.GL_ARRAY_BUFFER, 9 * 4, null, GL20.GL_STATIC_DRAW); + + final ByteBuffer faceByteBuffer = ByteBuffer.allocateDirect(6); + faceByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + this.faceBuffer = faceByteBuffer.asShortBuffer(); + + this.faceBuffer.put(0, (short) 0); + this.faceBuffer.put(1, (short) 1); + this.faceBuffer.put(2, (short) 2); + + Gdx.gl.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, 3 * 2, null, GL20.GL_STATIC_DRAW); + + } + + @Override + public void render() { + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); + +// Gdx.gl30.glBindVertexArray(this.VAO); + this.shaderProgram.begin(); + Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.arrayBuffer); + Gdx.gl.glBufferSubData(GL20.GL_ARRAY_BUFFER, 0, 9 * 4, this.vertexBuffer); + Gdx.gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, this.elementBuffer); + Gdx.gl.glBufferSubData(GL20.GL_ELEMENT_ARRAY_BUFFER, 0, 3 * 2, this.faceBuffer); + Gdx.gl.glDrawElements(GL20.GL_TRIANGLES, 9, GL20.GL_UNSIGNED_SHORT, 0); +// Gdx.gl.glDrawArrays(GL20.GL_TRIANGLES, 0, 3); + this.shaderProgram.end(); + } + + @Override + public void dispose() { + } + + @Override + public void resize(final int width, final int height) { + } + + public static final String vsSimple = "\r\n" + // + " attribute vec3 a_position;\r\n" + // + " void main() {\r\n" + // + " gl_Position = vec4(a_position, 1.0);\r\n" + // + " }\r\n"; + + public static final String fsSimple = "\r\n" + // + " void main() {\r\n" + // + " gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);\r\n" + // + " }\r\n"; + private ShaderProgram shaderProgram; + private FloatBuffer vertexBuffer; + private ShortBuffer faceBuffer; + +} diff --git a/core/src/com/etheller/warsmash/WarsmashTestGame2.java b/core/src/com/etheller/warsmash/WarsmashTestGame2.java new file mode 100644 index 0000000..8261284 --- /dev/null +++ b/core/src/com/etheller/warsmash/WarsmashTestGame2.java @@ -0,0 +1,138 @@ +package com.etheller.warsmash; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.GL30; + +public class WarsmashTestGame2 extends ApplicationAdapter { + private int VBO; + private int VAO; + + @Override + public void create() { + final ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(4 * 9); + vertexByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + final FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer(); + + vertexBuffer.put(0, -0.5f); + vertexBuffer.put(1, -0.5f); + vertexBuffer.put(2, 0); + vertexBuffer.put(3, 0.5f); + vertexBuffer.put(4, -0.5f); + vertexBuffer.put(5, 0); + vertexBuffer.put(6, 0f); + vertexBuffer.put(7, 0.5f); + vertexBuffer.put(8, 0); + vertexBuffer.clear(); + + Gdx.gl30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + Gdx.gl30.glEnable(GL20.GL_DEPTH_TEST); +// Gdx.gl30.glEnable(GL20.GL_CULL_FACE); + + final ByteBuffer tempByteBuffer = ByteBuffer.allocateDirect(4); + System.out.println(tempByteBuffer.order()); + tempByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + final IntBuffer temp = tempByteBuffer.asIntBuffer(); + + Gdx.gl30.glGenBuffers(1, temp); + this.VBO = temp.get(0); + + temp.clear(); + Gdx.gl30.glGenVertexArrays(1, temp); + this.VAO = temp.get(0); + + Gdx.gl30.glBindVertexArray(this.VAO); + + Gdx.gl30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.VBO); + Gdx.gl30.glBufferData(GL30.GL_ARRAY_BUFFER, 9 * 4, vertexByteBuffer, GL30.GL_STATIC_DRAW); + + Gdx.gl30.glVertexAttribPointer(0, 3, GL30.GL_FLOAT, false, 3 * 4, 0); + Gdx.gl30.glEnableVertexAttribArray(0); + + final int vertexShader = Gdx.gl30.glCreateShader(GL30.GL_VERTEX_SHADER); + Gdx.gl30.glShaderSource(vertexShader, vsSimple); + Gdx.gl30.glCompileShader(vertexShader); + + temp.clear(); + Gdx.gl30.glGetShaderiv(vertexShader, GL30.GL_COMPILE_STATUS, temp); + int success = temp.get(0); + if (success == 0) { + final String infoLog = Gdx.gl30.glGetShaderInfoLog(vertexShader); + System.err.println(infoLog); + throw new IllegalStateException("bad vertex shader"); + } + + final int fragmentShader = Gdx.gl30.glCreateShader(GL30.GL_FRAGMENT_SHADER); + Gdx.gl30.glShaderSource(fragmentShader, fsSimple); + Gdx.gl30.glCompileShader(fragmentShader); + + temp.clear(); + Gdx.gl30.glGetShaderiv(fragmentShader, GL30.GL_COMPILE_STATUS, temp); + success = temp.get(0); + if (success == 0) { + final String infoLog = Gdx.gl30.glGetShaderInfoLog(fragmentShader); + System.err.println(infoLog); + throw new IllegalStateException("bad fragment shader"); + } + + this.shaderProgram = Gdx.gl30.glCreateProgram(); + + Gdx.gl30.glAttachShader(this.shaderProgram, vertexShader); + Gdx.gl30.glAttachShader(this.shaderProgram, fragmentShader); + Gdx.gl30.glLinkProgram(this.shaderProgram); + + temp.clear(); + Gdx.gl30.glGetProgramiv(this.shaderProgram, GL30.GL_LINK_STATUS, temp); + success = temp.get(0); + if (success == 0) { + final String infoLog = Gdx.gl30.glGetProgramInfoLog(this.shaderProgram); + System.err.println(infoLog); + throw new IllegalStateException("bad program"); + } + + Gdx.gl30.glDeleteShader(vertexShader); + Gdx.gl30.glDeleteShader(fragmentShader); + } + + @Override + public void render() { + Gdx.gl30.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); + Gdx.gl30.glUseProgram(this.shaderProgram); + Gdx.gl30.glBindVertexArray(this.VAO); + + Gdx.gl30.glDrawArrays(GL30.GL_TRIANGLES, 0, 3); + } + + @Override + public void dispose() { + } + + @Override + public void resize(final int width, final int height) { + final int side = Math.min(width, height); + Gdx.gl30.glViewport((width - side) / 2, (height - side) / 2, side, side); + + } + + public static final String vsSimple = "\r\n" + // + "#version 450 core\r\n" + // + " layout(location = 0) in vec3 aPos;\r\n" + // + " void main() {\r\n" + // + " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\r\n" + // + " }\r\n"; + + public static final String fsSimple = "\r\n" + // + "#version 450 core\r\n" + // + " out vec4 FragColor;\r\n" + // + " void main() {\r\n" + // + " FragColor = vec4(0.2f, 1.0f, 0.2f, 1.0f);\r\n" + // + " }\r\n"; + private int shaderProgram; + +} diff --git a/core/src/com/etheller/warsmash/WarsmashTestGame3.java b/core/src/com/etheller/warsmash/WarsmashTestGame3.java new file mode 100644 index 0000000..f2b0ee7 --- /dev/null +++ b/core/src/com/etheller/warsmash/WarsmashTestGame3.java @@ -0,0 +1,145 @@ +package com.etheller.warsmash; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.GL30; + +public class WarsmashTestGame3 extends ApplicationAdapter { + private int VBO; + private int VAO; + + @Override + public void create() { + Gdx.gl30.glBindVertexArray(0); + + this.vertexByteBuffer = ByteBuffer.allocateDirect(4 * 9); + this.vertexByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + final FloatBuffer vertexBuffer = this.vertexByteBuffer.asFloatBuffer(); + + vertexBuffer.put(0, -0.5f); + vertexBuffer.put(1, -0.5f); + vertexBuffer.put(2, 0); + vertexBuffer.put(3, 0.5f); + vertexBuffer.put(4, -0.5f); + vertexBuffer.put(5, 0); + vertexBuffer.put(6, 0f); + vertexBuffer.put(7, 0.5f); + vertexBuffer.put(8, 0); + vertexBuffer.clear(); + + Gdx.gl30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + Gdx.gl30.glEnable(GL20.GL_DEPTH_TEST); +// Gdx.gl30.glEnable(GL20.GL_CULL_FACE); + + final ByteBuffer tempByteBuffer = ByteBuffer.allocateDirect(4); + tempByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + final IntBuffer temp = tempByteBuffer.asIntBuffer(); + + Gdx.gl30.glGenVertexArrays(1, temp); + this.VAO = temp.get(0); + + Gdx.gl30.glBindVertexArray(this.VAO); + + temp.clear(); + Gdx.gl30.glGenBuffers(1, temp); + this.VBO = temp.get(0); + + Gdx.gl30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.VBO); + Gdx.gl30.glBufferData(GL30.GL_ARRAY_BUFFER, 9 * 4, this.vertexByteBuffer, GL30.GL_STATIC_DRAW); + + Gdx.gl30.glVertexAttribPointer(0, 3, GL30.GL_FLOAT, false, 3 * 4, 0); + Gdx.gl30.glEnableVertexAttribArray(0); + + final int vertexShader = Gdx.gl30.glCreateShader(GL30.GL_VERTEX_SHADER); + Gdx.gl30.glShaderSource(vertexShader, vsSimple); + Gdx.gl30.glCompileShader(vertexShader); + + temp.clear(); + Gdx.gl30.glGetShaderiv(vertexShader, GL30.GL_COMPILE_STATUS, temp); + int success = temp.get(0); + if (success == 0) { + final String infoLog = Gdx.gl30.glGetShaderInfoLog(vertexShader); + System.err.println(infoLog); + throw new IllegalStateException("bad vertex shader"); + } + + final int fragmentShader = Gdx.gl30.glCreateShader(GL30.GL_FRAGMENT_SHADER); + Gdx.gl30.glShaderSource(fragmentShader, fsSimple); + Gdx.gl30.glCompileShader(fragmentShader); + + temp.clear(); + Gdx.gl30.glGetShaderiv(fragmentShader, GL30.GL_COMPILE_STATUS, temp); + success = temp.get(0); + if (success == 0) { + final String infoLog = Gdx.gl30.glGetShaderInfoLog(fragmentShader); + System.err.println(infoLog); + throw new IllegalStateException("bad fragment shader"); + } + + this.shaderProgram = Gdx.gl30.glCreateProgram(); + + Gdx.gl30.glAttachShader(this.shaderProgram, vertexShader); + Gdx.gl30.glAttachShader(this.shaderProgram, fragmentShader); + Gdx.gl30.glLinkProgram(this.shaderProgram); + + temp.clear(); + Gdx.gl30.glGetProgramiv(this.shaderProgram, GL30.GL_LINK_STATUS, temp); + success = temp.get(0); + if (success == 0) { + final String infoLog = Gdx.gl30.glGetProgramInfoLog(this.shaderProgram); + System.err.println(infoLog); + throw new IllegalStateException("bad program"); + } + + Gdx.gl30.glDeleteShader(vertexShader); + Gdx.gl30.glDeleteShader(fragmentShader); + } + + @Override + public void render() { + + Gdx.gl30.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); + Gdx.gl30.glBindVertexArray(this.VAO); + Gdx.gl30.glUseProgram(this.shaderProgram); + Gdx.gl30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.VBO); + Gdx.gl30.glVertexAttribPointer(0, 3, GL30.GL_FLOAT, false, 3 * 4, 0); + Gdx.gl30.glEnableVertexAttribArray(0); + + Gdx.gl30.glDrawArrays(GL30.GL_TRIANGLES, 0, 3); + } + + @Override + public void dispose() { + } + + @Override + public void resize(final int width, final int height) { + final int side = Math.min(width, height); + Gdx.gl30.glViewport((width - side) / 2, (height - side) / 2, side, side); + + } + + public static final String vsSimple = "\r\n" + // + "#version 450 core\r\n" + // + " layout(location = 0) in vec3 aPos;\r\n" + // + " void main() {\r\n" + // + " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\r\n" + // + " }\r\n"; + + public static final String fsSimple = "\r\n" + // + "#version 450 core\r\n" + // + " out vec4 FragColor;\r\n" + // + " void main() {\r\n" + // + " FragColor = vec4(0.2f, 1.0f, 0.2f, 1.0f);\r\n" + // + " }\r\n"; + private int shaderProgram; + + private ByteBuffer vertexByteBuffer; + +} diff --git a/core/src/com/etheller/warsmash/viewer5/Camera.java b/core/src/com/etheller/warsmash/viewer5/Camera.java index 79dfa53..41925f4 100644 --- a/core/src/com/etheller/warsmash/viewer5/Camera.java +++ b/core/src/com/etheller/warsmash/viewer5/Camera.java @@ -250,7 +250,7 @@ public class Camera { this.topClipPlane, this.nearClipPlane, this.farClipPlane); } - rotation.toMatrix(projectionMatrix.val); + rotation.toMatrix(viewMatrix.val); viewMatrix.translate(vectorHeap.set(location).scl(-1)); inverseRotation.set(rotation).conjugate(); diff --git a/core/src/com/etheller/warsmash/viewer5/ModelViewer.java b/core/src/com/etheller/warsmash/viewer5/ModelViewer.java index 28e27ae..1284991 100644 --- a/core/src/com/etheller/warsmash/viewer5/ModelViewer.java +++ b/core/src/com/etheller/warsmash/viewer5/ModelViewer.java @@ -2,6 +2,7 @@ package com.etheller.warsmash.viewer5; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -57,7 +58,7 @@ public class ModelViewer { this.rectBuffer = this.gl.glGenBuffer(); this.buffer = new ClientBuffer(this.gl); this.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.rectBuffer); - final ByteBuffer temp = ByteBuffer.allocateDirect(6); + final ByteBuffer temp = ByteBuffer.allocateDirect(6).order(ByteOrder.nativeOrder()); temp.put((byte) 0); temp.put((byte) 1); temp.put((byte) 2); @@ -282,7 +283,7 @@ public class ModelViewer { public void startFrame() { this.gl.glDepthMask(true); this.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); - this.gl.glClearColor(0.5f, 0.5f, 0.5f, 1); // TODO remove white background +// WarsmashGdxGame.bindDefaultVertexArray(); } public void render() { diff --git a/core/src/com/etheller/warsmash/viewer5/gl/ClientBuffer.java b/core/src/com/etheller/warsmash/viewer5/gl/ClientBuffer.java index 22ff687..0c513f6 100644 --- a/core/src/com/etheller/warsmash/viewer5/gl/ClientBuffer.java +++ b/core/src/com/etheller/warsmash/viewer5/gl/ClientBuffer.java @@ -1,6 +1,7 @@ package com.etheller.warsmash.viewer5.gl; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.FloatBuffer; import com.badlogic.gdx.graphics.GL20; @@ -33,7 +34,7 @@ public class ClientBuffer { this.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, this.buffer); - this.arrayBuffer = ByteBuffer.allocateDirect(this.size); + this.arrayBuffer = ByteBuffer.allocateDirect(this.size).order(ByteOrder.nativeOrder()); this.gl.glBufferData(GL20.GL_ARRAY_BUFFER, this.size, this.arrayBuffer, GL20.GL_DYNAMIC_DRAW); this.byteView = this.arrayBuffer; this.floatView = this.arrayBuffer.asFloatBuffer(); diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxComplexInstance.java b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxComplexInstance.java index 4792e88..1f22002 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxComplexInstance.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxComplexInstance.java @@ -1,6 +1,7 @@ package com.etheller.warsmash.viewer5.handlers.mdx; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.List; @@ -89,7 +90,8 @@ public class MdxComplexInstance extends ModelInstance { // A shared typed array for all world matrices of the internal nodes. this.worldMatrices = ((List) sharedNodeData[1]).toArray(new Matrix4[0]); - this.worldMatricesCopyHeap = ByteBuffer.allocateDirect(16 * this.worldMatrices.length * 4).asFloatBuffer(); + this.worldMatricesCopyHeap = ByteBuffer.allocateDirect(16 * this.worldMatrices.length * 4) + .order(ByteOrder.nativeOrder()).asFloatBuffer(); // And now initialize all of the nodes and objects for (final Bone bone : model.bones) { diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxRenderBatch.java b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxRenderBatch.java index 2e4a332..f5cf018 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxRenderBatch.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxRenderBatch.java @@ -18,6 +18,7 @@ import com.etheller.warsmash.viewer5.gl.ClientBuffer; import com.etheller.warsmash.viewer5.gl.WebGL; public class MdxRenderBatch extends RenderBatch { + private static final Matrix4 transposeHeap = new Matrix4(); public MdxRenderBatch(final Scene scene, final Model model, final TextureMapper textureMapper) { super(scene, model, textureMapper); @@ -85,8 +86,9 @@ public class MdxRenderBatch extends RenderBatch { shader.setVertexAttribute(m2, 3, GL20.GL_FLOAT, false, 48, 24); shader.setVertexAttribute(m3, 3, GL20.GL_FLOAT, false, 48, 36); - shader.setUniformMatrix4fv("u_VP", this.scene.camera.viewProjectionMatrix.val, 0, - this.scene.camera.viewProjectionMatrix.val.length); + transposeHeap.set(this.scene.camera.viewProjectionMatrix); + transposeHeap.tra(); + shader.setUniformMatrix4fv("u_VP", transposeHeap.val, 0, transposeHeap.val.length); gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, model.arrayBuffer); gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, model.elementBuffer); diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxShaders.java b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxShaders.java index d1360ba..8322d7d 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxShaders.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/MdxShaders.java @@ -66,7 +66,8 @@ public class MdxShaders { " varying vec2 v_uv;\r\n" + // " void main() {\r\n" + // " v_uv = a_uv;\r\n" + // - " gl_Position = u_VP * mat4(a_m0, 0.0, a_m1, 0.0, a_m2, 0.0, a_m3, 1.0) * vec4(a_position, 1.0);\r\n" + // +// " gl_Position = u_VP * mat4(a_m0, 0.0, a_m1, 0.0, a_m2, 0.0, a_m3, 1.0) * vec4(a_position, 1.0);\r\n" + // + " gl_Position = u_VP * vec4(a_position, 1.0);\r\n" + // " }\r\n"; public static final String fsSimple = "\r\n" + // @@ -77,9 +78,9 @@ public class MdxShaders { " void main() {\r\n" + // " vec4 color = texture2D(u_texture, v_uv);\r\n" + // " // 1bit Alpha\r\n" + // - " //if (u_filterMode == 1.0 && color.a < 0.75) {\r\n" + // - " //discard;\r\n" + // - " //}\r\n" + // + " if (u_filterMode == 1.0 && color.a < 0.75) {\r\n" + // + " discard;\r\n" + // + " }\r\n" + // " gl_FragColor = color;\r\n" + // " }\r\n"; diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/SetupGeosets.java b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/SetupGeosets.java index ee38440..498fc6c 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/mdx/SetupGeosets.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/mdx/SetupGeosets.java @@ -1,6 +1,7 @@ package com.etheller.warsmash.viewer5.handlers.mdx; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import java.util.ArrayList; @@ -184,7 +185,8 @@ public class SetupGeosets { } private static ShortBuffer wrapFaces(final int[] faces) { - final ShortBuffer wrapper = ByteBuffer.allocateDirect(faces.length * 2).asShortBuffer(); + final ShortBuffer wrapper = ByteBuffer.allocateDirect(faces.length * 2).order(ByteOrder.nativeOrder()) + .asShortBuffer(); for (final int face : faces) { wrapper.put((short) face); } @@ -193,14 +195,15 @@ public class SetupGeosets { } private static ByteBuffer wrap(final byte[] skin) { - final ByteBuffer wrapper = ByteBuffer.allocateDirect(skin.length); + final ByteBuffer wrapper = ByteBuffer.allocateDirect(skin.length).order(ByteOrder.nativeOrder()); wrapper.put(skin); wrapper.clear(); return wrapper; } private static FloatBuffer wrap(final float[] positions) { - final FloatBuffer wrapper = ByteBuffer.allocateDirect(positions.length * 4).asFloatBuffer(); + final FloatBuffer wrapper = ByteBuffer.allocateDirect(positions.length * 4).order(ByteOrder.nativeOrder()) + .asFloatBuffer(); wrapper.put(positions); wrapper.clear(); return wrapper; diff --git a/desktop/src/com/etheller/warsmash/desktop/DesktopLauncher.java b/desktop/src/com/etheller/warsmash/desktop/DesktopLauncher.java index faef1dc..b4b6f7d 100644 --- a/desktop/src/com/etheller/warsmash/desktop/DesktopLauncher.java +++ b/desktop/src/com/etheller/warsmash/desktop/DesktopLauncher.java @@ -31,6 +31,7 @@ public class DesktopLauncher { }; final LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.useGL30 = true; + config.gles30ContextMajorVersion = 3; config.gles30ContextMinorVersion = 3; new LwjglApplication(new WarsmashGdxGame(), config); }