org.lwjgl.opengl.EXTFramebufferObject Java Examples

The following examples show how to use org.lwjgl.opengl.EXTFramebufferObject. 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 File: OutlineUtils.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets up the FBO with depth and stencil
 *
 * @param fbo Framebuffer
 */
private static void setupFBO(final Framebuffer fbo) {
    // Deletes old render buffer extensions such as depth
    // Args: Render Buffer ID
    EXTFramebufferObject.glDeleteRenderbuffersEXT(fbo.depthBuffer);
    // Generates a new render buffer ID for the depth and stencil extension
    final int stencil_depth_buffer_ID = EXTFramebufferObject.glGenRenderbuffersEXT();
    // Binds new render buffer by ID
    // Args: Target (GL_RENDERBUFFER_EXT), ID
    EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, stencil_depth_buffer_ID);
    // Adds the depth and stencil extension
    // Args: Target (GL_RENDERBUFFER_EXT), Extension (GL_DEPTH_STENCIL_EXT),
    // Width, Height
    EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, EXTPackedDepthStencil.GL_DEPTH_STENCIL_EXT, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
    // Adds the stencil attachment
    // Args: Target (GL_FRAMEBUFFER_EXT), Attachment
    // (GL_STENCIL_ATTACHMENT_EXT), Target (GL_RENDERBUFFER_EXT), ID
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, stencil_depth_buffer_ID);
    // Adds the depth attachment
    // Args: Target (GL_FRAMEBUFFER_EXT), Attachment
    // (GL_DEPTH_ATTACHMENT_EXT), Target (GL_RENDERBUFFER_EXT), ID
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, stencil_depth_buffer_ID);
}
 
Example #2
Source File: Rendertarget.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a Rendertarget with a Texture that it renders the color buffer in
 * and a renderbuffer that it renders the depth to.
 * @param width the width
 * @param height the height
 * @return the newly created Rendertarget instance
*/
public static Rendertarget createRTTFramebuffer(int width, int height) {
	int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
	int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
	Rendertarget buffer = new Rendertarget(width,height);
	buffer.bind();

	int fboTexture = buffer.textureID;
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null);
	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);

	EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);
	EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height);
	EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);

	EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture);
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer);

	return buffer;
}
 
Example #3
Source File: CurveRenderState.java    From opsu with 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.r));
			buff.put((byte) (255 * col.g));
			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);
		ContextCapabilities capabilities = GLContext.getCapabilities();
		if (capabilities.OpenGL30) {
			GL30.glGenerateMipmap(GL11.GL_TEXTURE_1D);
		} else if (capabilities.GL_EXT_framebuffer_object) {
			EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
		} else {
			GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
		}
	}
}
 
Example #4
Source File: CurveRenderState.java    From opsu-dance with 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 #5
Source File: LegacyCurveRenderState.java    From opsu with 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_EXPERIMENTAL.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.r));
			buff.put((byte) (255 * col.g));
			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 #6
Source File: FrameBufferContainer.java    From LookingGlass with GNU General Public License v3.0 6 votes vote down vote up
private void allocateFrameBuffer() {
	if (this.framebuffer != 0) return;

	this.framebuffer = EXTFramebufferObject.glGenFramebuffersEXT(); //Release via: EXTFramebufferObject.glDeleteFramebuffersEXT(framebuffer);
	this.depthBuffer = EXTFramebufferObject.glGenRenderbuffersEXT(); //Release via: EXTFramebufferObject.glDeleteRenderbuffersEXT(depthBuffer);

	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, this.framebuffer);

	EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer);
	if (MinecraftForgeClient.getStencilBits() == 0) EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, width, height);
	else EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, org.lwjgl.opengl.EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width, height);

	EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer);
	if (MinecraftForgeClient.getStencilBits() != 0) EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer);

	this.texture = GL11.glGenTextures(); //Release via: GL11.glDeleteTextures(colorTexture);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texture);
	GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_INT, (java.nio.ByteBuffer) null);
	EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, this.texture, 0);

	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
}
 
Example #7
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a Rendertarget with a Texture that it renders the color buffer in
 * and a renderbuffer that it renders the depth to.
 * @param width the width
 * @param height the height
 * @return the newly created Rendertarget instance
