Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NewMap {
- int vaoID;
- int vertexBufferID;
- int indexBufferID;
- Shader shader = ShaderManager.getShader("SimpleColor");
- int indexCount;
- public NewMap()
- {
- VertexData v0 = new VertexData();
- v0.setXYZ(-1, -1, 0); v0.setNXYZ(0, 0, -1); v0.setUV(0, 0);
- VertexData v1 = new VertexData();
- v1.setXYZ(0, 1, 0); v1.setNXYZ(0, 0, -1); v1.setUV(1, 1);
- VertexData v2 = new VertexData();
- v2.setXYZ(1, -1, 0); v2.setNXYZ(0, 0, -1); v2.setUV(1, 0);
- VertexData[] data = new VertexData[] {v0, v1, v2};
- FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(data.length * VertexData.elementCount);
- for(int i = 0; i < data.length; i++)
- {
- vertBuffer.put(data[i].getElements());
- }
- vertBuffer.flip();
- byte[] indices = new byte[]
- {
- 0, 1, 2
- };
- indexCount = indices.length;
- ByteBuffer indexBuffer = BufferUtils.createByteBuffer(indices.length);
- indexBuffer.put(indices);
- indexBuffer.flip();
- vaoID = GL30.glGenVertexArrays();
- GL30.glBindVertexArray(vaoID);
- vertexBufferID = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferID);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertBuffer, GL15.GL_STATIC_DRAW);
- GL20.glVertexAttribPointer(0, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.positionOffset);
- GL20.glVertexAttribPointer(1, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.textureOffset);
- GL20.glVertexAttribPointer(2, VertexData.normalElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.normalOffset);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- GL30.glBindVertexArray(0);
- indexBufferID = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
- GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL15.GL_STATIC_DRAW);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
- GL20.glUseProgram(shader.getID());
- GL20.glBindAttribLocation(shader.getID(), 0, "inPosition");
- GL20.glBindAttribLocation(shader.getID(), 1, "inTexCoord");
- GL20.glBindAttribLocation(shader.getID(), 2, "inNormal");
- GL20.glUseProgram(0);
- }
- public void render(Camera cam)
- {
- GL20.glUseProgram(shader.getID());
- shader.setUniformMatrix("projMat", cam.getProjection());
- shader.setUniformMatrix("viewMat", cam.getView());
- shader.setUniformMatrix("modelMat", new Matrix4f());
- shader.setUniformVec("lightDirection", new Vector3f(0, 0, 1));
- shader.setUniformVec("diffuseColor", new Vector4f(1, 1, 1, 1));
- shader.setUniformVec("ambientColor", new Vector4f(0.15f, 0.15f, 0.15f, 1f));
- GL30.glBindVertexArray(vaoID);
- GL20.glEnableVertexAttribArray(0);
- GL20.glEnableVertexAttribArray(1);
- GL20.glEnableVertexAttribArray(2);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
- GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_BYTE, 0);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
- GL20.glDisableVertexAttribArray(0);
- GL20.glDisableVertexAttribArray(1);
- GL20.glDisableVertexAttribArray(2);
- GL30.glBindVertexArray(0);
- GL20.glUseProgram(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement