Java 类com.badlogic.gdx.utils.BufferUtils 实例源码

项目:ProjektGG    文件:ScreenshotUtils.java   
public static void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0,
            Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), true);

    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);

    SimpleDateFormat dateFormat = new SimpleDateFormat(
            "yyyy-MM-dd HH-mm-ss");

    PixmapIO.writePNG(
            Gdx.files.external(dateFormat.format(new Date()) + ".png"),
            pixmap);
    pixmap.dispose();
}
项目:cocos2d-java    文件:GLView.java   
/**
 * Get the current scissor rectangle
 */
public Rect getScissorRect() {
    if(!Engine.instance().isGLThread()) {
        // 不能在非gl线程中访问
        CCLog.error(TAG, "GLThread error");
        return null;
    }
    FloatBuffer fb = BufferUtils.newFloatBuffer(16); //4 * 4
    Gdx.gl.glGetFloatv(GL20.GL_SCISSOR_BOX, fb);
    float[] params = new float[4];
    fb.get(params);

    float x = (params[0] - _viewPortRect.x) / _scaleX;
    float y = (params[1] - _viewPortRect.y) / _scaleY;
    float w = params[2] / _scaleX;
    float h = params[3] / _scaleY;
    return (Rect) poolRect.set(x, y, w, h);
}
项目:gdx-cclibs    文件:Anisotropy.java   
/**
 * @return Whether the device supports anisotropic filtering.
 */
public static boolean isSupported () {
    GL20 gl = Gdx.gl;
    if (gl != null) {
        if (Gdx.graphics.supportsExtension("GL_EXT_texture_filter_anisotropic")) {
            anisotropySupported = true;
            FloatBuffer buffer = BufferUtils.newFloatBuffer(16);
            buffer.position(0);
            buffer.limit(buffer.capacity());
            Gdx.gl20.glGetFloatv(GL20.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, buffer);
            maxAnisotropySupported = buffer.get(0);
        }
        checkComplete = true;
    }
    return anisotropySupported;
}
项目:zierfisch    文件:TextureBuilder.java   
/**
 * 
 * @param image
 * @return
 * @see http://stackoverflow.com/a/10872080
 */
private ByteBuffer loadTexture(PNGDecoder image) {
    int bytesPerComponent = chooseBitsPerComponent() / 8;
    int bytesPerPixel = chooseComponentCount() * bytesPerComponent;
    int imageBufSize = image.getWidth() * image.getHeight() * bytesPerPixel;
    ByteBuffer buffer = BufferUtils.newByteBuffer(imageBufSize);
    Format format = pngDecodingFormatFromComponentCount();

    try {
        image.decode(buffer, image.getWidth() * bytesPerPixel, format);
    } catch (IOException e) {
        throw new ResourceException(e);
    }

    buffer.flip(); // FOR THE LOVE OF GOD DO NOT FORGET THIS

    return buffer;
}
项目:gdx-freetype-gwt    文件:FreeType.java   
public ByteBuffer getBuffer () {
    if (getRows() == 0)
        // Issue #768 - CheckJNI frowns upon env->NewDirectByteBuffer with NULL buffer or capacity 0
        // "JNI WARNING: invalid values for address (0x0) or capacity (0)"
        // FreeType sets FT_Bitmap::buffer to NULL when the bitmap is empty (e.g. for ' ')
        // JNICheck is on by default on emulators and might have a point anyway...
        // So let's avoid this and just return a dummy non-null non-zero buffer
        return BufferUtils.newByteBuffer(1);
    int offset = getBufferAddress(address);
    int length = getBufferSize(address);
    Int8Array as = getBuffer(address, offset, length);
    ArrayBuffer aBuf = as.buffer();
    ByteBuffer buf = FreeTypeUtil.newDirectReadWriteByteBuffer(aBuf, length, offset);

    return buf;
}
项目:Mundus    文件:BasePicker.java   
public Pixmap getFrameBufferPixmap(Viewport viewport) {
    int w = viewport.getScreenWidth();
    int h = viewport.getScreenHeight();
    int x = viewport.getScreenX();
    int y = viewport.getScreenY();
    final ByteBuffer pixelBuffer = BufferUtils.newByteBuffer(w * h * 4);

    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbo.getFramebufferHandle());
    Gdx.gl.glReadPixels(x, y, w, h, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pixelBuffer);
    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);

    final int numBytes = w * h * 4;
    byte[] imgLines = new byte[numBytes];
    final int numBytesPerLine = w * 4;
    for (int i = 0; i < h; i++) {
        pixelBuffer.position((h - i - 1) * numBytesPerLine);
        pixelBuffer.get(imgLines, i * numBytesPerLine, numBytesPerLine);
    }

    Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    BufferUtils.copy(imgLines, 0, pixmap.getPixels(), imgLines.length);

    return pixmap;
}
项目:nvlist    文件:PixmapUtil.java   
/**
 * Copies the contents of {@code src} to {@code dst}.
 *
 * @throws IllegalArgumentException If the pixmaps are different sizes or different formats.
 */
public static void copy(Pixmap src, Pixmap dst) {
    Format srcFmt = src.getFormat();
    Format dstFmt = dst.getFormat();
    Checks.checkArgument(srcFmt == dstFmt, "Formats not equal: src=" + srcFmt + ", dst=" + dstFmt);

    int srcW = src.getWidth();
    int dstW = dst.getWidth();
    Checks.checkArgument(srcW == dstW, "Widths not equal: src.w=" + srcW + ", dst.w=" + dstW);

    int srcH = src.getHeight();
    int dstH = src.getHeight();
    Checks.checkArgument(srcH == dstH, "Heights not equal: src.h=" + srcH + ", dst.h=" + dstH);

    ByteBuffer srcPixels = src.getPixels();
    ByteBuffer dstPixels = dst.getPixels();
    BufferUtils.copy(srcPixels, dstPixels, srcPixels.limit());
    srcPixels.clear();
    dstPixels.clear();
}
项目:teavm-libgdx    文件:OverlayTransformer.java   
@Override
public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) {
    if (cls.getName().equals(BufferUtils.class.getName())) {
        transformBufferUtils(cls, innerSource);
    } else if (cls.getName().equals(TextureData.Factory.class.getName())) {
        transformTextureData(cls, innerSource);
    } else if (cls.getName().equals(FileHandle.class.getName())) {
        transformFileHandle(cls);
    } else if (cls.getName().equals(Pixmap.class.getName())) {
        replaceClass(cls, innerSource.get(PixmapEmulator.class.getName()));
    } else if (cls.getName().equals(Matrix4.class.getName())) {
        transformMatrix(cls, innerSource);
    } else if (cls.getName().equals(VertexArray.class.getName()) ||
            cls.getName().equals(VertexBufferObject.class.getName())) {
        replaceClass(cls, innerSource.get(VertexArrayEmulator.class.getName()));
    } else if (cls.getName().equals(IndexArray.class.getName()) ||
            cls.getName().equals(IndexBufferObject.class.getName())) {
        replaceClass(cls, innerSource.get(IndexArrayEmulator.class.getName()));
    }
}
项目:libgdxcn    文件:ShaderProgram.java   
/** Constructs a new ShaderProgram and immediately compiles it.
 * 
 * @param vertexShader the vertex shader
 * @param fragmentShader the fragment shader */

public ShaderProgram (String vertexShader, String fragmentShader) {
    if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null");
    if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null");

    this.vertexShaderSource = vertexShader;
    this.fragmentShaderSource = fragmentShader;
    this.matrix = BufferUtils.newFloatBuffer(16);

    compileShaders(vertexShader, fragmentShader);
    if (isCompiled()) {
        fetchAttributes();
        fetchUniforms();
        addManagedShader(Gdx.app, this);
    }
}
项目:libgdxcn    文件:ShaderProgram.java   
private int loadShader (int type, String source) {
        GL20 gl = Gdx.gl20;
        IntBuffer intbuf = BufferUtils.newIntBuffer(1);

        int shader = gl.glCreateShader(type);
        if (shader == 0) return -1;

        gl.glShaderSource(shader, source);
        gl.glCompileShader(shader);
        gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, intbuf);

        int compiled = intbuf.get(0);
        if (compiled == 0) {
// gl.glGetShaderiv(shader, GL20.GL_INFO_LOG_LENGTH, intbuf);
// int infoLogLength = intbuf.get(0);
// if (infoLogLength > 1) {
            String infoLog = gl.glGetShaderInfoLog(shader);
            log += infoLog;
// }
            return -1;
        }

        return shader;
    }
