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


Java BufferUtils.createByteBuffer方法代码示例

本文整理汇总了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);
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:19,代码来源:BitmapLoader.java

示例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);
     }
  }
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:21,代码来源:AppletGameContainer.java

示例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);
	}
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:21,代码来源:AppGameContainer.java

示例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;
}
 
开发者ID:tek256,项目名称:LD38,代码行数:27,代码来源:Util.java

示例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);
   }
 
开发者ID:markd315,项目名称:Devpro,代码行数:25,代码来源:Texture.java

示例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;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:31,代码来源:ShaderLoader.java

示例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();
    }
}
 
开发者ID:nitrodragon,项目名称:lwjgl3_stuff,代码行数:40,代码来源:Texture.java

示例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;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:39,代码来源:ShaderLoader.java

示例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;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:29,代码来源:Shaders.java

示例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;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:12,代码来源:ShadersTex.java

示例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);
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:9,代码来源:OpenGLImpl.java

示例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;
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:7,代码来源:Utils.java

示例13: getImageBufferData

import org.lwjgl.BufferUtils; //导入方法依赖的package包/类
/**
 * @see org.newdawn.slick.opengl.ImageData#getImageBufferData()
 */
public ByteBuffer getImageBufferData() {
	return BufferUtils.createByteBuffer(getTexWidth() * getTexHeight() * 4);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:7,代码来源:EmptyImageData.java

示例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;
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:7,代码来源:Util.java

示例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;
}
 
开发者ID:LapisSea,项目名称:OpenGL-Bullet-engine,代码行数:44,代码来源:TextureLoader.java


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