當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferUtils類代碼示例

本文整理匯總了Java中org.lwjgl.BufferUtils的典型用法代碼示例。如果您正苦於以下問題:Java BufferUtils類的具體用法?Java BufferUtils怎麽用?Java BufferUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BufferUtils類屬於org.lwjgl包,在下文中一共展示了BufferUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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:j-dong,項目名稱:trashjam2017,代碼行數:21,代碼來源:AppletGameContainer.java

示例2: 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:j-dong,項目名稱:trashjam2017,代碼行數:21,代碼來源:AppGameContainer.java

示例3: GUILabel

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * Full constructor of a Label
 * @param text (String) : the text to print
 * @param xC (float) : the x coordonnate of the frame where start printing the Label (upper left corner)
 * @param yC (float) : the y coordonnate of the frame where start printing the Label (upper left corner)
 * @param color (java.awt.Color) : the Color you wish for the text
 * @param font (String) : the font (i.e. "Arial" or "Times new roman")
 * @param size (int) : the font size
 */
public GUILabel(String text, int xC, int yC, Color color, String font, int size){
	super(xC,yC);
	this.font = font;
	this.color = color;
	this.text = text;
	this.size = size;
	if(this.texture != null)this.texture.destroy();
	this.texture = Texture.loadFont(text,color,font,size);
	super.width = this.texture.width;
	super.height = this.texture.height;
	this.vbo = GL15.glGenBuffers();
	float[] a = new float[]{
			0,0,        0.0f,0.0f,
			1,0,         1.0f,0.0f,
			1,1,          1.0f,1.0f,
			0,1,         0.0f,1.0f
	};
	FloatBuffer buff = BufferUtils.createFloatBuffer(a.length);
	buff.put(a).flip();
	this.numberOfVertices = a.length/(2+2);

	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
	GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
 
開發者ID:mrdev023,項目名稱:Global-Gam-Jam-2017,代碼行數:35,代碼來源:GUILabel.java

示例4: fetchAttribs

import org.lwjgl.BufferUtils; //導入依賴的package包/類
private Attribute[] fetchAttribs()
{
	int len = GL20.glGetProgrami(this.handle, GL20.GL_ACTIVE_ATTRIBUTES);
	int strlen = GL20.glGetProgrami(this.handle, GL20.GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);

	Attribute[] attribs = new Attribute[len];

	IntBuffer sizeBuffer = BufferUtils.createIntBuffer(1);
	IntBuffer typeBuffer = BufferUtils.createIntBuffer(1);
	for(int i = 0; i < attribs.length; ++i)
	{
		String name = GL20.glGetActiveAttrib(this.handle, i, strlen, sizeBuffer, typeBuffer);
		int location = GL20.glGetAttribLocation(this.handle, name);
		attribs[i] = new Attribute(this, name, typeBuffer.get(), location);

		typeBuffer.flip();
	}

	return attribs;
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:21,代碼來源:Program.java

示例5: renderGL

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * Render the GL scene, this isn't efficient and if you know 
 * OpenGL I'm assuming you can see why. If not, you probably
 * don't want to use this feature anyway
 */
public void renderGL() {		
	FloatBuffer pos = BufferUtils.createFloatBuffer(4);
	pos.put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}).flip();
	FloatBuffer red = BufferUtils.createFloatBuffer(4);
	red.put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}).flip();

	GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
	GL11.glEnable(GL11.GL_LIGHT0);

	GL11.glEnable(GL11.GL_CULL_FACE);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_LIGHTING);
	
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	float h = (float) 600 / (float) 800;
	GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();	
	GL11.glTranslatef(0.0f, 0.0f, -40.0f);	
	GL11.glRotatef(rot,0,1,1);		
	
	GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);
	gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
}
 
開發者ID:IngSW-unipv,項目名稱:Progetto-C,代碼行數:31,代碼來源:SlickCallableTest.java

示例6: ShaderUniform