项目:libgdxcn    文件:VertexBufferObjectSubData.java   
@Override
public void setVertices (float[] vertices, int offset, int count) {
    isDirty = true;
    if (isDirect) {
        BufferUtils.copy(vertices, byteBuffer, count, offset);
        buffer.position(0);
        buffer.limit(count);
    } else {
        buffer.clear();
        buffer.put(vertices, offset, count);
        buffer.flip();
        byteBuffer.position(0);
        byteBuffer.limit(buffer.limit() << 2);
    }

    bufferChanged();
}
项目:libgdxcn    文件:FrameBuffer.java   
/** Releases all resources associated with the FrameBuffer. */
public void dispose () {
    GL20 gl = Gdx.gl20;

    IntBuffer handle = BufferUtils.newIntBuffer(1);

    colorTexture.dispose();
    if (hasDepth)
        gl.glDeleteRenderbuffer(depthbufferHandle);

    if (hasStencil)
        gl.glDeleteRenderbuffer(stencilbufferHandle);

    gl.glDeleteFramebuffer(framebufferHandle);

    if (buffers.get(Gdx.app) != null) buffers.get(Gdx.app).removeValue(this, true);
}
项目:libgdxcn    文件:ETC1.java   
public ETC1Data (FileHandle pkmFile) {
    byte[] buffer = new byte[1024 * 10];
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(pkmFile.read())));
        int fileSize = in.readInt();
        compressedData = BufferUtils.newUnsafeByteBuffer(fileSize);
        int readBytes = 0;
        while ((readBytes = in.read(buffer)) != -1) {
            compressedData.put(buffer, 0, readBytes);
        }
        compressedData.position(0);
        compressedData.limit(compressedData.capacity());
    } catch (Exception e) {
        throw new GdxRuntimeException("Couldn't load pkm file '" + pkmFile + "'", e);
    } finally {
        StreamUtils.closeQuietly(in);
    }

    width = getWidthPKM(compressedData, 0);
    height = getHeightPKM(compressedData, 0);
    dataOffset = PKM_HEADER_SIZE;
    compressedData.position(dataOffset);
    checkNPOT();
}
项目:libgdxcn    文件:Pixmap.java   
private void create (int width, int height, Format format2) {
    this.width = width;
    this.height = height;
    this.format = Format.RGBA8888;
    canvas = Canvas.createIfSupported();
    canvas.getCanvasElement().setWidth(width);
    canvas.getCanvasElement().setHeight(height);
    context = canvas.getContext2d();
    context.setGlobalCompositeOperation(getComposite());
    buffer = BufferUtils.newIntBuffer(1);
    id = nextId++;
    buffer.put(0, id);
    pixmaps.put(id, this);
}
项目:TinyVoxel    文件:Pixmap.java   
private void create (int width, int height, Format format2) {
    this.width = width;
    this.height = height;
    this.format = Format.RGBA8888;
    canvas = Canvas.createIfSupported();
    canvas.getCanvasElement().setWidth(width);
    canvas.getCanvasElement().setHeight(height);
    context = canvas.getContext2d();
    context.setGlobalCompositeOperation(getComposite());
    buffer = BufferUtils.newIntBuffer(1);
    id = nextId++;
    buffer.put(0, id);
    pixmaps.put(id, this);
}
项目:TinyVoxel    文件:Grid.java   
public void init(Bundle owner, int x, int y, int z) {
    this.owner = owner;
    this.x = x;
    this.y = y;
    this.z = z;

    transform.idt();
    transform.translate(x * Config.GRID_SIZE, y * Config.GRID_SIZE, z * Config.GRID_SIZE);

    inverseTransform.set(transform);
    inverseTransform.inv();

    transformBuffer.rewind();
    transformBuffer.put(transform.val);
    transformBuffer.rewind();

    inverseTransformBuffer.rewind();
    inverseTransformBuffer.put(inverseTransform.val);
    inverseTransformBuffer.rewind();

    this.matrix.clear();
    BufferUtils.copy(transform.val, this.matrix, transform.val.length, 0);
}
项目:ns2-scc-profiler    文件:Pixmap.java   
private void create (int width, int height, Format format2) {
    this.width = width;
    this.height = height;
    this.format = Format.RGBA8888;
    canvas = Canvas.createIfSupported();
    canvas.getCanvasElement().setWidth(width);
    canvas.getCanvasElement().setHeight(height);
    context = canvas.getContext2d();
    context.setGlobalCompositeOperation(getComposite());
    buffer = BufferUtils.newIntBuffer(1);
    id = nextId++;
    buffer.put(0, id);
    pixmaps.put(id, this);
}
项目:robovm-samples    文件:MetalBasic3DRenderer.java   
private void updateConstantBuffer() {
    baseModelViewMatrix.set(viewMatrix).translate(0.0f,  0.0f,  5f).rotate(1, 1, 1, rotation);
    ByteBuffer constant_buffer = dynamicConstantBuffer[constantDataBufferIndex].getContents();
    constant_buffer.order(ByteOrder.nativeOrder());
    for (int i = 0; i < kNumberOfBoxes; i++) {
        int multiplier = ((i % 2) == 0?1: -1);
        modelViewMatrix.set(baseModelViewMatrix).translate(0, 0, multiplier * 1.5f).rotate(1, 1, 1, rotation);

        normalMatrix.set(modelViewMatrix).tra().inv();
        constant_buffer.position((sizeOfConstantT *i) + normalMatrixOffset);
        BufferUtils.copy(normalMatrix.getValues(), 0, 16, constant_buffer);

        combinedMatrix.set(projectionMatrix).mul(modelViewMatrix);
        constant_buffer.position((sizeOfConstantT * i) + modelViewProjectionMatrixOffset);
        BufferUtils.copy(combinedMatrix.getValues(), 0, 16, constant_buffer);
    }
    rotation += 0.01;
}
项目:vtm    文件:Pixmap.java   
private void create (int width, int height, Format format2) {
    this.width = width;
    this.height = height;
    this.format = Format.RGBA8888;
    canvas = Canvas.createIfSupported();
    canvas.getCanvasElement().setWidth(width);
    canvas.getCanvasElement().setHeight(height);
    context = canvas.getContext2d();
    context.setGlobalCompositeOperation(getComposite());
    buffer = BufferUtils.newIntBuffer(1);
    id = nextId++;
    buffer.put(0, id);
    pixmaps.put(id, this);
}
项目:ingress-indonesia-dev    文件:ShaderProgram.java   
public ShaderProgram(String paramString1, String paramString2)
{
  if (paramString1 == null)
    throw new IllegalArgumentException("vertex shader must not be null");
  if (paramString2 == null)
    throw new IllegalArgumentException("fragment shader must not be null");
  this.vertexShaderSource = paramString1;
  this.fragmentShaderSource = paramString2;
  this.matrix = BufferUtils.newFloatBuffer(16);
  compileShaders(paramString1, paramString2);
  if (isCompiled())
  {
    fetchAttributes();
    fetchUniforms();
    addManagedShader(Gdx.app, this);
  }
}
项目:ingress-indonesia-dev    文件:ShaderProgram.java   
private int loadShader(int paramInt, String paramString)
{
  GL20 localGL20 = Gdx.graphics.getGL20();
  IntBuffer localIntBuffer = BufferUtils.newIntBuffer(1);
  int i = localGL20.glCreateShader(paramInt);
  if (i == 0)
    return -1;
  localGL20.glShaderSource(i, paramString);
  localGL20.glCompileShader(i);
  localGL20.glGetShaderiv(i, 35713, localIntBuffer);
  if (localIntBuffer.get(0) == 0)
  {
    String str = localGL20.glGetShaderInfoLog(i);
    this.log += str;
    return -1;
  }
  return i;
}
项目:ingress-indonesia-dev    文件:VertexBufferObjectSubData.java   
public VertexBufferObjectSubData(boolean paramBoolean, int paramInt, VertexAttribute[] paramArrayOfVertexAttribute)
{
  this.isStatic = paramBoolean;
  this.attributes = new VertexAttributes(paramArrayOfVertexAttribute);
  this.byteBuffer = BufferUtils.newByteBuffer(paramInt * this.attributes.vertexSize);
  this.isDirect = true;
  if (paramBoolean);
  for (int i = 35044; ; i = 35048)
  {
    this.usage = i;
    this.buffer = this.byteBuffer.asFloatBuffer();
    this.bufferHandle = createBufferObject();
    this.buffer.flip();
    this.byteBuffer.flip();
    return;
  }
}
项目:ingress-indonesia-dev    文件:FrameBuffer.java   
public void dispose()
{
  GL20 localGL20 = Gdx.graphics.getGL20();
  IntBuffer localIntBuffer = BufferUtils.newIntBuffer(1);
  this.colorTexture.dispose();
  if (this.hasDepth)
  {
    localIntBuffer.put(this.depthbufferHandle);
    localIntBuffer.flip();
    localGL20.glDeleteRenderbuffers(1, localIntBuffer);
  }
  localIntBuffer.clear();
  localIntBuffer.put(this.framebufferHandle);
  localIntBuffer.flip();
  localGL20.glDeleteFramebuffers(1, localIntBuffer);
  if (buffers.get(Gdx.app) != null)
    ((List)buffers.get(Gdx.app)).remove(this);
}
项目:ingress-indonesia-dev    文件:VertexBufferObject.java   
public VertexBufferObject(boolean paramBoolean, int paramInt, VertexAttributes paramVertexAttributes)
{
  this.isStatic = paramBoolean;
  this.attributes = paramVertexAttributes;
  this.attributeIndexCache = new int[paramVertexAttributes.size()];
  this.byteBuffer = BufferUtils.newUnsafeByteBuffer(paramInt * this.attributes.vertexSize);
  this.buffer = this.byteBuffer.asFloatBuffer();
  this.buffer.flip();
  this.byteBuffer.flip();
  if (paramBoolean);
  for (int i = 35044; ; i = 35048)
  {
    this.usage = i;
    this.bufferHandle = createBufferObject();
    return;
  }
}
项目:ingress-indonesia-dev    文件:VertexBufferObject.java   
public void dispose()
{
  if (Gdx.gl20 != null)
  {
    tmpHandle.clear();
    tmpHandle.put(this.bufferHandle);
    tmpHandle.flip();
    GL20 localGL20 = Gdx.gl20;
    localGL20.glBindBuffer(34962, 0);
    localGL20.glDeleteBuffers(1, tmpHandle);
  }
  for (this.bufferHandle = 0; ; this.bufferHandle = 0)
  {
    BufferUtils.disposeUnsafeByteBuffer(this.byteBuffer);
    return;
    tmpHandle.clear();
    tmpHandle.put(this.bufferHandle);
    tmpHandle.flip();
    GL11 localGL11 = Gdx.gl11;
    localGL11.glBindBuffer(34962, 0);
    localGL11.glDeleteBuffers(1, tmpHandle);
  }
}
项目:GangsterSquirrel    文件:MainGameClass.java   
/**
 * Takes a screenshot of the current game state and saves it in the assets directory
 */
public void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);
    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.local("screenshots/screenshot.png"), pixmap);
    pixmap.dispose();
}
项目:PixelDungeonTC    文件:Program.java   
public void link() {
    Gdx.gl.glLinkProgram( handle );

    IntBuffer status = BufferUtils.newIntBuffer(1);
    Gdx.gl.glGetProgramiv( handle, GL20.GL_LINK_STATUS, status );
    if (status.get() == GL20.GL_FALSE) {
        throw new Error( Gdx.gl.glGetProgramInfoLog( handle ) );
    }
}
项目:PixelDungeonTC    文件:Shader.java   
public void compile() {
    Gdx.gl.glCompileShader( handle );

    IntBuffer status = BufferUtils.newIntBuffer(1);
    Gdx.gl.glGetShaderiv( handle, GL20.GL_COMPILE_STATUS, status);
    if (status.get() == GL20.GL_FALSE) {
        throw new Error( Gdx.gl.glGetShaderInfoLog( handle ) );
    }
}
项目:jrpg-engine    文件:ScreenShotUtil.java   
public static void takeScreenShot(final String filePath) {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(
            0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true
    );

    Pixmap pixmap = new Pixmap(
            Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888
    );
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.external(filePath), pixmap);
    pixmap.dispose();
}
项目:gdx-bullet-gwt    文件:btBulletWorldImporter.java   
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) {
        final int len = (int) fileHandle.length();
        if (len <= 0)
            throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified");
        java.nio.ByteBuffer buff = BufferUtils.newByteBuffer(len);
        buff.put(fileHandle.readBytes());
        buff.position(0);
        boolean result = loadFileFromMemory(buff, len);
//      com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff);
        return result;
    }
项目:joe    文件:MainCamera.java   
public void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), true);
    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.external(UUID.randomUUID().toString() + ".png"), pixmap);
    pixmap.dispose();
}
项目:Argent    文件:GeometryShaderProgram.java   
protected int loadShader(int type, String source) throws Exception {
    IntBuffer intbuf = BufferUtils.newIntBuffer(1);
    int shader = Gdx.gl.glCreateShader(type);
    if(shader == 0) return -1;
    Gdx.gl.glShaderSource(shader, source);
    Gdx.gl.glCompileShader(shader);
    Gdx.gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, intbuf);

    int compiled = intbuf.get(0);
    if(compiled == 0) {
        $setValue_log($getValue__log() + Gdx.gl.glGetShaderInfoLog(shader));
        return -1;
    }
    return shader;
}
项目:gdx-freetype-gwt    文件:FreeTypeFontGenerator.java   
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file
 * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a
 * {@link GdxRuntimeException} if loading did not succeed. */
public FreeTypeFontGenerator (FileHandle fontFile) {
    name = fontFile.pathWithoutExtension();
    int fileSize = (int)fontFile.length();

    library = FreeType.initFreeType();
    if (library == null) throw new GdxRuntimeException("Couldn't initialize FreeType");

    ByteBuffer buffer;
    InputStream input = fontFile.read();
    try {
        if (fileSize == 0) {
            // Copy to a byte[] to get the file size, then copy to the buffer.
            byte[] data = StreamUtils.copyStreamToByteArray(input, fileSize > 0 ? (int)(fileSize * 1.5f) : 1024 * 16);
            buffer = BufferUtils.newByteBuffer(data.length);
            BufferUtils.copy(data, 0, buffer, data.length);
        } else {
            // Trust the specified file size.
            buffer = BufferUtils.newByteBuffer(fileSize);
            StreamUtils.copyStream(input, buffer);
        }
    } catch (IOException ex) {
        throw new GdxRuntimeException(ex);
    } finally {
        StreamUtils.closeQuietly(input);
    }

    face = library.newMemoryFace(buffer, 0);
    if (face == null) throw new GdxRuntimeException("Couldn't create face for font: " + fontFile);

    if (checkForBitmapFont()) return;
    setPixelSizes(0, 15);
}
项目:gdx-bullet-gwt    文件:btBulletWorldImporter.java   
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) {
        final int len = (int) fileHandle.length();
        if (len <= 0)
            throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified");
        java.nio.ByteBuffer buff = BufferUtils.newByteBuffer(len);
        buff.put(fileHandle.readBytes());
        buff.position(0);
        boolean result = loadFileFromMemory(buff, len);
//      com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff);
        return result;
    }
