本文整理汇总了Java中org.lwjgl.BufferUtils.createByteBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils.createByteBuffer方法的具体用法?Java BufferUtils.createByteBuffer怎么用?Java BufferUtils.createByteBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.BufferUtils
的用法示例。
在下文中一共展示了BufferUtils.createByteBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
@Override
public Bitmap load(InputStream stream) throws Exception
{
ByteBuffer buffer = BufferUtils.createByteBuffer(256);
try (ReadableByteChannel channel = Channels.newChannel(stream))
{
while (channel.read(buffer) != -1)
{
if (buffer.remaining() == 0)
{
buffer = resizeBuffer(buffer, buffer.capacity() * 2);
}
}
}
buffer.flip();
return new Bitmap(buffer, false, false);
}
示例2: setMouseCursor
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException {
try {
Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight()));
Graphics g = temp.getGraphics();
ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4);
g.drawImage(image.getFlippedCopy(false, true), 0, 0);
g.flush();
g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer);
Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight());
Mouse.setNativeCursor(cursor);
} catch (Throwable e) {
Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
}
}
示例3: setMouseCursor
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.Image, int, int)
*/
public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException {
try {
Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight()));
Graphics g = temp.getGraphics();
ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4);
g.drawImage(image.getFlippedCopy(false, true), 0, 0);
g.flush();
g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer);
Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),image.getHeight());
Mouse.setNativeCursor(cursor);
} catch (Throwable e) {
Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
}
}
示例4: ioResourceToByteBuffer
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
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 = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
ReadableByteChannel rbc = Channels.newChannel(source)){
buffer = BufferUtils.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;
}
示例5: Texture
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
public Texture(String string) throws IOException {
BufferedImage bi;
bi = ImageIO.read(new File(string));
this.width = bi.getWidth();
this.height = bi.getHeight();
int[] pixels_raw = bi.getRGB(0, 0, this.width, this.height, null, 0, this.width);
ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int pixel = pixels_raw[i*width + j];
pixels.put((byte) ((pixel >> 16) & 0xFF));
pixels.put((byte) ((pixel >> 8) & 0xFF));
pixels.put((byte) (pixel & 0xFF));
pixels.put((byte) ((pixel >> 24) & 0xFF));
}
}
pixels.flip();
id = glGenTextures();
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
}
示例6: loadShader
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
public static ShaderLoader loadShader(IResourceManager resourceManager, ShaderLoader.ShaderType type, String filename) throws IOException
{
ShaderLoader shaderloader = (ShaderLoader)type.getLoadedShaders().get(filename);
if (shaderloader == null)
{
ResourceLocation resourcelocation = new ResourceLocation("shaders/program/" + filename + type.getShaderExtension());
BufferedInputStream bufferedinputstream = new BufferedInputStream(resourceManager.getResource(resourcelocation).getInputStream());
byte[] abyte = toByteArray(bufferedinputstream);
ByteBuffer bytebuffer = BufferUtils.createByteBuffer(abyte.length);
bytebuffer.put(abyte);
bytebuffer.position(0);
int i = OpenGlHelper.glCreateShader(type.getShaderMode());
OpenGlHelper.glShaderSource(i, bytebuffer);
OpenGlHelper.glCompileShader(i);
if (OpenGlHelper.glGetShaderi(i, OpenGlHelper.GL_COMPILE_STATUS) == 0)
{
String s = StringUtils.trim(OpenGlHelper.glGetShaderInfoLog(i, 32768));
JsonException jsonexception = new JsonException("Couldn\'t compile " + type.getShaderName() + " program: " + s);
jsonexception.func_151381_b(resourcelocation.getResourcePath());
throw jsonexception;
}
shaderloader = new ShaderLoader(type, i, filename);
type.getLoadedShaders().put(filename, shaderloader);
}
return shaderloader;
}
示例7: Texture
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
public Texture(String filename) {
BufferedImage bufferedImage;
try {
URI file = getClass().getResource("/textures/" + filename).toURI();
bufferedImage = ImageIO.read(new File(file));
width = bufferedImage.getWidth();
height = bufferedImage.getHeight();
int[] pixels_raw;
pixels_raw = bufferedImage.getRGB(0, 0, width, height, null, 0, width);
ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int pixel = pixels_raw[i * width + j];
pixels.put((byte) ((pixel >> 16) & 0xFF)); // RED
pixels.put((byte) ((pixel >> 8) & 0xFF)); // GREEN
pixels.put((byte) ((pixel) & 0xFF)); // BLUE
pixels.put((byte) ((pixel >> 24) & 0xFF)); // ALPHA
}
}
// Prepares the ByteBuffer to be read from
pixels.flip();
id = glGenTextures();
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
} catch (IOException |URISyntaxException e) {
e.printStackTrace();
}
}
示例8: loadShader
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
public static ShaderLoader loadShader(IResourceManager resourceManager, ShaderLoader.ShaderType type, String filename) throws IOException
{
ShaderLoader shaderloader = (ShaderLoader)type.getLoadedShaders().get(filename);
if (shaderloader == null)
{
ResourceLocation resourcelocation = new ResourceLocation("shaders/program/" + filename + type.getShaderExtension());
IResource iresource = resourceManager.getResource(resourcelocation);
try
{
byte[] abyte = IOUtils.toByteArray((InputStream)(new BufferedInputStream(iresource.getInputStream())));
ByteBuffer bytebuffer = BufferUtils.createByteBuffer(abyte.length);
bytebuffer.put(abyte);
bytebuffer.position(0);
int i = OpenGlHelper.glCreateShader(type.getShaderMode());
OpenGlHelper.glShaderSource(i, bytebuffer);
OpenGlHelper.glCompileShader(i);
if (OpenGlHelper.glGetShaderi(i, OpenGlHelper.GL_COMPILE_STATUS) == 0)
{
String s = StringUtils.trim(OpenGlHelper.glGetShaderInfoLog(i, 32768));
JsonException jsonexception = new JsonException("Couldn\'t compile " + type.getShaderName() + " program: " + s);
jsonexception.setFilenameAndFlush(resourcelocation.getResourcePath());
throw jsonexception;
}
shaderloader = new ShaderLoader(type, i, filename);
type.getLoadedShaders().put(filename, shaderloader);
}
finally
{
IOUtils.closeQuietly((Closeable)iresource);
}
}
return shaderloader;
}
示例9: printLogInfo
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
private static boolean printLogInfo(int obj, String name)
{
IntBuffer intbuffer = BufferUtils.createIntBuffer(1);
ARBShaderObjects.glGetObjectParameterARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB, (IntBuffer)intbuffer);
int i = intbuffer.get();
if (i > 1)
{
ByteBuffer bytebuffer = BufferUtils.createByteBuffer(i);
intbuffer.flip();
ARBShaderObjects.glGetInfoLogARB(obj, intbuffer, bytebuffer);
byte[] abyte = new byte[i];
bytebuffer.get(abyte);
if (abyte[i - 1] == 0)
{
abyte[i - 1] = 10;
}
String s = new String(abyte);
SMCLog.info("Info log: " + name + "\n" + s);
return false;
}
else
{
return true;
}
}
示例10: getIntBuffer
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
public static IntBuffer getIntBuffer(int size)
{
if (intBuffer.capacity() < size)
{
int i = roundUpPOT(size);
byteBuffer = BufferUtils.createByteBuffer(i * 4);
intBuffer = byteBuffer.asIntBuffer();
}
return intBuffer;
}
示例11: glGetBooleanv
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
@Override
public void glGetBooleanv(int pname, IntBuffer params) {
ByteBuffer buffer = BufferUtils.createByteBuffer(params.capacity());
for (int b : params.array()) {
buffer.put((byte) b);
}
GL11.glGetBoolean(pname, buffer);
}
示例12: resizeBuffer
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) {
ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity);
buffer.flip();
newBuffer.put(buffer);
return newBuffer;
}
示例13: getImageBufferData
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.opengl.ImageData#getImageBufferData()
*/
public ByteBuffer getImageBufferData() {
return BufferUtils.createByteBuffer(getTexWidth() * getTexHeight() * 4);
}
示例14: resizeBuffer
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) {
ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity);
buffer.flip();
newBuffer.put(buffer);
return newBuffer;
}
示例15: imgToBuff
import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
public static ByteBuffer imgToBuff(BufferedImage image){
int[] pixels=new int[image.getWidth()*image.getHeight()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
ByteBuffer buffer=BufferUtils.createByteBuffer(image.getWidth()*image.getHeight()*image.getColorModel().getPixelSize()/8);
for(int y=0;y<image.getHeight();y++){
for(int x=0;x<image.getWidth();x++){
int pixel=pixels[y*image.getWidth()+x];
switch(image.getType()){
case TYPE_3BYTE_BGR:
case TYPE_INT_RGB:{
buffer.put((byte)(pixel>>16&0xFF)); // Red component
buffer.put((byte)(pixel>>8&0xFF)); // Green component
buffer.put((byte)(pixel&0xFF)); // Blue component
}
break;
case TYPE_4BYTE_ABGR:
case TYPE_INT_ARGB:{
buffer.put((byte)(pixel>>16&0xFF)); // Red component
buffer.put((byte)(pixel>>8&0xFF)); // Green component
buffer.put((byte)(pixel&0xFF)); // Blue component
buffer.put((byte)(pixel>>24&0xFF)); // Alpha component. Only for RGBA
}
break;
case TYPE_BYTE_GRAY:{
buffer.put((byte)pixel);
}
break;
case TYPE_USHORT_GRAY:{
buffer.putShort((short)pixel);
}
break;
default:
LogUtil.printlnEr(image.getType());
throw new IllegalStateException("Unknown type image format: "+image.getColorModel().toString());
}
}
}
buffer.flip();
return buffer;
}