Created
December 28, 2013 00:50
-
-
Save anonymous/8154703 to your computer and use it in GitHub Desktop.
The class that creates the FBO and the custom Renderer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kamikaze.opengl; | |
import static org.lwjgl.opengl.GL11.*; | |
import net.minecraft.block.Block; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.renderer.OpenGlHelper; | |
import net.minecraft.client.renderer.Tessellator; | |
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.MathHelper; | |
import net.minecraft.world.World; | |
public class RendererOpenGL extends TileEntitySpecialRenderer | |
{ | |
@Override | |
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) | |
{ | |
glPushMatrix(); | |
glTranslatef((float) x, (float) y, (float) z); | |
TileEntityOpenGL tileEnt = (TileEntityOpenGL) tileentity; | |
if (!tileEnt.renderScreen.initialized) | |
{ | |
tileEnt.renderScreen.init(); | |
System.out.println("init"); | |
} | |
tileEnt.renderScreen.render(); | |
renderBlock(tileEnt, tileEnt.worldObj, tileEnt.xCoord, tileEnt.yCoord, tileEnt.zCoord, OpenGL.openglBlock); | |
glPopMatrix(); | |
} | |
public void renderBlock(TileEntityOpenGL tileentity, World world, int x, int y, int z, Block block) | |
{ | |
//glTranslatef((float) x,(float) y,(float) z); | |
Tessellator tessellator = Tessellator.instance; | |
float light = world.getBlockLightValue(x, y, z); | |
int l = world.getLightBrightnessForSkyBlocks(x, y, z, 0); | |
int l1 = l % 65536; | |
int l2 = l / 65536; | |
//tessellator.setColorOpaque_F(light, light, light); | |
//OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)l1, (float)l2); | |
int dir = world.getBlockMetadata(x, y, z); | |
glPushMatrix(); | |
glTranslatef(0.5f, 0, 0.5f); | |
glRotatef(dir * (-90F), 0f, 1f, 0f); | |
glTranslatef(-0.5f, 0, -0.5f); | |
glEnable(GL_TEXTURE_2D); | |
glDisable(GL_LIGHTING); | |
glBindTexture(GL_TEXTURE_2D, tileentity.renderScreen.texID); | |
//glBindTexture(GL_TEXTURE_2D, 10); | |
//System.out.println(tileentity.renderScreen.texID); | |
glColor3f(1f, 1f, 1f); | |
glBegin(GL_QUADS); | |
glVertex3f(1f, 0f, 0f); | |
glVertex3f(0f, 0f, 0f); | |
glVertex3f(0f, 1f, 0f); | |
glVertex3f(1f, 1f, 0f); | |
glEnd(); | |
//glDisable(GL_TEXTURE_2D); | |
glPopMatrix(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kamikaze.opengl; | |
import static org.lwjgl.opengl.EXTFramebufferObject.*; | |
import static org.lwjgl.opengl.GL11.*; | |
import static org.lwjgl.opengl.GL14.*; | |
import java.nio.ByteBuffer; | |
import org.lwjgl.opengl.Display; | |
import org.lwjgl.opengl.GLContext; | |
import org.lwjgl.util.glu.GLU; | |
public class RenderScreen | |
{ | |
public int fboID; | |
public int texID; | |
public int renderBufferID; | |
public int width, height; | |
public boolean initialized = false; | |
public RenderScreen(int width, int height) | |
{ | |
this.width = width; | |
this.height = height; | |
} | |
public void init() | |
{ | |
if (!GLContext.getCapabilities().GL_EXT_framebuffer_object) | |
{ | |
System.out.println("FBO is not supported"); | |
//return; | |
} | |
this.fboID = glGenFramebuffersEXT(); | |
this.texID = glGenTextures(); | |
this.renderBufferID = glGenRenderbuffersEXT(); | |
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID); //Binds the fbo | |
//Texture | |
glBindTexture(GL_TEXTURE_2D, this.texID); | |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, this.width, this.height, 0, GL_RGBA, GL_INT, (ByteBuffer) null); | |
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this.texID, 0); | |
//RenderBuffer | |
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, this.renderBufferID); | |
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, this.width, this.height); | |
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, | |
this.renderBufferID); | |
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | |
this.initialized = true; | |
} | |
public void render() | |
{ | |
glPushMatrix(); | |
glViewport(0, 0, this.width, this.height); //Texture width & height | |
glBindTexture(GL_TEXTURE_2D, 0); | |
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this.fboID); | |
glClearColor((float) (Math.sin(System.currentTimeMillis() / 100) + 1) / 2, | |
(float) (Math.cos(System.currentTimeMillis() / 100) + 1) / 2, (float) | |
(Math.sin(System.currentTimeMillis() / 500) + 1) / 2, 1f); | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_MODELVIEW); | |
//glLoadIdentity(); | |
glColor4f(1f, 1f, 0, 0f); | |
glBegin(GL_QUADS); | |
glVertex3f(0.8f, 0.2f, 1f); | |
glVertex3f(0.2f, 0.2f, 1f); | |
glVertex3f(0.2f, 0.8f, 1f); | |
glVertex3f(0.8f, 0.8f, 1f); | |
glEnd(); | |
glRotatef(180, 0, 1f, 0); | |
//glFlush(); | |
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | |
glViewport(0, 0, Display.getWidth(), Display.getHeight()); | |
glPopMatrix(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment