List of usage examples for org.lwjgl.opengl GL20 glVertexAttribPointer
public static void glVertexAttribPointer(@NativeType("GLuint") int index, @NativeType("GLint") int size, @NativeType("GLenum") int type, @NativeType("GLboolean") boolean normalized, @NativeType("GLsizei") int stride, @NativeType("void const *") FloatBuffer pointer)
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, int ptr) { GL20.glVertexAttribPointer(indx, size, type, normalized, stride, ptr); }
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// www . j a v a 2s . com * @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:jpcsp.graphics.RE.RenderingEngineLwjgl.java
License:Open Source License
@Override public void setVertexAttribPointer(int id, int size, int type, boolean normalized, int stride, long offset) { GL20.glVertexAttribPointer(id, size, pointerTypeToGL[type], normalized, stride, offset); }
From source file:main.java.com.YeAJG.game.entity.Entity.java
License:Open Source License
private void SetupEntity(Vector3f[] vertex, Vector3f[] color, Vector2f[] uv) { // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class vertices = new VertexData[vertex.length]; for (int i = 0; i < vertex.length; i++) { vertices[i] = new VertexData(); vertices[i].setXYZ(vertex[i].x, vertex[i].y, vertex[i].z); vertices[i].setRGBA(color[i].x, color[i].y, color[i].z, 1.0f); vertices[i].setST(uv[i].x, uv[i].y); }/*from w ww . ja v a 2 s .c o m*/ // Put each 'Vertex' in one FloatBuffer verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride); FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer(); for (int i = 0; i < vertices.length; i++) { // Add position, color and texture floats to the buffer verticesFloatBuffer.put(vertices[i].getElements()); } verticesFloatBuffer.flip(); // OpenGL expects to draw vertices in counter clockwise order by default // TODO: Move this to Setup. byte[] indices = { 0, 1, 2, 2, 3, 0 }; indicesCount = indices.length; ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); // Create a new Vertex Array Object in memory and select it (bind) vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); // Create a new Vertex Buffer Object in memory and select it (bind) vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW); // Put the position coordinates in attribute list 0 GL20.glVertexAttribPointer(0, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.positionByteOffset); // Put the color components in attribute list 1 GL20.glVertexAttribPointer(1, VertexData.colorElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.colorByteOffset); // Put the texture coordinates in attribute list 2 GL20.glVertexAttribPointer(2, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.textureByteOffset); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); // Create a new VBO for the indices and select it (bind) - INDICES vboiId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); Game.cameraPos = new Vector3f(0, 0, -1); Game.exitOnGLError("setupQuad"); }
From source file:main.Loader.java
private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) { int vboID = GL15.glGenBuffers(); vbos.add(vboID);//from w w w . j av a 2 s . c o m GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); FloatBuffer buffer = storeDataInFloatBuffer(data); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
public void resizeBuffer() { vertByteBuff = BufferUtils.createByteBuffer(vertexCount * Vertex.stride); ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer(); for (Drawable object : objects) { object.store(vertFloatBuff);/*from w w w . ja va2 s .c o m*/ indicesBuffer.put(object.getIndices()); } for (Drawable object : orthoObjects) { object.store(vertFloatBuff); indicesBuffer.put(object.getIndices()); } indicesBuffer.flip(); vertFloatBuff.flip(); GL30.glBindVertexArray(vaoId); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertFloatBuff, GL15.GL_STREAM_DRAW); GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.stride, 0); GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, Vertex.stride, 16); GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, Vertex.stride, 32); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }
From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java
License:Open Source License
@Override public void addAttribute(int index, int size, TFloatList data) { ensureCreated("VertexArray must be created to add an attribute."); if (index > GL11.glGetInteger(GL_MAX_VERTEX_ATTRIBS)) { throw new IllegalArgumentException("Vertex attribute index exceeds maximum vertex attribute index."); }/*from ww w .ja v a 2s . c om*/ // Put the indices into an FloatBuffer final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size()); data.forEach((float f) -> { buffer.put(f); return true; }); buffer.flip(); // Bind the VAO GL30.glBindVertexArray(vao); // Generate and bind the attribute buffer final int id = GL15.glGenBuffers(); GL15.glBindBuffer(GL_ARRAY_BUFFER, id); // Set the attribute data GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW); // Enable the vertex attribute GL20.glEnableVertexAttribArray(index); // Set the vertex attribute settings GL20.glVertexAttribPointer(index, size, DataType.FLOAT.getGLConstant(), false, 0, 0L); // Disable the vertex attribute GL20.glDisableVertexAttribArray(index); // Unbind the attribute buffer GL15.glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the VAO GL30.glBindVertexArray(vao); // Add the buffer id to the attributes list this.attributes.insert(index, id); // Check for errors RenderUtil.checkGLError(); }
From source file:model.ModelMD2.java
@Override public void draw(float frame, float[] vpMatrix, float[] matrix, RenderEngine engine) { if (frame < 0 || frame > header.num_frames - 1) return;//from w w w . j a va 2 s.c o m //Select current frame and next int frame_0 = frame_ids[(int) Math.floor(frame)]; int frame_1 = frame_ids[(int) Math.min(Math.ceil(frame), header.num_frames - 1)]; //Upload frame interpolation GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_id); ShaderUtils.useProgram(shader_id); { //Upload uniform values ShaderUtils.setUniformMatrix4(shader_id, "viewprojMatrix", vpMatrix); ShaderUtils.setUniformMatrix4(shader_id, "modelMatrix", matrix); ShaderUtils.setUniformVar(shader_id, "frame_interpolated", (float) (frame - Math.floor(frame))); //ShaderUtils.setUniformVar(shader_id, "cameraDir", engine.camera.yaw, engine.camera.pitch, engine.camera.roll); //Bind frames to VAO GL30.glBindVertexArray(vao_id); { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_0);//Bind frame 0 { GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12); GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_1);//Bind frame 1 { GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 32, 0); GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, 32, 12); GL20.glVertexAttribPointer(5, 3, GL11.GL_FLOAT, false, 32, 20); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); //Enable attribs and render for (int i = 0; i < 6; i++) { GL20.glEnableVertexAttribArray(i); } { GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, header.num_tris * 3); } for (int i = 0; i < 6; i++) { GL20.glDisableVertexAttribArray(i); } } GL30.glBindVertexArray(0); } ShaderUtils.useProgram(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java
License:Apache License
/** Sets the vertex attribute with the given name. Throws an IllegalArgumentException in case it is not called in between a * {@link #begin()}/{@link #end()} block. * // w ww . ja v a 2s. c om * @param name the attribute name * @param size the number of components, must be >= 1 and <= 4 * @param type the type, must be one of GL20.GL_BYTE, GL20.GL_UNSIGNED_BYTE, GL20.GL_SHORT, * GL20.GL_UNSIGNED_SHORT,GL20.GL_FIXED, or GL20.GL_FLOAT. GL_FIXED will not work on the desktop * @param normalize whether fixed point data should be normalized. Will not work on the desktop * @param stride the stride in bytes between successive attributes * @param offset byte offset into the vertex buffer object bound to GL20.GL_ARRAY_BUFFER. */ public void setVertexAttribute(String name, int size, int type, boolean normalize, int stride, int offset) { checkContext(); int location = fetchAttributeLocation(name); if (location == -1) return; GL20.glVertexAttribPointer(location, size, type, normalize, stride, offset); }
From source file:net.smert.frameworkgl.opengl.helpers.VertexArrayHelper.java
License:Apache License
public void bindVertexAttrib(int index, int size, int type, ByteBuffer byteBuffer) { GL20.glVertexAttribPointer(index, size, type, false, 0, byteBuffer); }