本文整理汇总了Java中com.badlogic.gdx.utils.BufferUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils.copy方法的具体用法?Java BufferUtils.copy怎么用?Java BufferUtils.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.BufferUtils
的用法示例。
在下文中一共展示了BufferUtils.copy方法的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();
}
示例2: 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;
}
示例3: 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();
}
示例4: 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();
}
示例5: updateConstantBuffer
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
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;
}
示例6: takeScreenshot
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/**
* 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();
}
示例7: takeScreenShot
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
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();
}
示例8: takeScreenshot
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
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();
}
示例9: FreeTypeFontGenerator
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/** 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);
}
示例10: setVertices
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@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();
}
示例11: updateVertices
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@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();
}
示例12: updateVertices
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@Override
public void updateVertices (int targetOffset, float[] vertices, int sourceOffset, int count) {
isDirty = true;
final int pos = byteBuffer.position();
byteBuffer.position(targetOffset * 4);
BufferUtils.copy(vertices, sourceOffset, count, byteBuffer);
byteBuffer.position(pos);
buffer.position(0);
bufferChanged();
}
示例13: updateVertices
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@Override
public void updateVertices (int targetOffset, float[] vertices, int sourceOffset, int count) {
final int pos = byteBuffer.position();
byteBuffer.position(targetOffset * 4);
BufferUtils.copy(vertices, sourceOffset, count, byteBuffer);
byteBuffer.position(pos);
}
示例14: setVertices
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@Override
public void setVertices (float[] vertices, int offset, int count) {
isDirty = true;
BufferUtils.copy(vertices, byteBuffer, count, offset);
buffer.position(0);
buffer.limit(count);
bufferChanged();
}
示例15: getPixmap
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/**
* @return Pixmap representing the glyph, needs to be disposed manually.
*/
public Pixmap getPixmap(Format format) {
Pixmap pixmap = new Pixmap(getWidth(), getRows(), Format.Alpha);
BufferUtils.copy(getBuffer(), pixmap.getPixels(), pixmap.getPixels().capacity());
Pixmap converted = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), format);
Blending blending = Pixmap.getBlending();
Pixmap.setBlending(Blending.None);
converted.drawPixmap(pixmap, 0, 0);
Pixmap.setBlending(blending);
pixmap.dispose();
return converted;
}