*/
public static Rendertarget createRTTFramebuffer(int width, int height) {
	int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
	int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
	Rendertarget buffer = new Rendertarget(width,height);
	buffer.bind();

	int fboTexture = buffer.textureID;
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null);
	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);

	EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);
	EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height);
	EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);

	EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture);
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer);

	return buffer;
}
 
Example #8
Source File: Rendertarget.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new FBO.
 * @param width the width
 * @param height the height
 */
private Rendertarget(int width, int height) {
	this.width = width;
	this.height = height;
	fboID = EXTFramebufferObject.glGenFramebuffersEXT();
	vboID = GL15.glGenBuffers();
	textureID = GL11.glGenTextures();
	depthBufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
}
 
Example #9
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.Graphics#destroy()
 */
public void destroy() {
	super.destroy();

	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	buffer.put(FBO);
	buffer.flip();
	
	EXTFramebufferObject.glDeleteFramebuffersEXT(buffer);
	valid = false;
}
 
Example #10
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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");
	}
}
 
Example #11
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check the FBO for completeness as shown in the LWJGL tutorial
 * 
 * @throws SlickException Indicates an incomplete FBO
 */
private void completeCheck() throws SlickException {
	int framebuffer = EXTFramebufferObject.glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT); 
	switch ( framebuffer ) {
		case EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT:
			break;
		case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
			throw new SlickException( "FrameBuffer: " + FBO
					+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT exception" );
		case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
			throw new SlickException( "FrameBuffer: " + FBO
					+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT exception" );
		case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
			throw new SlickException( "FrameBuffer: " + FBO
					+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT exception" );
		case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
			throw new SlickException( "FrameBuffer: " + FBO
					+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT exception" );
		case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
			throw new SlickException( "FrameBuffer: " + FBO
					+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT exception" );
		case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
			throw new SlickException( "FrameBuffer: " + FBO
					+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT exception" );
		default:
			throw new SlickException( "Unexpected reply from glCheckFramebufferStatusEXT: " + framebuffer);
	}
}
 
Example #12
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Destroy the OpenGL objects associated with this Rendertarget. Do not try
 * to use this rendertarget with OpenGL after calling this method.
 */
public void destroyRTT() {
	EXTFramebufferObject.glDeleteFramebuffersEXT(fboID);
	EXTFramebufferObject.glDeleteRenderbuffersEXT(depthBufferID);
	GL11.glDeleteTextures(textureID);
	GL15.glDeleteBuffers(vboID);
}
 
Example #13
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new FBO.
 * @param width the width
 * @param height the height
 */
private Rendertarget(int width, int height) {
	this.width = width;
	this.height = height;
	fboID = EXTFramebufferObject.glGenFramebuffersEXT();
	vboID = GL15.glGenBuffers();
	textureID = GL11.glGenTextures();
	depthBufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
}
 
Example #14
Source File: Rendertarget.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Destroy the OpenGL objects associated with this Rendertarget. Do not try
 * to use this rendertarget with OpenGL after calling this method.
 */
public void destroyRTT() {
	EXTFramebufferObject.glDeleteFramebuffersEXT(fboID);
	EXTFramebufferObject.glDeleteRenderbuffersEXT(depthBufferID);
	GL11.glDeleteTextures(textureID);
	GL15.glDeleteBuffers(vboID);
}
 
Example #15
Source File: FramebufferTextureRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private void deleteBuffers() {
	IntBuffer tmp = BufferUtils.createIntBuffer(4);
	tmp.put(0, fb_id);
	EXTFramebufferObject.glDeleteFramebuffersEXT(tmp);
	tmp.put(0, rb_id);
	GL11.glDeleteTextures(tmp);
}
 
Example #16
Source File: FrameBufferContainer.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void freeFrameBuffer() {
	try {
		if (this.texture != 0) GL11.glDeleteTextures(this.texture);
		this.texture = 0;
		if (depthBuffer != 0) EXTFramebufferObject.glDeleteRenderbuffersEXT(depthBuffer);
		depthBuffer = 0;
		if (this.framebuffer != 0) EXTFramebufferObject.glDeleteFramebuffersEXT(this.framebuffer);
		this.framebuffer = 0;
	} catch (Exception e) {
		// Just in case, we make sure we don't crash. Because crashing is bad.
		LoggerUtils.error("Error while cleaning up a world view frame buffer.");
	}
}
 
Example #17
Source File: FramebufferRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private void deleteBuffers() {
	IntBuffer tmp = BufferUtils.createIntBuffer(4);
	tmp.put(0, fb_id);
	EXTFramebufferObject.glDeleteFramebuffersEXT(tmp);
	tmp.put(0, rb_id);
	EXTFramebufferObject.glDeleteRenderbuffersEXT(tmp);
}
 
Example #18
Source File: LwjglGLFboEXT.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glGenFramebuffersEXT(final IntBuffer frameBuffers) {
    checkLimit(frameBuffers);
    EXTFramebufferObject.glGenFramebuffersEXT(frameBuffers);
}
 
Example #19
Source File: LwjglGLFboEXT.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glFramebufferTexture2DEXT(final int target, final int attachment, final int texTarget,
                                      final int texture, final int level) {
    EXTFramebufferObject.glFramebufferTexture2DEXT(target, attachment, texTarget, texture, level);
}
 
Example #20
Source File: LwjglGLFboEXT.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glGenRenderbuffersEXT(final IntBuffer renderBuffers) {
    checkLimit(renderBuffers);
    EXTFramebufferObject.glGenRenderbuffersEXT(renderBuffers);
}
 
Example #21
Source File: LwjglGLFboEXT.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glGenerateMipmapEXT(final int target) {
    EXTFramebufferObject.glGenerateMipmapEXT(target);
}
 
Example #22
Source File: LwjglGLFboEXT.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glRenderbufferStorageEXT(final int target, final int internalFormat, final int width,
                                     final int height) {
    EXTFramebufferObject.glRenderbufferStorageEXT(target, internalFormat, width, height);
}
 
Example #23
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Bind this rendertarget as the primary framebuffer.
 */
public void bind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fboID);
}
 
Example #24
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Bind the default framebuffer.
 */
public static void unbind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
}
 
Example #25
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw a curve to the screen that's tinted with `color`. The first time
 * this is called this caches the image result of the curve and on subsequent
 * runs it just draws the cached copy to the screen.
 * @param color tint of the curve
 * @param borderColor the curve border color
 * @param from index to draw from
 * @param to index to draw to (exclusive)
 */
public void draw(Color color, Color borderColor, int from, int to) {
	float alpha = color.a;

	if (fbo == null)
		initFBO();

	if (lastPointDrawn != to || firstPointDrawn != from) {
		int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
		int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
		//glGetInteger requires a buffer of size 16, even though just 4
		//values are returned in this specific case
		IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
		GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
		GL11.glViewport(0, 0, fbo.width, fbo.height);
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		this.renderCurve(color, borderColor, from, to, firstPointDrawn != from);
		lastPointDrawn = to;
		firstPointDrawn = from;
		color.a = 1f;

		GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
		GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
	}

	// draw a fullscreen quad with the texture that contains the curve
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_TEXTURE_1D);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
	GL11.glBegin(GL11.GL_QUADS);
	GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha);
	GL11.glTexCoord2f(1.0f, 1.0f);
	GL11.glVertex2i(fbo.width, 0);
	GL11.glTexCoord2f(0.0f, 1.0f);
	GL11.glVertex2i(0, 0);
	GL11.glTexCoord2f(0.0f, 0.0f);
	GL11.glVertex2i(0, fbo.height);
	GL11.glTexCoord2f(1.0f, 0.0f);
	GL11.glVertex2i(fbo.width, fbo.height);
	GL11.glEnd();
}
 
Example #26
Source File: RenderUtils.java    From LookingGlass with GNU General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public final static void renderWorldToTexture(float renderTime, int framebuffer, int width, int height) {
	if (framebuffer == 0) return;
	Minecraft mc = Minecraft.getMinecraft();
	if (mc.skipRenderWorld) return;
	EntityRenderer entityRenderer = mc.entityRenderer;

	//Backup current render settings
	int heightBackup = mc.displayHeight;
	int widthBackup = mc.displayWidth;

	int thirdPersonBackup = mc.gameSettings.thirdPersonView;
	boolean hideGuiBackup = mc.gameSettings.hideGUI;
	int particleBackup = mc.gameSettings.particleSetting;
	boolean anaglyphBackup = mc.gameSettings.anaglyph;
	int renderDistanceBackup = mc.gameSettings.renderDistanceChunks;
	float FOVbackup = mc.gameSettings.fovSetting;

	//Render world
	try {
		//Set all of the render setting to work on the proxy world
		mc.displayHeight = height;
		mc.displayWidth = width;

		//TODO: params (FOV, Particle setting, renderDistance)
		mc.gameSettings.thirdPersonView = 0;
		mc.gameSettings.hideGUI = true;
		//mc.gameSettings.particleSetting = ;
		mc.gameSettings.anaglyph = false;
		//mc.gameSettings.renderDistanceChunks = ;  
		//mc.gameSettings.fovSetting = ;

		//Set gl options
		GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
		GL11.glClearColor(1.0f, 0.0f, 0.0f, 0.5f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

		int i1 = mc.gameSettings.limitFramerate;
		if (mc.isFramerateLimitBelowMax()) {
			entityRenderer.renderWorld(renderTime, (1000000000 / i1));
		} else {
			entityRenderer.renderWorld(renderTime, 0L);
		}
	} catch (Exception e) {
		try {
			//Clean up the tessellator, just in case.
			Tessellator.instance.draw();
		} catch (Exception e2) {
			//It might throw an exception, but that just means we didn't need to clean it up (this time)
		}
		throw new RuntimeException("Error while rendering proxy world", e);
	} finally {
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);

		GL11.glViewport(0, 0, widthBackup, heightBackup);
		GL11.glLoadIdentity();

		mc.gameSettings.thirdPersonView = thirdPersonBackup;
		mc.gameSettings.hideGUI = hideGuiBackup;
		mc.gameSettings.particleSetting = particleBackup;
		mc.gameSettings.anaglyph = anaglyphBackup;
		mc.gameSettings.renderDistanceChunks = renderDistanceBackup;
		mc.gameSettings.fovSetting = FOVbackup;

		mc.displayHeight = heightBackup;
		mc.displayWidth = widthBackup;
	}
}
 
