Java Code Examples for org.lwjgl.BufferUtils

The following examples show how to use org.lwjgl.BufferUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: graphicsfuzz   Source File: DesktopComputeJobManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void prepareEnvironment(JsonObject environmentJson) {
  final JsonObject bufferJson = environmentJson.get("buffer").getAsJsonObject();
  final int bufferBinding = bufferJson.get("binding").getAsInt();
  final int[] bufferInput = UniformSetter.getIntArray(bufferJson.get("input").getAsJsonArray());
  final IntBuffer intBufferData = BufferUtils.createIntBuffer(bufferInput.length);
  intBufferData.put(bufferInput);
  intBufferData.flip();
  shaderStorageBufferObject = GL15.glGenBuffers();
  checkError();
  GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject);
  checkError();
  GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER, intBufferData, GL15.GL_STATIC_DRAW);
  checkError();
  GL30.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, bufferBinding, shaderStorageBufferObject);
  checkError();
  numGroups = UniformSetter.getIntArray(environmentJson.get("num_groups").getAsJsonArray());
}
 
Example 2
/**
 * @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(),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);
	}
}
 
Example 3
Source Project: ldparteditor   Source File: Circle.java    License: MIT License 6 votes vote down vote up
public Circle(float r, float g, float b, float dir_x, float dir_y, float dir_z, float radius, float line_width) {
    dir_x = dir_x / 1000f;
    dir_y = dir_y / 1000f;
    dir_z = dir_z / 1000f;
    radius = radius / 1000f;
    this.r = r;
    this.g = g;
    this.b = b;

    rotation = makeRotationDir(new Vector3f(dir_x, dir_y, dir_z));
    matrix = BufferUtils.createFloatBuffer(16);
    rotation.store(matrix);
    matrix.position(0);

    final float step = (float) (Math.PI / 16d);
    float angle = 0f;
    final float radius2 = radius - line_width / 6f;
    for (int i = 0; i < 66; i += 2) {
        circle[i] = (float) (radius * Math.cos(angle));
        circle[i + 1] = (float) (radius * Math.sin(angle));
        circle2[i] = (float) (radius2 * Math.cos(angle));
        circle2[i + 1] = (float) (radius2 * Math.sin(angle));
        angle = angle + step;
    }

}
 
Example 4
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example2.2.vert"), readFromFile("example2.2.frag"));
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(24).put(new float[] { 0.0f, 0.5f, 0.0f, 1.0f,
			0.5f, -0.366f, 0.0f, 1.0f,
			-0.5f, -0.366f, 0.0f, 1.0f,
			1.0f, 0.0f, 0.0f, 1.0f,
			0.0f, 1.0f, 0.0f, 1.0f,
			0.0f, 0.0f, 1.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
}
 
Example 5
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example2.1.vert"), readFromFile("example2.1.frag"));
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.75f, 0.75f, 0.0f, 1.0f,
			0.75f, -0.75f, 0.0f, 1.0f,
			-0.75f, -0.75f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
}
 
Example 6
Source Project: opsu-dance   Source File: CurveRenderState.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.b)); // I know this looks strange...
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
	}
}
 
Example 7
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example3.2.vert"), readFromFile("example3.2.frag"));
	offsetLocation = program.getUniformLocation("offset");
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f,
			0.25f, -0.25f, 0.0f, 1.0f,
			-0.25f, -0.25f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
}
 
Example 8
Source Project: AdvancedRocketry   Source File: ClientDynamicTexture.java    License: MIT License 6 votes vote down vote up
private void init() {
	//create array, every single pixel

	ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL);

	for(int i = 0; i < image.getHeight() * image.getWidth(); i++) {
			buffer.putInt(0x00000000);
	}
	buffer.flip();
	
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId());
	
	//Just clamp to edge
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
	
	//Scale linearly
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
	
	GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
	
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
}
 
Example 9
Source Project: NOVA-Core   Source File: BWItem.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) {
	this.item = item;
	this.meta = meta;
	this.tag = tag;

	components.add(new StaticRenderer())
		.onRender(model -> {
				model.addChild(new CustomModel(self -> {
					Tessellator.instance.draw();
					GL11.glPushMatrix();
					DoubleBuffer buffer = BufferUtils.createDoubleBuffer(4 * 4);
					double[] flatArray = Arrays.stream(self.matrix.getMatrix().getData())
						.flatMapToDouble(Arrays::stream)
						.toArray();
					buffer.put(flatArray);
					buffer.position(0);
					GL11.glMultMatrix(buffer);
					RenderItem.getInstance().doRender(fakeEntity, 0, 0, 0, 0, 0);
					GL11.glPopMatrix();
					Tessellator.instance.startDrawingQuads();
				}));
			}
		);
}
 
Example 10
Source Project: Visage   Source File: Cube.java    License: MIT License 6 votes vote down vote up
@Override
public void render(Renderer renderer) {
	if (tcbo == Integer.MAX_VALUE) {
		if (Visage.trace) Visage.log.finest("Creating texture coord buffer");
		tcbo = glGenBuffers();
		FloatBuffer uv = BufferUtils.createFloatBuffer(texture.u.length+texture.v.length);
		for (int i = 0; i < texture.u.length; i++) {
			uv.put(texture.u[i]);
			uv.put(texture.v[i]);
		}
		uv.flip();
		glBindBuffer(GL_ARRAY_BUFFER, tcbo);
		glBufferData(GL_ARRAY_BUFFER, uv, GL_STATIC_DRAW);
	}
	doRender(renderer, renderer.owner.cubeVbo, tcbo, RenderContext.vertices);
}
 
Example 11
Source Project: WraithEngine   Source File: GLTexture.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Extracts pixel colors from the texture data object and formats them into an
 * RGBA8 byte buffer.
 * 
 * @param textureData
 *     - The texture data containing the color data.
 * @return A formatted byte buffer containing the pixel colors.
 */
