本文整理汇总了Java中com.jogamp.common.nio.Buffers.newDirectByteBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java Buffers.newDirectByteBuffer方法的具体用法?Java Buffers.newDirectByteBuffer怎么用?Java Buffers.newDirectByteBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jogamp.common.nio.Buffers
的用法示例。
在下文中一共展示了Buffers.newDirectByteBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toImage
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
/**
* Turns gl to BufferedImage with fixed format
*
* @param gl
* @param w
* @param h
* @return
*/
protected BufferedImage toImage(GL2 gl, int w, int h) {
gl.glReadBuffer(GL.GL_FRONT); // or GL.GL_BACK
ByteBuffer glBB = Buffers.newDirectByteBuffer(4 * w * h);
gl.glReadPixels(0, 0, w, h, GL2.GL_BGRA, GL.GL_BYTE, glBB);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int b = 2 * glBB.get();
int g = 2 * glBB.get();
int r = 2 * glBB.get();
int a = glBB.get(); // not using
bd[(h - y - 1) * w + x] = (b << 16) | (g << 8) | r | 0xFF000000;
}
}
return bi;
}
示例2: linkProgram
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
final public boolean linkProgram(int programId) {
gl.glLinkProgram(programId);
// check state
IntBuffer linkStatus = IntBuffer.allocate(1);
gl.glGetProgramiv(programId, GL3.GL_LINK_STATUS, linkStatus);
while (linkStatus.remaining() > 0) {
int result = linkStatus.get();
if (result == 0) {
// get error
IntBuffer infoLogLengthBuffer = Buffers.newDirectIntBuffer(1);
ByteBuffer infoLogBuffer = Buffers.newDirectByteBuffer(2048);
gl.glGetProgramInfoLog(programId, infoLogBuffer.limit(), infoLogLengthBuffer, infoLogBuffer);
final byte[] infoLogBytes = new byte[infoLogLengthBuffer.get()];
infoLogBuffer.get(infoLogBytes);
String infoLogString = new String(infoLogBytes);
// be verbose
Console.println("[" + programId + "]: failed: " + infoLogString);
//
return false;
}
}
//
return true;
}
示例3: checkShader
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
/**
* Check a shader for errors.
* <p>
* Call this method on a compiled shader.
* @param gl the OpenGL interface
* @param shader the ID of the shader to check
*/
private static void checkShader(@Nonnull GL2 gl, int shader) {
IntBuffer intBuffer = IntBuffer.allocate(1);
gl.glGetShaderiv(shader, GL2.GL_COMPILE_STATUS, intBuffer);
if (intBuffer.get(0) == GL.GL_FALSE) {
gl.glGetShaderiv(shader, GL2.GL_INFO_LOG_LENGTH, intBuffer);
int length = intBuffer.get(0);
String out = null;
if (length > 0) {
ByteBuffer infoLog = Buffers.newDirectByteBuffer(length);
gl.glGetShaderInfoLog(shader, infoLog.limit(), intBuffer, infoLog);
byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
try {
out = new String(infoBytes, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new GLException("Error during shader compilation");
}
}
throw new GLException("Error during shader compilation:\n" + out);
}
}
示例4: checkProgram
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
/**
* Check the program for errors.
* <p>
* Call this after a shader has been linked into the program.
* @param gl the OpenGL interface
*/
private void checkProgram(@Nonnull GL2 gl) {
IntBuffer intBuffer = IntBuffer.allocate(1);
gl.glGetProgramiv(id, GL2.GL_LINK_STATUS, intBuffer);
if (intBuffer.get(0) == GL.GL_FALSE) {
gl.glGetProgramiv(id, GL2.GL_INFO_LOG_LENGTH, intBuffer);
int length = intBuffer.get(0);
String out = null;
if (length > 0) {
ByteBuffer infoLog = Buffers.newDirectByteBuffer(length);
gl.glGetProgramInfoLog(id, infoLog.limit(), intBuffer, infoLog);
byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
try {
out = new String(infoBytes, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new GLException("Error during program link");
}
}
throw new GLException("Error during program link:\n" + out);
}
}
示例5: doInit
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
@Override
public boolean doInit(GL2ES2 gl) {
vertices = Buffers.newDirectByteBuffer(options.numVerticesInBuffer * bytesPerVertex);
try {
final int[] vbos = new int[2];
int numBuffers = 1;
gl.glGenBuffers(numBuffers, IntBuffer.wrap(vbos));
vertexVbo = vbos[0];
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexVbo);
gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity(), null, GL2ES2.GL_STREAM_DRAW);
} catch (final Exception e) {
options.usingVBOs = false;
}
return true;
}
示例6: allocateBlankBuffer
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
/** Allocates a temporary, empty ByteBuffer suitable for use in a
call to glCompressedTexImage2D. This is used by the Texture
class to expand non-power-of-two DDS compressed textures to
power-of-two sizes on hardware not supporting OpenGL 2.0 and the
NPOT texture extension. The specified OpenGL internal format
must be one of GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, or
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT.
*/
public static ByteBuffer allocateBlankBuffer(final int width,
final int height,
final int openGLInternalFormat) {
int size = width * height;
switch (openGLInternalFormat) {
case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
size /= 2;
break;
case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
break;
default:
throw new IllegalArgumentException("Illegal OpenGL texture internal format " +
openGLInternalFormat);
}
if (size == 0)
size = 1;
return Buffers.newDirectByteBuffer(size);
}
示例7: checkShaderLogInfo
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
public static void checkShaderLogInfo(GL2 inGL, int inShaderObjectID) {
IntBuffer tReturnValue = Buffers.newDirectIntBuffer(1);
inGL.glGetShaderiv(inShaderObjectID, GL2.GL_COMPILE_STATUS, tReturnValue);
if (tReturnValue.get(0) == GL.GL_FALSE) {
inGL.glGetShaderiv(inShaderObjectID, GL2.GL_INFO_LOG_LENGTH, tReturnValue);
final int length = tReturnValue.get(0);
String out = null;
if (length > 0) {
final ByteBuffer infoLog = Buffers.newDirectByteBuffer(length);
inGL.glGetShaderInfoLog(inShaderObjectID, infoLog.limit(), tReturnValue, infoLog);
final byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
out = new String(infoBytes);
System.out.print(out);
}
throw new GLException("Error during shader compilation:\n" + out + "\n");
}
}
示例8: checkProgramLogInfo
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
public static void checkProgramLogInfo(GL2 inGL, int inShaderObjectID) {
IntBuffer tReturnValue = Buffers.newDirectIntBuffer(1);
inGL.glGetProgramiv(inShaderObjectID, GL2.GL_LINK_STATUS, tReturnValue);
if (tReturnValue.get(0) == GL.GL_FALSE) {
inGL.glGetProgramiv(inShaderObjectID, GL2.GL_INFO_LOG_LENGTH, tReturnValue);
final int length = tReturnValue.get(0);
String out = null;
if (length > 0) {
final ByteBuffer infoLog = Buffers.newDirectByteBuffer(length);
inGL.glGetProgramInfoLog(inShaderObjectID, infoLog.limit(), tReturnValue, infoLog);
final byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
out = new String(infoBytes);
System.out.print(out);
}
throw new GLException("Error during shader linking:\n" + out + "\n");
}
}
示例9: readPixels
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
private static Texture readPixels(BufferedImage img, boolean storeAlphaChannel) {
int[] packedPixels = new int[img.getWidth() * img.getHeight()];
PixelGrabber pixelgrabber = new PixelGrabber(img, 0, 0, img.getWidth(), img.getHeight(), packedPixels, 0, img.getWidth());
try {
pixelgrabber.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException();
}
int bytesPerPixel = storeAlphaChannel ? 4 : 3;
ByteBuffer unpackedPixels = Buffers.newDirectByteBuffer(packedPixels.length * bytesPerPixel);
for (int row = img.getHeight() - 1; row >= 0; row--) {
for (int col = 0; col < img.getWidth(); col++) {
int packedPixel = packedPixels[row * img.getWidth() + col];
unpackedPixels.put((byte) ((packedPixel >> 16) & 0xFF));
unpackedPixels.put((byte) ((packedPixel >> 8) & 0xFF));
unpackedPixels.put((byte) ((packedPixel >> 0) & 0xFF));
if (storeAlphaChannel) {
unpackedPixels.put((byte) ((packedPixel >> 24) & 0xFF));
}
}
}
unpackedPixels.flip();
return new Texture(unpackedPixels, img.getWidth(), img.getHeight());
}
示例10: SoundFile
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
public SoundFile(byte[] data, int freq, int loop,int size, int format){
this.data[0] = Buffers.newDirectByteBuffer(data);
this.freq[0] = freq;
this.loop[0] = loop;
this.size[0] = size;
this.format[0] = format;
al.alGenBuffers(1, buffer, 0);
al.alBufferData(buffer[0], this.format[0], this.data[0], this.size[0], this.freq[0]);
}
示例11: linkProgram
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
final public boolean linkProgram(int programId) {
gl.glLinkProgramARB(programId);
// check state
IntBuffer linkStatus = IntBuffer.allocate(1);
gl.glGetProgramiv(programId, GL2.GL_LINK_STATUS, linkStatus);
while (linkStatus.remaining() > 0) {
int result = linkStatus.get();
if (result == 0) {
// get error
IntBuffer infoLogLengthBuffer = Buffers.newDirectIntBuffer(1);
ByteBuffer infoLogBuffer = Buffers.newDirectByteBuffer(2048);
gl.glGetProgramInfoLog(programId, infoLogBuffer.limit(), infoLogLengthBuffer, infoLogBuffer);
final byte[] infoLogBytes = new byte[infoLogLengthBuffer.get()];
infoLogBuffer.get(infoLogBytes);
String infoLogString = new String(infoLogBytes);
// be verbose
Console.println("[" + programId + "]: failed: " + infoLogString);
//
return false;
}
}
//
return true;
}
示例12: linkProgram
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
final public boolean linkProgram(int programId) {
gl.glLinkProgram(programId);
// check state
IntBuffer linkStatus = IntBuffer.allocate(1);
gl.glGetProgramiv(programId, GLES2.GL_LINK_STATUS, linkStatus);
while (linkStatus.remaining() > 0) {
int result = linkStatus.get();
if (result == 0) {
// get error
IntBuffer infoLogLengthBuffer = Buffers.newDirectIntBuffer(1);
ByteBuffer infoLogBuffer = Buffers.newDirectByteBuffer(2048);
gl.glGetProgramInfoLog(programId, infoLogBuffer.limit(), infoLogLengthBuffer, infoLogBuffer);
final byte[] infoLogBytes = new byte[infoLogLengthBuffer.get()];
infoLogBuffer.get(infoLogBytes);
String infoLogString = new String(infoLogBytes);
// be verbose
Console.println("[" + programId + "]: failed: " + infoLogString);
//
return false;
}
}
//
return true;
}
示例13: doInit
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
@Override
protected boolean doInit(GL2ES2 gl) {
program = CompassProgram.INSTANCE;
program.init(gl);
Astroid3f astroid = new Astroid3f(1, 8);
vertices = Buffers.newDirectByteBuffer(astroid.triangles.length * 24);
for (int i = 0; i < astroid.triangles.length; i++) {
float[] point = astroid.points[astroid.triangles[i]];
float[] normal = astroid.normals[astroid.triangles[i]];
vertices.putFloat(point[0]);
vertices.putFloat(point[1]);
vertices.putFloat(point[2]);
vertices.putFloat(normal[0]);
vertices.putFloat(normal[1]);
vertices.putFloat(normal[2]);
}
vertices.rewind();
StaticRenderer.Options options = new StaticRenderer.Options(true, GL.GL_TRIANGLES);
options.addAttribute(3, GL.GL_FLOAT, false);
options.addAttribute(3, GL.GL_FLOAT, false);
renderer = new StaticRenderer(vertices, options);
renderer.init(gl);
textRenderer = new TextRenderer(labelFont, true, true, null, false);
textRenderer.init();
textRenderer.setUseVertexArrays(true);
textRenderer.setColor(Color.WHITE);
return true;
}
示例14: nonLinearHypsoTextureBuffer
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
private ByteBuffer nonLinearHypsoTextureBuffer() {
int cols = getCols();
int rows = getRows();
ByteBuffer buffer = Buffers.newDirectByteBuffer(cols * rows);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
int i = (int)(texture1DMapper.get1DTextureCoordinate(c, r) * 255);
buffer.put((byte)(i));
}
}
buffer.rewind();
return buffer;
}
示例15: imageToBytes
import com.jogamp.common.nio.Buffers; //导入方法依赖的package包/类
public static ByteBuffer imageToBytes(BufferedImage img, int[] w_h)
{
int width = img.getWidth();
int height = img.getHeight();
int bpp = img.getColorModel().getPixelSize()/8;
ByteBuffer data = Buffers.newDirectByteBuffer(width * bpp * height);
Raster alpha = img.getAlphaRaster();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int RGB = img.getRGB(x, y);
data.put((byte)(RGB >> 16));
data.put((byte)((RGB >> 8) & 0xFF));
data.put((byte)(RGB & 0xFF));
if (bpp == 4)
{
data.put((byte)alpha.getPixel(x, y, new int[1])[0]);
}
}
}
data.flip();
w_h[0] = width;
w_h[1] = height;
w_h[2] = bpp;
return data;
}