项目:ns2-scc-profiler    文件:Pixmap.java   
private void create (int width, int height, Format format2) {
    this.width = width;
    this.height = height;
    this.format = Format.RGBA8888;
    canvas = Canvas.createIfSupported();
    canvas.getCanvasElement().setWidth(width);
    canvas.getCanvasElement().setHeight(height);
    context = canvas.getContext2d();
    context.setGlobalCompositeOperation(getComposite());
    buffer = BufferUtils.newIntBuffer(1);
    id = nextId++;
    buffer.put(0, id);
    pixmaps.put(id, this);
}
项目:pixel-dungeon-rebirth    文件:Program.java   
public void link() {
    Gdx.gl.glLinkProgram(handle);

    IntBuffer status = BufferUtils.newIntBuffer(1);
    Gdx.gl.glGetProgramiv(handle, GL20.GL_LINK_STATUS, status);
    if (status.get() == GL20.GL_FALSE) {
        throw new Error(Gdx.gl.glGetProgramInfoLog(handle));
    }
}
项目:pixel-dungeon-rebirth    文件:Shader.java   
public void compile() {
    Gdx.gl.glCompileShader(handle);

    IntBuffer status = BufferUtils.newIntBuffer(1);
    Gdx.gl.glGetShaderiv(handle, GL20.GL_COMPILE_STATUS, status);
    if (status.get() == GL20.GL_FALSE) {
        throw new Error(Gdx.gl.glGetShaderInfoLog(handle));
    }
}
项目:teavm-libgdx    文件:VertexArrayEmulator.java   
@Override
public void setVertices(float[] vertices, int offset, int count) {
    isDirty = true;
    BufferUtils.copy(vertices, buffer, count, offset);
    buffer.position(0);
    buffer.limit(count);
    bufferChanged();
}
项目:teavm-libgdx    文件:VertexArrayEmulator.java   
@Override
public void updateVertices(int targetOffset, float[] vertices, int sourceOffset, int count) {
    isDirty = true;
    final int pos = buffer.position();
    buffer.position(targetOffset);
    BufferUtils.copy(vertices, sourceOffset, count, buffer);
    buffer.position(pos);
    bufferChanged();
}
项目:teavm-libgdx    文件:IndexArrayEmulator.java   
/**
 * Creates a new IndexBufferObject to be used with vertex arrays.
 *
 * @param maxIndices
 *            the maximum number of indices this buffer can hold
 */
public IndexArrayEmulator(int maxIndices) {
    this.isDirect = true;
    buffer = BufferUtils.newShortBuffer(maxIndices);
    buffer.flip();
    bufferHandle = Gdx.gl20.glGenBuffer();
    usage = GL20.GL_STATIC_DRAW;
}