private ByteBuffer getPixelData(TextureData textureData)
{
    int pixelCount = textureData.getWidth() * textureData.getHeight();
    ByteBuffer pixels = BufferUtils.createByteBuffer(pixelCount * 4);

    for (int y = 0; y < textureData.getHeight(); y++)
    {
        for (int x = 0; x < textureData.getWidth(); x++)
        {
            int color = textureData.getPixel(x, y);
            pixels.put((byte) ((color >> 16) & 0xFF));
            pixels.put((byte) ((color >> 8) & 0xFF));
            pixels.put((byte) (color & 0xFF));
            pixels.put((byte) ((color >> 24) & 0xFF));
        }
    }

    pixels.flip();
    return pixels;
}
 
Example 12
private void ensureCapacity(int capacity) {
    if (capacity <= buffer.capacity()) {
        return;
    }

    ByteBuffer resized = BufferUtils.createByteBuffer(mathRoundPoT(capacity));

    resized.put(buffer);
    resized.clear();

    buffer = resized;
    address = memAddress(resized);
}
 
Example 13
private void loadTextures() {
	for(int a = 0; a < textures.length; a++)
		textures[a] = glGenTextures();
	
	try {
		PNGDecoder decoder = new PNGDecoder(getClass().getResourceAsStream("example16.1.gamma_ramp.png"));
		ByteBuffer buffer = BufferUtils.createByteBuffer(decoder.getWidth() * decoder.getHeight() * 4);
		decoder.decode(buffer, decoder.getWidth() * 4, Format.RGBA);
		buffer.flip();
		
		glBindTexture(GL_TEXTURE_2D, textures[0]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
		
		glBindTexture(GL_TEXTURE_2D, textures[1]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
		
		glBindTexture(GL_TEXTURE_2D, 0);
	} catch(Exception exc) {
		exc.printStackTrace();
		destroy();
	}
	
	samplerObject = glGenSamplers();
	glSamplerParameteri(samplerObject, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(samplerObject, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(samplerObject, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glSamplerParameteri(samplerObject, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
 
Example 14
/**
 * Get the current graphics context background color
 * 
 * @return The background color of this graphics context
 */
public Color getBackground() {
	predraw();
	FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
	GL.glGetFloat(SGL.GL_COLOR_CLEAR_VALUE, buffer);
	postdraw();

	return new Color(buffer);
}
 
Example 15
Source Project: ure   Source File: USpeaker.java    License: MIT License 5 votes vote down vote up
IntBuffer makePlaySource(float gain) {
    IntBuffer source = BufferUtils.createIntBuffer(1);
    alGenSources(source);
    alSourcef(source.get(0), AL_GAIN, gain);
    alSourcef(source.get(0), AL_REFERENCE_DISTANCE, 2.0f);
    alSourcef(source.get(0), AL_MAX_DISTANCE, (float)config.getVolumeFalloffDistance());
    return source;
}
 
Example 16
/**
    * Play a mod or xm track streamed from the specified location
    * 
    * @param module The moudle to play back
    * @param source The OpenAL source to play the music on
    * @param start True if the music should be started
    * @param loop True if the track should be looped
    */
public void play(Module module, int source, boolean loop, boolean start) {
	this.source = source;
	this.loop = loop;
	this.module = module;
	done = false;
	
	ibxm = new IBXM(48000);
	ibxm.set_module(module);
	songDuration = ibxm.calculate_song_duration();

	if (bufferNames != null) {
		AL10.alSourceStop(source);
		bufferNames.flip();
		AL10.alDeleteBuffers(bufferNames);
	}
	
	bufferNames = BufferUtils.createIntBuffer(2);
	AL10.alGenBuffers(bufferNames);
	remainingBufferCount = 2;
	
	for (int i=0;i<2;i++) {
        stream(bufferNames.get(i));
	}
       AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcef(source, AL10.AL_PITCH, 1.0f);
	AL10.alSourcef(source, AL10.AL_GAIN, 1.0f); 
	
	if (start) {
		AL10.alSourcePlay(source);
	}
}
 
Example 17
Source Project: tribaltrouble   Source File: AudioSource.java    License: GNU General Public License v2.0 5 votes vote down vote up
public AudioSource() {
	IntBuffer source_buffer = BufferUtils.createIntBuffer(1);
	if (AL.isCreated())
		AL10.alGenSources(source_buffer);
	// if alGenSources fails, the source object will be null (default value)
	source = source_buffer;
}
 
Example 18
Source Project: tribaltrouble   Source File: Sky.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final ShortVBO makeSkyFanIndices() {
	int size = subdiv_axis + 2;
	ShortBuffer temp = BufferUtils.createShortBuffer(size);
	temp.put(0, (short)(sky_vertices.capacity()/3 - 1));
	for (int i = 0; i < subdiv_axis; i++) {
	   temp.put(i + 1, (short)((subdiv_height - 1)*subdiv_axis - i - 1));
	}
	temp.put(subdiv_axis + 1, (short)((subdiv_height - 1)*subdiv_axis - 1));
	
	ShortVBO fan_indices = new ShortVBO(ARBBufferObject.GL_STATIC_DRAW_ARB, size);
	temp.rewind();
	fan_indices.put(temp);
	return fan_indices;
}
 
Example 19
Source Project: mini2Dx   Source File: Mini2DxOpenALAudioDevice.java    License: Apache License 2.0 5 votes vote down vote up
public Mini2DxOpenALAudioDevice (Mini2DxOpenALAudio audio, int sampleRate, boolean isMono, int bufferSize, int bufferCount) {
	this.audio = audio;
	channels = isMono ? 1 : 2;
	this.bufferSize = bufferSize;
	this.bufferCount = bufferCount;
	this.format = channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
	this.sampleRate = sampleRate;
	secondsPerBuffer = (float)bufferSize / bytesPerSample / channels / sampleRate;
	tempBuffer = BufferUtils.createByteBuffer(bufferSize);
}
 
Example 20
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.class.getClassLoader().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;
}
 
Example 21
Source Project: ldparteditor   Source File: GLMatrixStack.java    License: MIT License 5 votes vote down vote up
public void glScalef(float x, float y, float z) {

        Matrix4f.scale(new Vector3f(x, y, z), currentMatrix, currentMatrix);

        final FloatBuffer buf = BufferUtils.createFloatBuffer(16);
        currentMatrix.store(buf);
        buf.position(0);

        int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
        GL20.glUniformMatrix4fv(model, false, buf);
    }
 
Example 22
Source Project: jmonkeyengine   Source File: Utils.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TempBuffer() {
    b16 = BufferUtils.createByteBuffer(16);
    b16s = b16.asShortBuffer();
    b16i = b16.asIntBuffer();
    b16l = b16.asLongBuffer();
    b16f = b16.asFloatBuffer();
    b16d = b16.asDoubleBuffer();
}
 
Example 23
Source Project: tribaltrouble   Source File: Test.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final static int createTexture(int width, int height, IntBuffer pixel_data) {
	IntBuffer handle_buffer = BufferUtils.createIntBuffer(1);
	GL11.glGenTextures(handle_buffer);
	int tex_handle = handle_buffer.get(0);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_handle);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL12.GL_UNSIGNED_INT_8_8_8_8, pixel_data);

	return tex_handle;
}
 
Example 24
Source Project: OpenGL-Animation   Source File: SkeletonLoader.java    License: The Unlicense 5 votes vote down vote up
private FloatBuffer convertData(String[] rawData){
	float[] matrixData = new float[16];
	for(int i=0;i<matrixData.length;i++){
		matrixData[i] = Float.parseFloat(rawData[i]);
	}
	FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
	buffer.put(matrixData);
	buffer.flip();
	return buffer;
}
 
Example 25
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param url A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, URL url) {
	this.source = source;
	this.url = url;

	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 26
Source Project: jmonkeyengine   Source File: Utils.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TempBuffer() {
    b16 = BufferUtils.createByteBuffer(16);
    b16s = b16.asShortBuffer();
    b16i = b16.asIntBuffer();
    b16l = b16.asLongBuffer();
    b16f = b16.asFloatBuffer();
    b16d = b16.asDoubleBuffer();
}
 
Example 27
Source Project: ldparteditor   Source File: GLMatrixStack.java    License: MIT License 5 votes vote down vote up
public void glLoadMatrix(Matrix4f m) {
    final FloatBuffer m_buf = BufferUtils.createFloatBuffer(16);
    m.store(m_buf);
    m_buf.position(0);
    currentMatrix = m;

    int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
    GL20.glUniformMatrix4fv(model, false, m_buf);
}
 
Example 28
Source Project: ldparteditor   Source File: GLMatrixStack.java    License: MIT License 5 votes vote down vote up
public void glLoadIdentity() {
    final Matrix4f ID = new Matrix4f();
    Matrix4f.setIdentity(ID);
    final FloatBuffer ID_buf = BufferUtils.createFloatBuffer(16);
    ID.store(ID_buf);
    ID_buf.position(0);
    currentMatrix = ID;

    int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
    GL20.glUniformMatrix4fv(model, false, ID_buf);

    int view = shader.getUniformLocation("view" ); //$NON-NLS-1$
    GL20.glUniformMatrix4fv(view, false, ID_buf);
}
 
Example 29
Source Project: malmo   Source File: TextureHelper.java    License: MIT License 5 votes vote down vote up
public static int loadShader(String filename, int shaderType) throws IOException
{
    int shaderID = -1;
    InputStream stream = MalmoMod.class.getClassLoader().getResourceAsStream(filename);
    if (stream == null)
    {
        System.out.println("Cannot find shader.");
        return -1;
    }
    try
    {
        byte[] abyte = IOUtils.toByteArray((InputStream) (new BufferedInputStream(stream)));
        ByteBuffer bytebuffer = BufferUtils.createByteBuffer(abyte.length);
        bytebuffer.put(abyte);
        bytebuffer.position(0);
        shaderID = OpenGlHelper.glCreateShader(shaderType);
        OpenGlHelper.glShaderSource(shaderID, bytebuffer);
        OpenGlHelper.glCompileShader(shaderID);

        if (OpenGlHelper.glGetShaderi(shaderID, OpenGlHelper.GL_COMPILE_STATUS) == 0)
        {
            String s = StringUtils.trim(OpenGlHelper.glGetShaderInfoLog(shaderID, 32768));
            JsonException jsonexception = new JsonException("Couldn\'t compile shader program: " + s);
            throw jsonexception;
        }
    }
    finally
    {
        IOUtils.closeQuietly(stream);
    }
    return shaderID;
}
 
Example 30
Source Project: malmo   Source File: VideoProducerImplementation.java    License: MIT License 5 votes vote down vote up
@Override
public void prepare(MissionInit missionInit)
{
    this.fbo = new Framebuffer(this.videoParams.getWidth(), this.videoParams.getHeight(), true);
    // Create a buffer for retrieving the depth map, if requested:
    if (this.videoParams.isWantDepth())
        this.depthBuffer = BufferUtils.createFloatBuffer(this.videoParams.getWidth() * this.videoParams.getHeight());
    // Set the requested camera position
    Minecraft.getMinecraft().gameSettings.thirdPersonView = this.videoParams.getViewpoint();
}