-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweaked FBO a bit to support different texture sizes.
Billboard entity renderer will use FBO-based font texture.
- Loading branch information
1 parent
ceeec29
commit 887de88
Showing
11 changed files
with
258 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
93 changes: 93 additions & 0 deletions
93
...sProject3dClient/src/com/nuclearunicorn/negame/client/render/BillboardEntityRenderer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.nuclearunicorn.negame.client.render; | ||
|
||
|
||
import com.nuclearunicorn.libroguelike.game.world.WorldView; | ||
import com.nuclearunicorn.libroguelike.render.EntityRenderer; | ||
import com.nuclearunicorn.libroguelike.render.Render; | ||
import com.nuclearunicorn.libroguelike.render.WindowRender; | ||
import com.nuclearunicorn.libroguelike.render.overlay.OverlaySystem; | ||
import com.nuclearunicorn.negame.client.render.utils.FBO; | ||
import org.lwjgl.opengl.*; | ||
import org.newdawn.slick.Color; | ||
|
||
public class BillboardEntityRenderer extends EntityRenderer { | ||
|
||
private static FBO fbo = new FBO(32, 32); //smalllll texture to fit ascii characters | ||
|
||
@Override | ||
public void render(){ | ||
|
||
|
||
//OverlaySystem.ttf.drawString(0,0, "@", Color.red); | ||
fbo.render_begin(); | ||
|
||
GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | ||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); | ||
|
||
OverlaySystem.ttf.drawString(4, 8, "@", Color.white); | ||
|
||
fbo.render_end(); | ||
|
||
WindowRender.set3DMode(); | ||
TilesetVoxelRenderer.camera.setMatrix(); | ||
|
||
int tileHeight = WorldView.getYOffset(ent.tile); | ||
|
||
|
||
//point sprites | ||
|
||
GL11.glEnable(GL11.GL_BLEND); | ||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); | ||
GL11.glEnable(GL20.GL_POINT_SPRITE); | ||
GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE); | ||
|
||
//----------------------------------------------------------------- | ||
/* | ||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | ||
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); | ||
glEnable(GL_POINT_SPRITE); | ||
glActiveTexture(GL_TEXTURE0); | ||
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); | ||
//Activate shader program here | ||
// Send pointSize to shader program | ||
glBegin(GL_POINTS); | ||
// Render points here | ||
glVertex3f(...); | ||
glEnd(GL_POINTS); | ||
*/ | ||
//----------------------------------------------------------------- | ||
|
||
GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE); //_ARB? | ||
GL11.glHint(GL11.GL_POINT_SMOOTH_HINT, GL11.GL_NICEST); | ||
GL11.glEnable(GL20.GL_POINT_SPRITE); | ||
|
||
//Render.bind_texture("some texture"); | ||
|
||
|
||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.fbo_texture_id); | ||
|
||
|
||
|
||
GL11.glTexEnvi(GL20.GL_POINT_SPRITE, GL20.GL_COORD_REPLACE, GL11.GL_TRUE); | ||
|
||
//Replace me with shader | ||
GL11.glPointSize(tileHeight/2.0f); | ||
|
||
|
||
GL11.glEnable(GL11.GL_POINT_SMOOTH); | ||
GL11.glBegin(GL11.GL_POINTS); | ||
|
||
GL11.glColor3f(1.0f, 1.0f, 1.0f); | ||
//GL11.gl | ||
|
||
//GL20.glUniform1f(20, 20f); | ||
GL11.glVertex3f(ent.origin.getX() * 1.00005f, (tileHeight + 20 ) * 0.05f, ent.origin.getY() * 1.00005f); | ||
|
||
|
||
GL11.glEnd(); | ||
|
||
WindowRender.set2DMode(); | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
NamesProject3dClient/src/com/nuclearunicorn/negame/client/render/utils/FBO.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.nuclearunicorn.negame.client.render.utils; | ||
|
||
import org.lwjgl.opengl.*; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.nio.IntBuffer; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.lwjgl.BufferUtils; | ||
import org.lwjgl.opengl.EXTFramebufferObject; | ||
import org.lwjgl.opengl.GL11; | ||
import org.lwjgl.opengl.GLContext; | ||
|
||
import static org.lwjgl.opengl.EXTFramebufferObject.*; | ||
import static org.lwjgl.opengl.GL11.*; | ||
import static org.lwjgl.opengl.GL12.*; | ||
import static org.lwjgl.opengl.GL14.*; | ||
|
||
/** | ||
* | ||
* @author Administrator | ||
*/ | ||
public class FBO { | ||
|
||
/* | ||
* Sometimes fbo minimap rendering can result in buggy blinking screen. | ||
* In such case we must disable fbo minimap directly from the config file | ||
*/ | ||
|
||
public static boolean fbo_enabled = false; | ||
private static String use_fbo = null; | ||
|
||
static | ||
{ | ||
/*try { | ||
Properties p = new Properties(); | ||
p.load(new FileInputStream("client.ini")); | ||
use_fbo = p.getProperty("fbo_enabled"); | ||
if (use_fbo == null){ | ||
use_fbo = "1"; | ||
} | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
fbo_enabled = GLContext.getCapabilities().GL_EXT_framebuffer_object && (!use_fbo.equals("0")); | ||
*/ | ||
fbo_enabled = GLContext.getCapabilities().GL_EXT_framebuffer_object; | ||
} | ||
|
||
int fbo_id; | ||
public int fbo_texture_id; | ||
|
||
private int textureW; | ||
private int textureH; | ||
|
||
public FBO(int textureW, int textureH){ | ||
|
||
this.textureW = textureW; | ||
this.textureH = textureH; | ||
|
||
if (fbo_enabled){ | ||
//create texture | ||
fbo_texture_id = GL11.glGenTextures(); | ||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo_texture_id); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); | ||
|
||
glTexImage2D(GL_TEXTURE_2D, 0, | ||
GL_RGBA8, textureW, textureH, 0, GL_RGBA, | ||
GL_UNSIGNED_BYTE, (ByteBuffer)null); | ||
|
||
glBindTexture(GL_TEXTURE_2D, 0); | ||
|
||
//now create framebuffer | ||
fbo_id = EXTFramebufferObject.glGenFramebuffersEXT(); | ||
EXTFramebufferObject.glBindFramebufferEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo_id ); | ||
|
||
//attach a texture to FBO collor channel | ||
EXTFramebufferObject.glFramebufferTexture2DEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, | ||
GL11.GL_TEXTURE_2D, fbo_texture_id, 0); | ||
|
||
//------------------------------------------------------------------ | ||
//check FBO status and shit | ||
int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); | ||
if(status != GL_FRAMEBUFFER_COMPLETE_EXT) { | ||
throw new RuntimeException("Unsupported fbo status:"+status); | ||
} | ||
|
||
// switch back to window-system-provided framebuffer | ||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | ||
} | ||
} | ||
|
||
/* | ||
* Prepares FBO for rendering path | ||
*/ | ||
public void render_begin(){ | ||
|
||
EXTFramebufferObject.glBindFramebufferEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo_id ); | ||
|
||
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT | GL_COLOR_BUFFER_BIT | GL_SCISSOR_BIT); | ||
glDisable(GL_SCISSOR_TEST); | ||
glViewport(0, 0, textureW, textureH); | ||
|
||
glMatrixMode(GL_PROJECTION); | ||
glPushMatrix(); | ||
glLoadIdentity(); | ||
glOrtho(0, textureW, textureH, 0, -1.0, 1.0); | ||
glMatrixMode(GL_MODELVIEW); | ||
glPushMatrix(); | ||
glLoadIdentity(); | ||
glDisable(GL_SCISSOR_TEST); | ||
} | ||
|
||
public void render_end(){ | ||
EXTFramebufferObject.glBindFramebufferEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); | ||
|
||
glMatrixMode(GL_PROJECTION); | ||
glPopMatrix(); | ||
glMatrixMode(GL_MODELVIEW); | ||
glPopMatrix(); | ||
glPopAttrib(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
uniform float pointSize; | ||
void main() { | ||
gl_Position = ftransform(); | ||
gl_PointSize = pointSize / gl_Position.w; | ||
} |
This file contains 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