当前位置: 首页>>代码示例>>Java>>正文


Java BufferUtils类代码示例

本文整理汇总了Java中com.badlogic.gdx.utils.BufferUtils的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils类的具体用法?Java BufferUtils怎么用?Java BufferUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BufferUtils类属于com.badlogic.gdx.utils包,在下文中一共展示了BufferUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: takeScreenshot

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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();
}
 
开发者ID:eskalon,项目名称:ProjektGG,代码行数:18,代码来源:ScreenshotUtils.java

示例2: getScissorRect

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:mingwuyun,项目名称:cocos2d-java,代码行数:21,代码来源:GLView.java

示例3: isSupported

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:CypherCove,项目名称:gdx-cclibs,代码行数:19,代码来源:Anisotropy.java

示例4: loadTexture

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
/**
 * 
 * @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;
}
 
开发者ID:urstruktur,项目名称:zierfisch,代码行数:24,代码来源:TextureBuilder.java

示例5: getBuffer

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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;
}
 
开发者ID:intrigus,项目名称:gdx-freetype-gwt,代码行数:17,代码来源:FreeType.java

示例6: getFrameBufferPixmap

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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;
}
 
开发者ID:mbrlabs,项目名称:Mundus,代码行数:25,代码来源:BasePicker.java

示例7: copy

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:anonl,项目名称:nvlist,代码行数:25,代码来源:PixmapUtil.java

示例8: transformClass

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
@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()));
    }
}
 
开发者ID:konsoletyper,项目名称:teavm-libgdx,代码行数:21,代码来源:OverlayTransformer.java

示例9: ShaderProgram

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
/** 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);
	}
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:21,代码来源:ShaderProgram.java

示例10: loadShader

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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;
	}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:25,代码来源:ShaderProgram.java

示例11: setVertices

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
@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();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:18,代码来源:VertexBufferObjectSubData.java

示例12: dispose

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
/** 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);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:18,代码来源:FrameBuffer.java

示例13: ETC1Data

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:26,代码来源:ETC1.java

示例14: create

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:15,代码来源:Pixmap.java

示例15: create

import com.badlogic.gdx.utils.BufferUtils; //导入依赖的package包/类
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);
}
 
开发者ID:neuroradiology,项目名称:TinyVoxel,代码行数:15,代码来源:Pixmap.java


注:本文中的com.badlogic.gdx.utils.BufferUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。