List of usage examples for org.lwjgl.opengl GL15 glBufferData
public static void glBufferData(@NativeType("GLenum") int target, @NativeType("void const *") double[] data, @NativeType("GLenum") int usage)
From source file:wrapper.vbo.Vbo.java
License:Open Source License
public void rebind(int size) { FloatBuffer temp = BufferUtils.createFloatBuffer(size); FloatBuffer temp_tex = BufferUtils.createFloatBuffer(size); vertex.rewind();// w w w . j a v a 2s . c o m maxlength = size; texture.rewind(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);// clear and generate // two new memory // locations with a // large amount of space GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp, GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp_tex, GL15.GL_DYNAMIC_DRAW); // reassign the previous data to this , useful for string generation. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertex); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texid); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, texture); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:wrapper.vbo.Vbo.java
License:Open Source License
public void rebind_empty(int size) { FloatBuffer temp = BufferUtils.createFloatBuffer(size); FloatBuffer temp_tex = BufferUtils.createFloatBuffer(size); vertex.rewind();// w w w .j av a 2s . c o m maxlength = size; vertcount = 0; texture.rewind(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);// clear and generate // two new memory // locations with a // large amount of space GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp, GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp_tex, GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:wrath.client.graphics.Model.java
License:Open Source License
/** * Creates a 2D or 3D model from a list of verticies. * Models are always assumed to be made with triangles, and will be rendered as such. * @param name The {@link java.lang.String} name of the Model. * @param verticies The list of verticies in the model. One point is represented by (x, y, z), and there must be at least 3 points. * @param indicies The list of points to connect for OpenGL. Look up indicies in OpenGL for reference. * @param normals The list of 3 float vectors describing the normal vector of the model's surface. * @param useDefaultShaders If true, shaders will be set up automatically. * @return Returns the {@link wrath.client.graphics.Model} object of your model. */// w ww . j av a 2 s . c o m public static Model createModel(String name, float[] verticies, int[] indicies, float[] normals, boolean useDefaultShaders) { // Generating VAO int vaoid = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoid); // Generating Verticies VBO int vtvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtvboid); FloatBuffer vbuffer = BufferUtils.createFloatBuffer(verticies.length); vbuffer.put(verticies); vbuffer.flip(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(VERTICIES_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0); // Generating Normals VBO int nmvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, nmvboid); FloatBuffer nbuffer = BufferUtils.createFloatBuffer(normals.length); nbuffer.put(normals); nbuffer.flip(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, nbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(NORMALS_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0); // Generating Indicies VBO int invboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, invboid); IntBuffer ibuffer = BufferUtils.createIntBuffer(indicies.length); ibuffer.put(indicies); ibuffer.flip(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, ibuffer, GL15.GL_STATIC_DRAW); // Creating Model Object Model model; File mfile = new File("assets/models/" + name); if (!mfile.exists()) model = new Model(name, vaoid, new Integer[] { vtvboid, invboid, nmvboid }, verticies, indicies, normals, useDefaultShaders); else model = new Model(name, vaoid, new Integer[] { vtvboid, invboid, nmvboid }, null, null, null, useDefaultShaders); Game.getCurrentInstance().getLogger().println("Loaded model '" + name + "' with " + verticies.length + " verticies, " + indicies.length + " indicies, and " + normals.length + " normals."); if (useDefaultShaders) model.attachShader(ShaderProgram.DEFAULT_SHADER); // Unbinding OpenGL Objects GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); Game.getCurrentInstance().addToTrashCleanup(model); Game.getCurrentInstance().addToRefreshList(model); return model; }
From source file:wrath.client.graphics.Model.java
License:Open Source License
/** * Applies a {@link wrath.client.graphics.Texture} to the model to be rendered on top of the Model. * Only one can be attached at a time.//w ww . j av a 2 s .com * @param texture The {@link wrath.client.graphics.Texture} to associate with this model. * @param textureCoords The (u, v) coordinates of the texture to the model. */ public void attachTexture(Texture texture, float[] textureCoords) { this.texture = texture; if (this.textureCoords != null) textureCoords = this.textureCoords; if (shader == null) Game.getCurrentInstance().getLogger().println( "Warning: If no shader is present to pass texture co-ordinates, then the texture will not render!"); GL30.glBindVertexArray(vao); int vboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboid); FloatBuffer vbuffer = BufferUtils.createFloatBuffer(textureCoords.length); vbuffer.put(textureCoords); vbuffer.flip(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(TEXTURE_ATTRIB_INDEX, 2, GL11.GL_FLOAT, false, 0, 0); if (shader != null) shader.bindAttribute(TEXTURE_ATTRIB_INDEX, "in_TextureCoord"); GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); vbos.add(vboid); EntityRenderer.preLoadedModels.put(name + "," + texture.getTextureFile().getName(), this); }
From source file:wrath.client.graphics.Model.java
License:Open Source License
@Override public void reload() { float[] varray = null; float[] narray = null; int[] iarray; File modelFile = new File("assets/models/" + name); if (modelFile.exists()) { ArrayList<String> src = readObjFile(modelFile); ArrayList<Vector3f> verticies = new ArrayList<>(); ArrayList<Vector2f> texCoords = new ArrayList<>(); ArrayList<Vector3f> normals = new ArrayList<>(); ArrayList<Integer> indicies = new ArrayList<>(); float[] tarray = null; boolean tmp = true; for (String inp : src) { String[] buf = inp.split(" "); if (inp.startsWith("v ")) verticies.add(new Vector3f(Float.parseFloat(buf[1]), Float.parseFloat(buf[2]), Float.parseFloat(buf[3]))); else if (inp.startsWith("vt ")) texCoords.add(new Vector2f(Float.parseFloat(buf[1]), Float.parseFloat(buf[2]))); else if (inp.startsWith("vn ")) normals.add(new Vector3f(Float.parseFloat(buf[1]), Float.parseFloat(buf[2]), Float.parseFloat(buf[3]))); else if (inp.startsWith("f ")) { if (tmp) { varray = new float[verticies.size() * 3]; narray = new float[verticies.size() * 3]; tarray = new float[verticies.size() * 2]; tmp = false;//from w ww . ja va 2s .com } for (int x = 1; x <= 3; x++) { String[] curDat; if (buf[x].contains("//")) { curDat = buf[x].split("//"); int ptr = Integer.parseInt(curDat[0]) - 1; indicies.add(ptr); Vector3f norm = normals.get(Integer.parseInt(curDat[1]) - 1); narray[ptr * 3] = norm.x; narray[ptr * 3 + 1] = norm.y; narray[ptr * 3 + 2] = norm.z; } else { curDat = buf[x].split("/"); int ptr = Integer.parseInt(curDat[0]) - 1; indicies.add(ptr); Vector2f tex = texCoords.get(Integer.parseInt(curDat[1]) - 1); tarray[ptr * 2] = tex.x; tarray[ptr * 2 + 1] = 1 - tex.y; Vector3f norm = normals.get(Integer.parseInt(curDat[2]) - 1); narray[ptr * 3] = norm.x; narray[ptr * 3 + 1] = norm.y; narray[ptr * 3 + 2] = norm.z; } } } } int i = 0; for (Vector3f ve : verticies) { varray[i] = ve.x; varray[i + 1] = ve.y; varray[i + 2] = ve.z; i += 3; } iarray = new int[indicies.size()]; for (int z = 0; z < indicies.size(); z++) iarray[z] = indicies.get(z); textureCoords = tarray; indiciesLen = iarray.length; } else { varray = verticies; narray = normals; iarray = indicies; indiciesLen = indicies.length; } // Generating VAO vao = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vao); // Generating Verticies VBO int vtvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtvboid); FloatBuffer vbuffer = BufferUtils.createFloatBuffer(varray.length); vbuffer.put(varray); vbuffer.flip(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(VERTICIES_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0); // Generating Normals VBO int nmvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, nmvboid); FloatBuffer nbuffer = BufferUtils.createFloatBuffer(narray.length); nbuffer.put(narray); nbuffer.flip(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, nbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(NORMALS_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0); // Generating Indicies VBO int invboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, invboid); IntBuffer ibuffer = BufferUtils.createIntBuffer(iarray.length); ibuffer.put(iarray); ibuffer.flip(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, ibuffer, GL15.GL_STATIC_DRAW); // Generating Texture VBO int texvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texvboid); FloatBuffer tbuffer = BufferUtils.createFloatBuffer(textureCoords.length); tbuffer.put(textureCoords); tbuffer.flip(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(TEXTURE_ATTRIB_INDEX, 2, GL11.GL_FLOAT, false, 0, 0); // Creating Model Object vbos.add(vtvboid); vbos.add(invboid); vbos.add(nmvboid); vbos.add(texvboid); Game.getCurrentInstance().getLogger().println("Reloaded model '" + name + "'!"); if (defaultShaders) this.attachShader(ShaderProgram.DEFAULT_SHADER); // Unbinding OpenGL Objects GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }