Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //RawModel.java
- public class RawModel {
- private int vaoID;
- private int vertexCount;
- public void RawMOdel(int vaoID, int vertexCount){
- this.vaoID = vaoID;
- this.vertexCount = vertexCount;
- }
- public in getVaoID(){
- return vaoID;
- }
- public int getVertexCount(){
- return vertexCount;
- }
- }
- //Loader.java
- public class Loader {
- public RawModel loadToVAO(float[] positions){
- int vaoID= createVAO();
- storeDataInAttributeList(0, positions);
- unbindVAO();
- return new RawMOdel(vaoID, positions.length / 3);
- }
- private int createVAO(){
- int vaoID = GL30.glGenVertexArrays();
- GL30.glBindVertexArray(vaoID);
- return vaoID;
- }
- private void storeDataInAttributeList(int attributeNumber, float[] data){
- int vboID = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
- }
- private void unbindVAO(){
- GL30.glBindVertexArray(0);
- }
- }
- //Index Buffers Rendering
- //In Loader.java
- private void bindIndicesBuffer(int[] indices){
- int vboID = GL15.glGenBuffers();
- vbos.add(vboID);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID();
- IntBuffer buffer = storeDataInIntBuffer(indices);
- GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
- }
- //Add:in public RawModel(constructor)
- float[] posistions, int[] indices
- bindIndicesBuffer(indices);
- //Change in renderer:
- GL11.glDrawElements(GL11.GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
- private IntBuffer storeDataInIntBuffer(int[] data){
- IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
- buffer.put(data);
- buffer.flip();
- return buffer;
- }
- //In MaingameLoop.java
- float[] vertices = {
- -0.5f, 0.5f, 0,
- -0.5f, -0.5f, 0,
- 0.5f, -0.5f, 0,
- 0.5f, 0.5f, 0f
- };
- int[] indices = {
- 0, 1, 3,
- 3, 1, 2
- };
- //Texturing
- //Add:
- private List<Integer> texture = new ArrayList<Integer>();
- public int loadTexture(String fileName){
- Texture texture = null;
- try{
- texture = TextureLoader.getTexture("PNG", new FileInputStream("res/"+fileName+".png"));
- } catch (FileNotFoundException e){
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- int textureID = texture.getTextureID();
- return textureID;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement