Java Code Examples for org.lwjgl.BufferUtils#createFloatBuffer()
The following examples show how to use
org.lwjgl.BufferUtils#createFloatBuffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformProvider.java From OpenModsLib with MIT License | 6 votes |
public Transformation(Orientation orientation) { final javax.vecmath.Matrix4f originalMatrix = new javax.vecmath.Matrix4f(); originalMatrix.set(orientation.getLocalToWorldMatrix()); asMatrix = TRSRTransformation.toLwjgl(originalMatrix); asBuffer = BufferUtils.createFloatBuffer(16); asMatrix.store(asBuffer); asBuffer.rewind(); asInverseMatrix = new Matrix4f(); Matrix4f.invert(asMatrix, asInverseMatrix); asInverseBuffer = BufferUtils.createFloatBuffer(16); asInverseMatrix.store(asInverseBuffer); asInverseBuffer.rewind(); }
Example 2
Source File: Arrow.java From ldparteditor with MIT License | 6 votes |
public Arrow(float r, float g, float b, float dir_x, float dir_y, float dir_z, float cone_height, float cone_width, float line_width) { dir_x = dir_x / 1000f; dir_y = dir_y / 1000f; dir_z = dir_z / 1000f; this.r = r; this.g = g; this.b = b; this.line_width = line_width; length = (float) Math.sqrt(dir_x * dir_x + dir_y * dir_y + dir_z * dir_z); cone_start = length - cone_height; line_end = length - cone_height / 3f; rotation = makeRotationDir(new Vector3f(dir_x, dir_y, dir_z)); matrix_buf = BufferUtils.createFloatBuffer(16); rotation.store(matrix_buf); matrix_buf.position(0); float cone_radius = cone_width; float step = (float) (Math.PI / 8d); float angle = 0f; for (int i = 0; i < 34; i += 2) { cone[i] = (float) (cone_radius * Math.cos(angle)); cone[i + 1] = (float) (cone_radius * Math.sin(angle)); angle = angle + step; } }
Example 3
Source File: SlickCallableTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Render the GL scene, this isn't efficient and if you know * OpenGL I'm assuming you can see why. If not, you probably * don't want to use this feature anyway */ public void renderGL() { FloatBuffer pos = BufferUtils.createFloatBuffer(4); pos.put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}).flip(); FloatBuffer red = BufferUtils.createFloatBuffer(4); red.put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}).flip(); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos); GL11.glEnable(GL11.GL_LIGHT0); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_LIGHTING); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float h = (float) 600 / (float) 800; GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -40.0f); GL11.glRotatef(rot,0,1,1); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red); gear(0.5f, 2.0f, 2.0f, 10, 0.7f); }
Example 4
Source File: Cube.java From Visage with MIT License | 6 votes |
@Override public void render(Renderer renderer) { if (tcbo == Integer.MAX_VALUE) { if (Visage.trace) Visage.log.finest("Creating texture coord buffer"); tcbo = glGenBuffers(); FloatBuffer uv = BufferUtils.createFloatBuffer(texture.u.length+texture.v.length); for (int i = 0; i < texture.u.length; i++) { uv.put(texture.u[i]); uv.put(texture.v[i]); } uv.flip(); glBindBuffer(GL_ARRAY_BUFFER, tcbo); glBufferData(GL_ARRAY_BUFFER, uv, GL_STATIC_DRAW); } doRender(renderer, renderer.owner.cubeVbo, tcbo, RenderContext.vertices); }
Example 5
Source File: GLMatrixStack.java From ldparteditor with MIT License | 5 votes |
public void clear() { stack.clear(); final Matrix4f ID = new Matrix4f(); Matrix4f.setIdentity(ID); final FloatBuffer ID_buf = BufferUtils.createFloatBuffer(16); ID.store(ID_buf); ID_buf.position(0); currentMatrix = ID; int model = shader.getUniformLocation("model" ); //$NON-NLS-1$ GL20.glUniformMatrix4fv(model, false, ID_buf); }
Example 6
Source File: AudioManager.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
private AudioSource getSource(CameraState camera_state, AudioParameters params) { if (!AL.isCreated()) return null; float this_dist_squared; if (params.relative) this_dist_squared = params.x*params.x + params.y*params.y + params.z*params.z; else this_dist_squared = getCamDistSquared(camera_state, params.x, params.y, params.z); if (this_dist_squared > params.distance*params.distance) { return null; } AudioSource best_source = findSource(params); if (best_source == null) { float max_dist_squared = this_dist_squared; FloatBuffer position = BufferUtils.createFloatBuffer(3); for (int i = 0; i < sources.length; i++) { AudioSource source = (AudioSource)sources[i]; if (source.getRank() == params.rank) { int source_index = source.getSource(); AL10.alGetSource(source_index, AL10.AL_POSITION, position); float dist_squared = getCamDistSquared(camera_state, position.get(0), position.get(1), position.get(2)); if (dist_squared > max_dist_squared) { max_dist_squared = dist_squared; best_source = source; } } } } stopSource(best_source); return best_source; }
Example 7
Source File: Example4_4.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void init() { glClearColor(0, 0, 0, 0); program = new ShaderProgram(readFromFile("example4.4.vert"), readFromFile("example4.4.frag")); offsetUniform = program.getUniformLocation("offset"); perspectiveMatrixUniform = program.getUniformLocation("perspectiveMatrix"); float zNear = 0.5f, zFar = 3; perspectiveMatrix = BufferUtils.createFloatBuffer(16); perspectiveMatrix.put(0, frustumScale); perspectiveMatrix.put(5, frustumScale); perspectiveMatrix.put(10, (zFar + zNear) / (zNear - zFar)); perspectiveMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar)); perspectiveMatrix.put(11, -1); program.begin(); glUniformMatrix4(perspectiveMatrixUniform, false, perspectiveMatrix); program.end(); vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); // In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5. glBindVertexArray(glGenVertexArrays()); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); }
Example 8
Source File: GLMatrixStack.java From ldparteditor with MIT License | 5 votes |
public void glTranslatef(float x, float y, float z) { Matrix4f.translate(new Vector3f(x, y, z), currentMatrix, currentMatrix); final FloatBuffer buf = BufferUtils.createFloatBuffer(16); currentMatrix.store(buf); buf.position(0); int model = shader.getUniformLocation("model" ); //$NON-NLS-1$ GL20.glUniformMatrix4fv(model, false, buf); }
Example 9
Source File: GLMatrixStack.java From ldparteditor with MIT License | 5 votes |
public void glPopMatrix() { if (!stack.isEmpty()) { currentMatrix = stack.pop(); final FloatBuffer buf = BufferUtils.createFloatBuffer(16); currentMatrix.store(buf); buf.position(0); int model = shader.getUniformLocation("model" ); //$NON-NLS-1$ GL20.glUniformMatrix4fv(model, false, buf); } }
Example 10
Source File: LwjglRasteriser.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setCameraMatrix(Matrix4f matrix, Vector3f lookAt, Vector3f eye, Vector3f up) { GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); FloatBuffer buffer = BufferUtils.createFloatBuffer(16); matrix.store(buffer); buffer.flip(); GL11.glLoadMatrix(buffer); }
Example 11
Source File: LwjglMesh.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static FloatBuffer realloc(FloatBuffer existing, final int existingSize, final int newSize) { FloatBuffer newBuffer = BufferUtils.createFloatBuffer(newSize); if (existing != null) { existing.flip(); newBuffer.put(existing); } return newBuffer; }
Example 12
Source File: Example5_2.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void init() { glClearColor(0, 0, 0, 0); program = new ShaderProgram(readFromFile("example5.2.vert"), readFromFile("example5.2.frag")); offsetUniform = program.getUniformLocation("offset"); perspectiveMatrixUniform = program.getUniformLocation("perspectiveMatrix"); float zNear = 1, zFar = 3; perspectiveMatrix = BufferUtils.createFloatBuffer(16); perspectiveMatrix.put(0, frustumScale); perspectiveMatrix.put(5, frustumScale); perspectiveMatrix.put(10, (zFar + zNear) / (zNear - zFar)); perspectiveMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar)); perspectiveMatrix.put(11, -1); program.begin(); glUniformMatrix4(perspectiveMatrixUniform, false, perspectiveMatrix); program.end(); int vbo1 = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo1); glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); int vbo2 = glGenBuffers(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2); glBufferData(GL_ELEMENT_ARRAY_BUFFER, (ShortBuffer)BufferUtils.createShortBuffer(indices.length).put(indices).flip(), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); vao = glGenVertexArrays(); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo1); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 36 * 3 * 4); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2); glBindVertexArray(0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); }
Example 13
Source File: Util.java From 3DGameEngine with Apache License 2.0 | 4 votes |
public static FloatBuffer CreateFloatBuffer(int size) { return BufferUtils.createFloatBuffer(size); }
Example 14
Source File: Shader.java From LWJGL-3-Tutorial with MIT License | 4 votes |
public void setUniform(String uniformName, Matrix4f value) { int location = glGetUniformLocation(programObject, uniformName); FloatBuffer matrixData = BufferUtils.createFloatBuffer(16); value.get(matrixData); if (location != -1) glUniformMatrix4fv(location, false, matrixData); }
Example 15
Source File: GLMesh.java From WraithEngine with Apache License 2.0 | 4 votes |
@Override public void update(VertexData vertexData) { if (isDisposed()) throw new IllegalStateException("Mesh already disposed!"); FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexData.getDataArray().length); vertexBuffer.put(vertexData.getDataArray()); vertexBuffer.flip(); ShortBuffer indexBuffer = BufferUtils.createShortBuffer(vertexData.getTriangles().length); indexBuffer.put(vertexData.getTriangles()); indexBuffer.flip(); if (!created) { vaoId = opengl.generateVertexArray(); vboId = opengl.generateBuffer(); indexId = opengl.generateBuffer(); } bindStates.bindVao(vaoId); bindStates.bindBuffer(false, vboId); opengl.uploadBufferData(vertexBuffer); int stride = vertexData.getVertexByteSize(); int offset = 0; ShaderAttributes attributes = vertexData.getAttributeSizes(); for (int i = 0; i < attributes.getCount(); i++) { opengl.setVertexAttributePointer(i, attributes.getAttributeSize(i), stride, offset); offset += attributes.getAttributeSize(i) * 4; } bindStates.bindBuffer(true, indexId); opengl.uploadBufferData(indexBuffer); created = true; indexCount = vertexData.getTriangles().length; }
Example 16
Source File: BufferUtil.java From oreon-engine with GNU General Public License v3.0 | 4 votes |
public static FloatBuffer createFloatBuffer(int size) { return BufferUtils.createFloatBuffer(size); }
Example 17
Source File: FontHelper.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
public static void drawString(String s, float x, float y, TrueTypeFont font, float scaleX, float scaleY, float rotationZ, float... rgba){ Minecraft mc = Minecraft.getMinecraft(); ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); if(mc.gameSettings.hideGUI){ return; } float amt = 2F / sr.getScaleFactor(); if(sr.getScaleFactor() == 1){ amt = 2; } FloatBuffer matrixData = BufferUtils.createFloatBuffer(16); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, matrixData); FontHelper.set2DMode(matrixData); GL11.glPushMatrix(); y = mc.displayHeight-(y*sr.getScaleFactor())-(((font.getLineHeight()/amt))); float tx = (x*sr.getScaleFactor())+(font.getWidth(s)/2); float tranx = tx+2; float trany = y+(font.getLineHeight()/2); GL11.glTranslatef(tranx,trany,0); GL11.glRotatef(rotationZ, 0f, 0f, 1f); GL11.glTranslatef(-tranx,-trany,0); GL11.glEnable(GL11.GL_BLEND); if(s.contains(formatEscape)){ String[] pars = s.split(formatEscape); float totalOffset = 0; for(int i = 0; i < pars.length; i++){ String par = pars[i]; float[] c = rgba; if(i > 0){ c = Formatter.getFormatted(par.charAt(0)); par = par.substring(1, par.length()); } font.drawString((x*sr.getScaleFactor()+totalOffset), y, par, scaleX/amt, scaleY/amt, c); totalOffset += font.getWidth(par); } }else{ font.drawString((x*sr.getScaleFactor()), y, s, scaleX/amt, scaleY/amt, rgba); } GL11.glPopMatrix(); GL11.glDisable(GL11.GL_BLEND); FontHelper.set3DMode(); }
Example 18
Source File: GLMesh.java From WraithEngine with Apache License 2.0 | 4 votes |
@Override public void update(VertexData vertexData) { if (isDisposed()) throw new IllegalStateException("Mesh already disposed!"); FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexData.getDataArray().length); vertexBuffer.put(vertexData.getDataArray()); vertexBuffer.flip(); ShortBuffer indexBuffer = BufferUtils.createShortBuffer(vertexData.getTriangles().length); indexBuffer.put(vertexData.getTriangles()); indexBuffer.flip(); if (!created) { vaoId = opengl.generateVertexArray(); vboId = opengl.generateBuffer(); indexId = opengl.generateBuffer(); } bindStates.bindVao(vaoId); bindStates.bindBuffer(false, vboId); opengl.uploadBufferData(vertexBuffer); int stride = vertexData.getVertexByteSize(); int offset = 0; ShaderAttributes attributes = vertexData.getAttributeSizes(); for (int i = 0; i < attributes.getCount(); i++) { opengl.setVertexAttributePointer(i, attributes.getAttributeSize(i), stride, offset); offset += attributes.getAttributeSize(i) * 4; } bindStates.bindBuffer(true, indexId); opengl.uploadBufferData(indexBuffer); created = true; indexCount = vertexData.getTriangles().length; }
Example 19
Source File: Colour.java From LowPolyWater with The Unlicense | 4 votes |
public FloatBuffer getAsFloatBuffer() { FloatBuffer buffer = BufferUtils.createFloatBuffer(4); buffer.put(new float[] { col.x, col.y, col.z, a }); buffer.flip(); return buffer; }
Example 20
Source File: WorldToScreen.java From LiquidBounce with GNU General Public License v3.0 | 3 votes |
public static Matrix4f getMatrix(int matrix) { FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(16); GL11.glGetFloat(matrix, floatBuffer); return (Matrix4f) new Matrix4f().load(floatBuffer); }