Java Code Examples for org.lwjgl.BufferUtils#createByteBuffer()
The following examples show how to use
org.lwjgl.BufferUtils#createByteBuffer() .
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: OpenGLRenderDevice.java From DareEngine with BSD 2-Clause "Simplified" License | 6 votes |
private static ByteBuffer makeRGBABuffer(ArrayBitmap image) { if (image == null) { return null; } final ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4); image.visitAll(new ArrayBitmap.IVisitor() { @Override public void visit(int x, int y, int pixel) { buffer.put(Color.getARGBComponent(pixel, 1)); buffer.put(Color.getARGBComponent(pixel, 2)); buffer.put(Color.getARGBComponent(pixel, 3)); buffer.put(Color.getARGBComponent(pixel, 0)); } }); buffer.flip(); return buffer; }
Example 2
Source File: LwjglContext.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type) { long memFlags = Utils.getMemoryAccessFlags(access); int typeFlag = LwjglImage.decodeImageType(type); Utils.tempBuffers[0].b16i.rewind(); //query count int ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, null, Utils.tempBuffers[0].b16i); Utils.checkError(ret, "clGetSupportedImageFormats"); int count = Utils.tempBuffers[0].b16i.get(0); if (count == 0) { return new ImageFormat[0]; } //get formats CLImageFormat.Buffer formatsB = new CLImageFormat.Buffer(BufferUtils.createByteBuffer(count * CLImageFormat.SIZEOF)); ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, formatsB, (IntBuffer) null); Utils.checkError(ret, "clGetSupportedImageFormats"); //convert formats ImageFormat[] formats = new ImageFormat[count]; for (int i=0; i<count; ++i) { CLImageFormat f = formatsB.get(); Image.ImageChannelOrder channelOrder = LwjglImage.encodeImageChannelOrder(f.image_channel_order()); Image.ImageChannelType channelType = LwjglImage.encodeImageChannelType(f.image_channel_data_type()); formats[i] = new ImageFormat(channelOrder, channelType); } return formats; }
Example 3
Source File: LegacyCurveRenderState.java From opsu 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_EXPERIMENTAL.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.r)); buff.put((byte) (255 * col.g)); 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: Example14_1.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 6 votes |
private ByteBuffer buildGaussianData(int cosAngleResolution) { ByteBuffer textureData = BufferUtils.createByteBuffer(cosAngleResolution); for(int a = 0; a < cosAngleResolution; a++) { float cosAng = a / (float)(cosAngleResolution - 1); float angle = (float)Math.acos(cosAng); float exponent = angle / specularShininess; exponent = -(exponent * exponent); float gaussianTerm = (float)Math.exp(exponent); textureData.put((byte)(gaussianTerm * 255)); } textureData.flip(); return textureData; }
Example 5
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 6
Source File: FontTexture.java From ure with MIT License | 5 votes |
private ByteBuffer readFile(String filename) throws IOException { InputStream is = this.getClass().getResourceAsStream(filename); byte[] bytes = IOUtils.toByteArray(is); ByteBuffer buffer = BufferUtils.createByteBuffer(bytes.length + 1); buffer.put(bytes); buffer.flip(); return buffer; }
Example 7
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 8
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 9
Source File: LwjglMesh.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static ByteBuffer realloc(ByteBuffer existing, final int existingSize, final int newSize) { ByteBuffer newBuffer = BufferUtils.createByteBuffer(newSize); if (existing != null) { existing.flip(); newBuffer.put(existing); } return newBuffer; }
Example 10
Source File: ImageBuffer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.opengl.ImageData#getImageBufferData() */ public ByteBuffer getImageBufferData() { ByteBuffer scratch = BufferUtils.createByteBuffer(rawData.length); scratch.put(rawData); scratch.flip(); return scratch; }
Example 11
Source File: IOUtils.java From recast4j with zlib License | 5 votes |
public static ByteBuffer toByteBuffer(InputStream is, boolean direct) throws IOException { byte[] data = toByteArray(is); if (direct) { ByteBuffer b = BufferUtils.createByteBuffer(data.length); b.put(data); b.flip(); return b; } else { return ByteBuffer.wrap(data); } }
Example 12
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) { offset = b.position(); ByteBuffer b2 = BufferUtils.createByteBuffer(offset + data.length * type.size); b2.put((ByteBuffer)b.flip()); type.store(b2, data); return b2; }
Example 13
Source File: OpenGLRenderDevice.java From DareEngine with BSD 2-Clause "Simplified" License | 5 votes |
@Override public ArrayBitmap getTexture(int id, int x, int y, int width, int height) { int[] dest = new int[width * height]; TextureData tex = textures.get(id); ByteBuffer buffer = BufferUtils.createByteBuffer(tex.width * tex.height * 4); bindTexture(id); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); dest = byteBufferToInt(dest, buffer, tex.width, tex.height); return new ArrayBitmap(width, height, dest, x, y, width); }
Example 14
Source File: ImageSet.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 5 votes |
final ByteBuffer getImageData(int mipmapLevel, int arrayIx, int faceIx) { byte[] imageData = m_imageData.get(mipmapLevel); int imageDataOffset = ((arrayIx * m_faceCount) + faceIx) * m_imageSizes[mipmapLevel]; ByteBuffer imageDataBuffer = BufferUtils.createByteBuffer(m_imageSizes[mipmapLevel]); for(int i = imageDataOffset; i < imageDataOffset + m_imageSizes[mipmapLevel]; i++) { imageDataBuffer.put(imageData[i]); } imageDataBuffer.flip(); return imageDataBuffer; }
Example 15
Source File: Utils.java From lwjglbook with Apache License 2.0 | 4 votes |
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); buffer.flip(); newBuffer.put(buffer); return newBuffer; }
Example 16
Source File: Utils.java From lwjglbook with Apache License 2.0 | 4 votes |
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); buffer.flip(); newBuffer.put(buffer); return newBuffer; }
Example 17
Source File: Utils.java From lwjglbook with Apache License 2.0 | 4 votes |
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); buffer.flip(); newBuffer.put(buffer); return newBuffer; }
Example 18
Source File: ImageLoader.java From Lwjgl3-Game-Engine-Programming-Series with MIT License | 4 votes |
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); buffer.flip(); newBuffer.put(buffer); return newBuffer; }
Example 19
Source File: APIBuffer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public APIBuffer() { buffer = BufferUtils.createByteBuffer(DEFAULT_CAPACITY); address = memAddress(buffer); }
Example 20
Source File: BufferUtil.java From oreon-engine with GNU General Public License v3.0 | 4 votes |
public static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); buffer.flip(); newBuffer.put(buffer); return newBuffer; }