Created
January 9, 2014 22:27
-
-
Save maluramichael/8343268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VIEW | |
1.0 0.0 0.0 0.0 | |
0.0 1.0 0.0 0.0 | |
0.0 0.0 1.0 0.0 | |
0.0 0.0 0.0 1.0 | |
PROJECTION | |
2.4142134 0.0 0.0 0.0 | |
0.0 2.4142134 0.0 0.0 | |
0.0 0.0 -1.0 -0.0 | |
0.0 0.0 -1.0 0.0 | |
PROJECTION TRANSPOSE | |
2.4142134 0.0 0.0 0.0 | |
0.0 2.4142134 0.0 0.0 | |
0.0 0.0 -1.0 -1.0 | |
0.0 0.0 -0.0 0.0 | |
MODEL | |
5.0 0.0 0.0 0.0 | |
0.0 5.0 0.0 0.0 | |
0.0 0.0 5.0 0.0 | |
0.0 0.0 0.0 1.0 | |
RENDER FUNCTION | |
Matrix4f viewMatrix = world.getCamera().getViewMatrix(); | |
Matrix4f projectionMatrix = world.getCamera().getProjectionMatrix(); | |
Mesh mesh = ((MeshComponent) entity.getComponentByClass(MeshComponent.class)).getMesh(); | |
Shader shader = ((ShaderComponent) entity.getComponentByClass(ShaderComponent.class)).getShader(); | |
if (mesh == null || shader == null) return; | |
Matrix4f modelMatrix = ((ModelMatrixComponent) entity.getComponentByClass(ModelMatrixComponent.class)).getModelMatrix(); | |
GL11.glEnable(GL11.GL_DEPTH_TEST); | |
GL11.glEnable(GL11.GL_TEXTURE_2D); | |
shader.bind(); | |
mesh.bind(); | |
OpenGLUtil.checkError(); | |
FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16); | |
modelMatrix.store(matrixBuffer); | |
matrixBuffer.flip(); | |
shader.setUniform("modelMatrix", modelMatrix); | |
OpenGLUtil.checkError(); | |
viewMatrix.store(matrixBuffer); | |
matrixBuffer.flip(); | |
shader.setUniform("viewMatrix", viewMatrix); | |
OpenGLUtil.checkError(); | |
projectionMatrix.store(matrixBuffer); | |
matrixBuffer.flip(); | |
shader.setUniform("projectionMatrix", projectionMatrix, true); | |
OpenGLUtil.checkError(); | |
int positionAttribute = GL20.glGetAttribLocation(shader.getProgramId(), "position"); | |
OpenGLUtil.checkError(); | |
GL20.glEnableVertexAttribArray(positionAttribute); | |
GL20.glVertexAttribPointer(positionAttribute, 4, GL11.GL_FLOAT, false, 0, 0); | |
OpenGLUtil.checkError(); | |
GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndexCount(), GL11.GL_UNSIGNED_INT, 0); | |
OpenGLUtil.checkError(); | |
mesh.unbind(); | |
shader.unbind(); | |
OpenGLUtil.checkError(); | |
GL20.glDisableVertexAttribArray(positionAttribute); | |
OpenGLUtil.checkError(); | |
GL11.glDisable(GL11.GL_DEPTH_TEST); | |
GL11.glDisable(GL11.GL_TEXTURE_2D); | |
OpenGLUtil.checkError(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment