List of usage examples for org.lwjgl.opengl GL15 glBindBuffer
public static void glBindBuffer(@NativeType("GLenum") int target, @NativeType("GLuint") int buffer)
From source file:game.level.map.TileMapGenerator.java
License:Open Source License
public static int[] RebuildMesh(int[][] map, int startZ) { long startTime; long endTime; Map = map;//from ww w .jav a 2s . c o m int count[] = CountWalls_Floors(); int[] Handles = new int[3]; int VBOVertexHandle = GL15.glGenBuffers(); int VBOColorHandle = GL15.glGenBuffers(); int VBONormalHandle = GL15.glGenBuffers(); Random rGen = new Random(); startTime = System.currentTimeMillis(); FloatBuffer VertexPositionData = BufferUtils .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3)); FloatBuffer VertexColorData = BufferUtils .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3)); FloatBuffer VertexNormalData = BufferUtils .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3)); for (float y = 0; y < Map.length; y++) { for (float x = 0; x < Map[0].length; x++) { if (Map[(int) y][(int) x] > 0) { for (float x1 = 0; x1 < DIVISIONS; x1++) { for (float y1 = 0; y1 < DIVISIONS; y1++) { for (float z1 = 0; z1 < DIVISIONS; z1++) { if (y1 == 0 || x1 == 0 || z1 == 0 || y1 == DIVISIONS - 1 || x1 == DIVISIONS - 1 || z1 == DIVISIONS - 1) { VertexPositionData .put(CreateCube(x * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS * x1, y * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS * y1, startZ - z1 * WALL_SCALAR, CUBE_LENGTH / DIVISIONS)); GenerateDefaultCubeData(VertexColorData, VertexNormalData, Map[(int) y][(int) x], rGen); } } } } } else if (Map[(int) y][(int) x] == 0) { } else { VertexPositionData.put(CreateFloor(x * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS, y * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS, startZ)); GenerateDefaultFloorData(VertexColorData, VertexNormalData, Map[(int) y][(int) x], rGen); } } } // GEN CUBES HERE VertexPositionData.flip(); VertexColorData.flip(); VertexNormalData.flip(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBONormalHandle); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexNormalData, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); Handles[0] = VBOVertexHandle; Handles[1] = VBOColorHandle; Handles[2] = VBONormalHandle; endTime = System.currentTimeMillis(); System.out.println("Took " + Long.toString((endTime - startTime) / 1000) + " seconds to build a map."); return Handles; }
From source file:go.graphics.swing.opengl.LWJGLDrawContext.java
License:Open Source License
private void bindArrayBuffer(GeometryHandle geometry) throws IllegalBufferException { int id;/*from w w w .j a v a 2 s . c o m*/ if (geometry == null) { id = 0; } else { if (!geometry.isValid()) { throw new IllegalBufferException("Geometry handle is not valid: " + geometry); } id = geometry.getInternalId(); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id); }
From source file:go.graphics.swing.opengl.LWJGLDrawContext.java
License:Open Source License
@Override public void endWriteGeometry(GeometryHandle geometry) { if (canUseVBOs) { GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }// w w w .j a v a2 s. co m }
From source file:go.graphics.swing.opengl.LWJGLDrawContext.java
License:Open Source License
@Override public GeometryHandle generateGeometry(int bytes) { int vertexBufferId; if (canUseVBOs) { vertexBufferId = allocateVBO();/* w ww. ja v a2s. co m*/ if (vertexBufferId == 0) { return null; } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, BufferUtils.createByteBuffer(bytes), GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } else { ByteBuffer bb = ByteBuffer.allocateDirect(bytes); bb.order(ByteOrder.nativeOrder()); vertexBufferId = geometries.size(); geometries.add(bb); } return new LWJGLGeometryHandle(this, vertexBufferId); }
From source file:gui.lwjgl.GUIElementLoader.java
/** * Stores data in an attribute list of a VAO. * * @param vaoID The id of the VAO to which data will be added. * @param attributeNumber The number of the attribute list in which the data * will be stored./*from w w w.j ava 2 s .com*/ * @param data The data that will be stored in the attribute list. */ private static void storeDataInAttributeList(int vaoID, int attributeNumber, int coordinateSize, float[] data) { // bind VAO so that it can be used. bindVAO(vaoID); // Create new VBO. int vboID = GL15.glGenBuffers(); // Adds VBO to list so that it can be cleared when needed. vbos.add(vboID); // VBO has to be bound aswel. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); // Converts float array to an instance of FloatBuffer, which can // be stored in a VBO. FloatBuffer buffer = Convert.toReadableFloatBuffer(data); // Puts the buffer into the VBO, and GL_STATIC_DRAW tells it that it // won't ever be modified. GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); // Specifies that this is for the Vertex Array. GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0); // Unbind the VBO. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // unbind VAO so that another may be bound. unbindVAO(); }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glBindBuffer(int target, int buffer) { GL15.glBindBuffer(target, buffer); }
From source file:itdelatrisu.opsu.render.CurveRenderState.java
License:Open Source License
/** * Restore the old OpenGL state that's backed up in {@code state}. * @param state the old state to restore *///from w ww. ja v a2 s .c o m private void endRender(RenderState state) { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPopMatrix(); GL11.glEnable(GL11.GL_BLEND); GL20.glUseProgram(state.oldProgram); GL13.glActiveTexture(state.texUnit); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer); if (!state.depthWriteEnabled) GL11.glDepthMask(false); if (!state.depthEnabled) GL11.glDisable(GL11.GL_DEPTH_TEST); if (state.texEnabled) GL11.glEnable(GL11.GL_TEXTURE_2D); if (state.smoothedPoly) GL11.glEnable(GL11.GL_POLYGON_SMOOTH); if (!state.blendEnabled) GL11.glDisable(GL11.GL_BLEND); }
From source file:itdelatrisu.opsu.render.CurveRenderState.java
License:Open Source License
/** * Do the actual drawing of the curve into the currently bound framebuffer. * @param color the color of the curve/*w w w . ja va 2s. c o m*/ * @param borderColor the curve border color * @param curve the points along the curve */ private void draw_curve(Color color, Color borderColor, Vec2f[] curve) { staticState.initGradient(); RenderState state = startRender(); int vtx_buf; // the size is: floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone) FloatBuffer buff = BufferUtils .createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2)) .asFloatBuffer(); staticState.initShaderProgram(); vtx_buf = GL15.glGenBuffers(); for (int i = 0; i < curve.length; ++i) { float x = curve[i].x; float y = curve[i].y; //if (i == 0 || i == curve.length - 1){ fillCone(buff, x, y, NewCurveStyleState.DIVIDES); if (i != 0) { float last_x = curve[i - 1].x; float last_y = curve[i - 1].y; double diff_x = x - last_x; double diff_y = y - last_y; x = (float) (x - diff_x / 2); y = (float) (y - diff_y / 2); fillCone(buff, x, y, NewCurveStyleState.DIVIDES); } } buff.flip(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW); GL20.glUseProgram(staticState.program); GL20.glEnableVertexAttribArray(staticState.attribLoc); GL20.glEnableVertexAttribArray(staticState.texCoordLoc); GL20.glUniform1i(staticState.texLoc, 0); GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b); GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a); //stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w) //2*4 is for skipping the first 2 floats (u,v) GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4); GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0); for (int i = 0; i < curve.length * 2 - 1; ++i) GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2); GL20.glDisableVertexAttribArray(staticState.texCoordLoc); GL20.glDisableVertexAttribArray(staticState.attribLoc); GL15.glDeleteBuffers(vtx_buf); endRender(state); }
From source file:ivorius.ivtoolkit.models.data.IndexBufferObject.java
License:Apache License
/** * Binds this IndexBufferObject for rendering with glDrawElements. *///w w w .ja v a2 s. com public void bind() { if (bufferHandle == 0) throw new RuntimeException("No buffer allocated!"); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, bufferHandle); if (isDirty) { byteBuffer.limit(buffer.limit() * 2); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, byteBuffer, usage); isDirty = false; } isBound = true; }
From source file:ivorius.ivtoolkit.models.data.IndexBufferObject.java
License:Apache License
/** * Unbinds this IndexBufferObject. */ public void unbind() { GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); isBound = false; }