Example #27
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw a curve to the screen that's tinted with `color`. The first time
 * this is called this caches the image result of the curve and on subsequent
 * runs it just draws the cached copy to the screen.
 * @param color tint of the curve
 * @param borderColor the curve border color
 * @param from index to draw from
 * @param to index to draw to (exclusive)
 */
public void draw(Color color, Color borderColor, int from, int to) {
	float alpha = color.a;

	if (fbo == null) {
		// this should not be null, but issue #106 claims it is possible, at least 3 people had this...
		// debugging shows that the draw was called after discardGeometry was, which does not really make sense
		initFBO();
	}

	if (lastPointDrawn != to || firstPointDrawn != from) {
		int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
		int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
		//glGetInteger requires a buffer of size 16, even though just 4
		//values are returned in this specific case
		IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
		GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
		GL11.glViewport(0, 0, fbo.width, fbo.height);
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		this.renderCurve(color, borderColor, from, to, firstPointDrawn != from);
		lastPointDrawn = to;
		firstPointDrawn = from;
		color.a = 1f;

		GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
		GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
	}

	// draw a fullscreen quad with the texture that contains the curve
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_TEXTURE_1D);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
	GL11.glBegin(GL11.GL_QUADS);
	GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha);
	GL11.glTexCoord2f(1.0f, 1.0f);
	GL11.glVertex2i(fbo.width, 0);
	GL11.glTexCoord2f(0.0f, 1.0f);
	GL11.glVertex2i(0, 0);
	GL11.glTexCoord2f(0.0f, 0.0f);
	GL11.glVertex2i(0, fbo.height);
	GL11.glTexCoord2f(1.0f, 0.0f);
	GL11.glVertex2i(fbo.width, fbo.height);
	GL11.glEnd();
}
 
Example #28
Source File: Rendertarget.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Bind the default framebuffer.
 */
public static void unbind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
}
 
Example #29
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Bind to the FBO created
 */
private void bind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO);
	GL11.glReadBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);
}
 
Example #30
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Unbind from the FBO created
 */
private void unbind() {
	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
	GL11.glReadBuffer(GL11.GL_BACK); 
}