import org.lwjgl.BufferUtils; //導入依賴的package包/類
public ShaderUniform(String name, int type, int count, ShaderManager manager)
{
    this.shaderName = name;
    this.uniformCount = count;
    this.uniformType = type;
    this.shaderManager = manager;

    if (type <= 3)
    {
        this.uniformIntBuffer = BufferUtils.createIntBuffer(count);
        this.uniformFloatBuffer = null;
    }
    else
    {
        this.uniformIntBuffer = null;
        this.uniformFloatBuffer = BufferUtils.createFloatBuffer(count);
    }

    this.uniformLocation = -1;
    this.markDirty();
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:22,代碼來源:ShaderUniform.java

示例7: 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

示例8: cleanUpSource

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * Clean up the buffers applied to the sound source
 */
private void cleanUpSource() {
	SoundStore store = SoundStore.get();
	
	AL10.alSourceStop(store.getSource(0));
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	int queued = AL10.alGetSourcei(store.getSource(0), AL10.AL_BUFFERS_QUEUED);
	
	while (queued > 0)
	{
		AL10.alSourceUnqueueBuffers(store.getSource(0), buffer);
		queued--;
	}
	
	AL10.alSourcei(store.getSource(0), AL10.AL_BUFFER, 0);
}
 
開發者ID:imaTowan,項目名稱:Towan,代碼行數:19,代碼來源:StreamSound.java

示例9: Model

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * Creates the buffers and puts the data inside
 *
 * @param vertices the edges of the pinball
 */
Model(double[] vertices) {
    draw_count = vertices.length / 3;
  
    buffer = BufferUtils.createDoubleBuffer(vertices.length);
    buffer.put(vertices);
    buffer.flip();

    vao_id = glGenVertexArrays();
    glBindVertexArray(vao_id);

    vbo_id = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
    glBufferData(GL_ARRAY_BUFFER, buffer, GL_DYNAMIC_DRAW);

    glVertexAttribPointer(0, 3, GL_DOUBLE, false, 0, 0);
    glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
}
 
開發者ID:TauOmicronMu,項目名稱:TeamProject,代碼行數:26,代碼來源:Model.java

示例10: Track

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * (Use this as the default!)
 * Creates a new Track from the wav file at filepath, with a static source at the default location (0,0,0)
 * and default gain (1.0f) and pitch (1.0f).
 * @param filepath The path to the wav file to load in.
 */
public Track(String filepath) {
    buffer = BufferUtils.createIntBuffer(1);
    source = BufferUtils.createIntBuffer(1);

    /**
     * Set default values for the source, gain and pitch:
     *     sourcePos : 0.0f, 0.0f, 0.0f
     *     sourceVel : 0.0f, 0.0f, 0.0f
     *     gain      : 1.0f
     *     pitch     : 1.0f
     */
    sourcePos = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f}).rewind();
    sourceVel = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f}).rewind();
    gain = 1.0f;
    pitch = 1.0f;

    loadALData(filepath);
}
 
開發者ID:TauOmicronMu,項目名稱:TeamProject,代碼行數:25,代碼來源:AudioEngine.java

示例11: 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

示例12: 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:SkidJava,項目名稱:BaseClient,代碼行數:29,代碼來源:Shaders.java

示例13: glGetClipPlanef

import org.lwjgl.BufferUtils; //導入依賴的package包/類
@Override
public void glGetClipPlanef(int pname, FloatBuffer eqn) {
    DoubleBuffer buffer = BufferUtils.createDoubleBuffer(eqn.capacity());
    for (float f : eqn.array()) {
        buffer.put(f);
    }
    GL11.glGetClipPlane(pname, buffer);
}
 
開發者ID:dmitrykolesnikovich,項目名稱:featurea,代碼行數:9,代碼來源:OpenGLImpl.java

示例14: removeBuffers

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * Clean up the buffers applied to the sound source
 */
private void removeBuffers() {
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	int queued = AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED);
	
	while (queued > 0)
	{
		AL10.alSourceUnqueueBuffers(source, buffer);
		queued--;
	}
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:14,代碼來源:OpenALStreamPlayer.java

示例15: init

import org.lwjgl.BufferUtils; //導入依賴的package包/類
/**
 * Initialise the FBO that will be used to render to
 * 
 * @throws SlickException
 */
private void init() throws SlickException {
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	EXTFramebufferObject.glGenFramebuffersEXT(buffer); 
	FBO = buffer.get();

	// for some reason FBOs won't work on textures unless you've absolutely just
	// created them.
	try {
		Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());
		
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO);
		EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 
													   EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
													   GL11.GL_TEXTURE_2D, tex.getTextureID(), 0);
		
		completeCheck();
		unbind();
		
		// Clear our destination area before using it
		clear();
		flush();
		
		// keep hold of the original content
		drawImage(image, 0, 0);
		image.setTexture(tex);
		
	} catch (Exception e) {
		throw new SlickException("Failed to create new texture for FBO");
	}
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:36,代碼來源:FBOGraphics.java


注:本文中的org.lwjgl.BufferUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。