org.lwjgl.BufferUtils Java Examples
The following examples show how to use
org.lwjgl.BufferUtils.
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: DesktopComputeJobManager.java From graphicsfuzz with Apache License 2.0 | 6 votes |
@Override public void prepareEnvironment(JsonObject environmentJson) { final JsonObject bufferJson = environmentJson.get("buffer").getAsJsonObject(); final int bufferBinding = bufferJson.get("binding").getAsInt(); final int[] bufferInput = UniformSetter.getIntArray(bufferJson.get("input").getAsJsonArray()); final IntBuffer intBufferData = BufferUtils.createIntBuffer(bufferInput.length); intBufferData.put(bufferInput); intBufferData.flip(); shaderStorageBufferObject = GL15.glGenBuffers(); checkError(); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject); checkError(); GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER, intBufferData, GL15.GL_STATIC_DRAW); checkError(); GL30.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, bufferBinding, shaderStorageBufferObject); checkError(); numGroups = UniformSetter.getIntArray(environmentJson.get("num_groups").getAsJsonArray()); }
Example #2
Source File: Circle.java From ldparteditor with MIT License | 6 votes |
public Circle(float r, float g, float b, float dir_x, float dir_y, float dir_z, float radius, float line_width) { dir_x = dir_x / 1000f; dir_y = dir_y / 1000f; dir_z = dir_z / 1000f; radius = radius / 1000f; this.r = r; this.g = g; this.b = b; rotation = makeRotationDir(new Vector3f(dir_x, dir_y, dir_z)); matrix = BufferUtils.createFloatBuffer(16); rotation.store(matrix); matrix.position(0); final float step = (float) (Math.PI / 16d); float angle = 0f; final float radius2 = radius - line_width / 6f; for (int i = 0; i < 66; i += 2) { circle[i] = (float) (radius * Math.cos(angle)); circle[i + 1] = (float) (radius * Math.sin(angle)); circle2[i] = (float) (radius2 * Math.cos(angle)); circle2[i + 1] = (float) (radius2 * Math.sin(angle)); angle = angle + step; } }
Example #3
Source File: CurveRenderState.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Reads the first row of the slider gradient texture and upload it as * a 1D texture to OpenGL if it hasn't already been done. */ public void initGradient() { if (gradientTexture == 0) { Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale()); staticState.gradientTexture = GL11.glGenTextures(); ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4); for (int i = 0; i < slider.getWidth(); ++i) { Color col = slider.getColor(i, 0); buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.b)); // I know this looks strange... buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.a)); } buff.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture); GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff); EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D); } }
Example #4
Source File: Example3_2.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void init() { glClearColor(0, 0, 0, 0); program = new ShaderProgram(readFromFile("example3.2.vert"), readFromFile("example3.2.frag")); offsetLocation = program.getUniformLocation("offset"); vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f, 0.25f, -0.25f, 0.0f, 1.0f, -0.25f, -0.25f, 0.0f, 1.0f }).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()); }
Example #5
Source File: ClientDynamicTexture.java From AdvancedRocketry with MIT License | 6 votes |
private void init() { //create array, every single pixel ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL); for(int i = 0; i < image.getHeight() * image.getWidth(); i++) { buffer.putInt(0x00000000); } buffer.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId()); //Just clamp to edge GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); //Scale linearly GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); }
Example #6
Source File: Example2_1.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void init() { glClearColor(0, 0, 0, 0); program = new ShaderProgram(readFromFile("example2.1.vert"), readFromFile("example2.1.frag")); vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.75f, 0.75f, 0.0f, 1.0f, 0.75f, -0.75f, 0.0f, 1.0f, -0.75f, -0.75f, 0.0f, 1.0f }).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()); }
Example #7
Source File: BWItem.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) { this.item = item; this.meta = meta; this.tag = tag; components.add(new StaticRenderer()) .onRender(model -> { model.addChild(new CustomModel(self -> { Tessellator.instance.draw(); GL11.glPushMatrix(); DoubleBuffer buffer = BufferUtils.createDoubleBuffer(4 * 4); double[] flatArray = Arrays.stream(self.matrix.getMatrix().getData()) .flatMapToDouble(Arrays::stream) .toArray(); buffer.put(flatArray); buffer.position(0); GL11.glMultMatrix(buffer); RenderItem.getInstance().doRender(fakeEntity, 0, 0, 0, 0, 0); GL11.glPopMatrix(); Tessellator.instance.startDrawingQuads(); })); } ); }
Example #8
Source File: Example2_2.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void init() { glClearColor(0, 0, 0, 0); program = new ShaderProgram(readFromFile("example2.2.vert"), readFromFile("example2.2.frag")); vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(24).put(new float[] { 0.0f, 0.5f, 0.0f, 1.0f, 0.5f, -0.366f, 0.0f, 1.0f, -0.5f, -0.366f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }).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()); }
Example #9
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 #10
Source File: GLTexture.java From WraithEngine with Apache License 2.0 | 6 votes |
/** * Extracts pixel colors from the texture data object and formats them into an * RGBA8 byte buffer. * * @param textureData * - The texture data containing the color data. * @return A formatted byte buffer containing the pixel colors. */ private ByteBuffer getPixelData(TextureData textureData) { int pixelCount = textureData.getWidth() * textureData.getHeight(); ByteBuffer pixels = BufferUtils.createByteBuffer(pixelCount * 4); for (int y = 0; y < textureData.getHeight(); y++) { for (int x = 0; x < textureData.getWidth(); x++) { int color = textureData.getPixel(x, y); pixels.put((byte) ((color >> 16) & 0xFF)); pixels.put((byte) ((color >> 8) & 0xFF)); pixels.put((byte) (color & 0xFF)); pixels.put((byte) ((color >> 24) & 0xFF)); } } pixels.flip(); return pixels; }
Example #11
Source File: AppGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.Image, int, int) */ public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException { try { Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight())); Graphics g = temp.getGraphics(); ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4); g.drawImage(image.getFlippedCopy(false, true), 0, 0); g.flush(); g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer); Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight()); Mouse.setNativeCursor(cursor); } catch (Throwable e) { Log.error("Failed to load and apply cursor.", e); throw new SlickException("Failed to set mouse cursor", e); } }
Example #12
Source File: Utils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TempBuffer() { b16 = BufferUtils.createByteBuffer(16); b16s = b16.asShortBuffer(); b16i = b16.asIntBuffer(); b16l = b16.asLongBuffer(); b16f = b16.asFloatBuffer(); b16d = b16.asDoubleBuffer(); }
Example #13
Source File: OpenALStreamPlayer.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Create a new player to work on an audio stream * * @param source The source on which we'll play the audio * @param url A reference to the audio file to stream */ public OpenALStreamPlayer(int source, URL url) { this.source = source; this.url = url; bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT); AL10.alGenBuffers(bufferNames); }
Example #14
Source File: GLMatrixStack.java From ldparteditor with MIT License | 5 votes |
public void glLoadIdentity() { 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); int view = shader.getUniformLocation("view" ); //$NON-NLS-1$ GL20.glUniformMatrix4fv(view, false, ID_buf); }
Example #15
Source File: GLMatrixStack.java From ldparteditor with MIT License | 5 votes |
public void glLoadMatrix(Matrix4f m) { final FloatBuffer m_buf = BufferUtils.createFloatBuffer(16); m.store(m_buf); m_buf.position(0); currentMatrix = m; int model = shader.getUniformLocation("model" ); //$NON-NLS-1$ GL20.glUniformMatrix4fv(model, false, m_buf); }
Example #16
Source File: TextureHelper.java From malmo with MIT License | 5 votes |
public static int loadShader(String filename, int shaderType) throws IOException { int shaderID = -1; InputStream stream = MalmoMod.class.getClassLoader().getResourceAsStream(filename); if (stream == null) { System.out.println("Cannot find shader."); return -1; } try { byte[] abyte = IOUtils.toByteArray((InputStream) (new BufferedInputStream(stream))); ByteBuffer bytebuffer = BufferUtils.createByteBuffer(abyte.length); bytebuffer.put(abyte); bytebuffer.position(0); shaderID = OpenGlHelper.glCreateShader(shaderType); OpenGlHelper.glShaderSource(shaderID, bytebuffer); OpenGlHelper.glCompileShader(shaderID); if (OpenGlHelper.glGetShaderi(shaderID, OpenGlHelper.GL_COMPILE_STATUS) == 0) { String s = StringUtils.trim(OpenGlHelper.glGetShaderInfoLog(shaderID, 32768)); JsonException jsonexception = new JsonException("Couldn\'t compile shader program: " + s); throw jsonexception; } } finally { IOUtils.closeQuietly(stream); } return shaderID; }
Example #17
Source File: VideoProducerImplementation.java From malmo with MIT License | 5 votes |
@Override public void prepare(MissionInit missionInit) { this.fbo = new Framebuffer(this.videoParams.getWidth(), this.videoParams.getHeight(), true); // Create a buffer for retrieving the depth map, if requested: if (this.videoParams.isWantDepth()) this.depthBuffer = BufferUtils.createFloatBuffer(this.videoParams.getWidth() * this.videoParams.getHeight()); // Set the requested camera position Minecraft.getMinecraft().gameSettings.thirdPersonView = this.videoParams.getViewpoint(); }
Example #18
Source File: Utils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TempBuffer() { b16 = BufferUtils.createByteBuffer(16); b16s = b16.asShortBuffer(); b16i = b16.asIntBuffer(); b16l = b16.asLongBuffer(); b16f = b16.asFloatBuffer(); b16d = b16.asDoubleBuffer(); }
Example #19
Source File: GLMatrixStack.java From ldparteditor with MIT License | 5 votes |
public void glMultMatrixf(Matrix4f matrix) { Matrix4f.mul(currentMatrix, matrix, 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 #20
Source File: OpenALStreamPlayer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new player to work on an audio stream * * @param source The source on which we'll play the audio * @param ref A reference to the audio file to stream */ public OpenALStreamPlayer(int source, String ref) { this.source = source; this.ref = ref; bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT); AL10.alGenBuffers(bufferNames); }
Example #21
Source File: LWJGLOpenVR.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void getRenderSize(Vector2f store) { IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); VRSystem.VRSystem_GetRecommendedRenderTargetSize(w, h); logger.config("Recommended render width : " + w.get(0)); logger.config("Recommended render height: " + h.get(0)); store.x = w.get(0); store.y = h.get(0); }
Example #22
Source File: Material.java From WraithEngine with Apache License 2.0 | 5 votes |
/** * Creates a new material object. * * @param shader * - The shader this material uses to render with. * @throws IllegalArgumentException * If the shader is null, or is already disposed. */ public Material(IShader shader) { if (shader == null) throw new IllegalArgumentException("Shader cannot be null!"); if (shader.isDisposed()) throw new IllegalArgumentException("Shader already disposed!"); this.shader = shader; matrixFloatBuffer = BufferUtils.createFloatBuffer(16); }
Example #23
Source File: Utils.java From lwjglbook with Apache License 2.0 | 5 votes |
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException { ByteBuffer buffer; Path path = Paths.get(resource); if (Files.isReadable(path)) { try (SeekableByteChannel fc = Files.newByteChannel(path)) { buffer = BufferUtils.createByteBuffer((int) fc.size() + 1); while (fc.read(buffer) != -1) ; } } else { try ( InputStream source = Utils.class.getResourceAsStream(resource); ReadableByteChannel rbc = Channels.newChannel(source)) { buffer = createByteBuffer(bufferSize); while (true) { int bytes = rbc.read(buffer); if (bytes == -1) { break; } if (buffer.remaining() == 0) { buffer = resizeBuffer(buffer, buffer.capacity() * 2); } } } } buffer.flip(); return buffer; }
Example #24
Source File: TerrainPicking.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
public void getTerrainPosition(){ if (isActive() && glfwGetMouseButton(BaseContext.getWindow().getId(),1) == GLFW_PRESS){ Vec3f pos = new Vec3f(0,0,0); DoubleBuffer xPos = BufferUtils.createDoubleBuffer(1); DoubleBuffer yPos = BufferUtils.createDoubleBuffer(1); glfwGetCursorPos(BaseContext.getWindow().getId(), xPos, yPos); Vec2f screenPos = new Vec2f((float) xPos.get(),(float) yPos.get()); GLContext.getResources().getSceneDepthMap().bind(); glGetTexImage(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,GL_FLOAT,depthmapBuffer); float depth = depthmapBuffer.get((int) (BaseContext.getWindow().getWidth() * screenPos.getY() + screenPos.getX())); // window coords Vec2f w = new Vec2f(screenPos.getX()/BaseContext.getWindow().getWidth(), screenPos.getY()/BaseContext.getWindow().getHeight()); //ndc coords Vec3f ndc = new Vec3f(w.getX() * 2 - 1, w.getY() * 2 - 1, depth); float cw = BaseContext.getCamera().getProjectionMatrix().get(3,2) / (ndc.getZ() - BaseContext.getCamera().getProjectionMatrix().get(2,2)); Vec3f clip = ndc.mul(cw); Vec4f clipPos = new Vec4f(clip.getX(),clip.getY(),clip.getZ(),cw); Vec4f worldPos = BaseContext.getCamera().getViewProjectionMatrix().invert().mul(clipPos); worldPos = worldPos.div(worldPos.getW()); pos.setX(worldPos.getX()); pos.setY(worldPos.getY()); pos.setZ(worldPos.getZ()); System.out.println("TerrainPicking: " + pos); } }
Example #25
Source File: Utils.java From lwjglbook with Apache License 2.0 | 5 votes |
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException { ByteBuffer buffer; Path path = Paths.get(resource); if (Files.isReadable(path)) { try (SeekableByteChannel fc = Files.newByteChannel(path)) { buffer = BufferUtils.createByteBuffer((int) fc.size() + 1); while (fc.read(buffer) != -1) ; } } else { try ( InputStream source = Utils.class.getResourceAsStream(resource); ReadableByteChannel rbc = Channels.newChannel(source)) { buffer = createByteBuffer(bufferSize); while (true) { int bytes = rbc.read(buffer); if (bytes == -1) { break; } if (buffer.remaining() == 0) { buffer = resizeBuffer(buffer, buffer.capacity() * 2); } } } } buffer.flip(); return buffer; }
Example #26
Source File: Mesh.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ByteBuffer storeData(ByteBuffer b, String[] data) { start = b.position(); count = data.length; ByteBuffer b2 = BufferUtils.createByteBuffer(start + count * type.size); b2.put((ByteBuffer)b.flip()); type.store(b2, data); return b2; }
Example #27
Source File: OpenALStreamPlayer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new player to work on an audio stream * * @param source The source on which we'll play the audio * @param url A reference to the audio file to stream */ public OpenALStreamPlayer(int source, URL url) { this.source = source; this.url = url; bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT); AL10.alGenBuffers(bufferNames); }
Example #28
Source File: ClientDynamicTexture.java From AdvancedRocketry with MIT License | 5 votes |
/** * @return IntBuffer containing the pixels for the image */ public IntBuffer getByteBuffer() { ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL);; //GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId()); //GL11.glGetTexImage(GL11.GL_TEXTURE_2D,0 , GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); int[] pixels = new int[image.getWidth() * image.getHeight()]; image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()); IntBuffer ret = buffer.asIntBuffer(); ret.put(pixels); return ret; }
Example #29
Source File: Material.java From WraithEngine with Apache License 2.0 | 5 votes |
/** * Creates a new material object. * * @param shader * - The shader this material uses to render with. * @throws IllegalArgumentException * If the shader is null, or is already disposed. */ public Material(IShader shader) { if (shader == null) throw new IllegalArgumentException("Shader cannot be null!"); if (shader.isDisposed()) throw new IllegalArgumentException("Shader already disposed!"); this.shader = shader; matrixFloatBuffer = BufferUtils.createFloatBuffer(16); }
Example #30
Source File: LwjglProgram.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private String Log(long device) { Utils.pointerBuffers[0].rewind(); int ret = CL10.clGetProgramBuildInfo(program, device, CL10.CL_PROGRAM_BUILD_LOG, (ByteBuffer) null, Utils.pointerBuffers[0]); Utils.checkError(ret, "clGetProgramBuildInfo"); int count = (int) Utils.pointerBuffers[0].get(0); final ByteBuffer buffer = BufferUtils.createByteBuffer(count); ret = CL10.clGetProgramBuildInfo(program, device, CL10.CL_PROGRAM_BUILD_LOG, buffer, null); Utils.checkError(ret, "clGetProgramBuildInfo"); return MemoryUtil.memASCII(buffer); }