|
@@ -8,10 +8,8 @@ import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import org.lwjgl.BufferUtils;
|
|
|
import static org.lwjgl.opengl.GL11.*;
|
|
|
-import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
|
|
|
-import static org.lwjgl.opengl.GL15.glBindBuffer;
|
|
|
+import static org.lwjgl.opengl.GL14.*;
|
|
|
import static org.lwjgl.opengl.GL20.*;
|
|
|
-import static org.lwjgl.opengl.GL30.glBindVertexArray;
|
|
|
|
|
|
public final class Shader
|
|
|
{
|
|
@@ -25,13 +23,14 @@ public final class Shader
|
|
|
|
|
|
protected static boolean initDone = false;
|
|
|
|
|
|
+ private final static FontRenderer FONT_RENDERER = new FontRenderer();
|
|
|
+ private final static ColorRenderer COLOR_RENDERER = new ColorRenderer();
|
|
|
+
|
|
|
// uniform stuff
|
|
|
private static int unifViewMatrix = -1;
|
|
|
private static int unifModelMatrix = -1;
|
|
|
private static MatrixStack modelMatrix;
|
|
|
|
|
|
- private static int unifDepth = -1;
|
|
|
-
|
|
|
private static int unifAmbientLight = -1;
|
|
|
private static int[][] unifLight;
|
|
|
|
|
@@ -51,9 +50,6 @@ public final class Shader
|
|
|
modelMatrix = new MatrixStack(20);
|
|
|
updateMatrix();
|
|
|
|
|
|
- unifDepth = glGetUniformLocation(program, "depth");
|
|
|
- setDepth(0.0f);
|
|
|
-
|
|
|
unifAmbientLight = glGetUniformLocation(program, "ambientLight");
|
|
|
setAmbientLight(1.0f, 1.0f, 1.0f);
|
|
|
|
|
@@ -69,13 +65,13 @@ public final class Shader
|
|
|
}
|
|
|
|
|
|
unifUseTexture = glGetUniformLocation(program, "useTexture");
|
|
|
- setTextureUsing(false);
|
|
|
+ setTextureEnabled(false);
|
|
|
|
|
|
unifUseColor = glGetUniformLocation(program, "useColor");
|
|
|
- setColorUsing(false);
|
|
|
+ setColorEnabled(false);
|
|
|
|
|
|
unifUseLight = glGetUniformLocation(program, "useLight");
|
|
|
- setLightUsing(false);
|
|
|
+ setLightEnabled(false);
|
|
|
|
|
|
setViewPort(width, height);
|
|
|
initDone = true;
|
|
@@ -95,6 +91,16 @@ public final class Shader
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static FontRenderer getFontRenderer()
|
|
|
+ {
|
|
|
+ return FONT_RENDERER;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ColorRenderer getColorRenderer()
|
|
|
+ {
|
|
|
+ return COLOR_RENDERER;
|
|
|
+ }
|
|
|
+
|
|
|
private static void updateViewMatrix()
|
|
|
{
|
|
|
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
|
|
@@ -111,12 +117,12 @@ public final class Shader
|
|
|
|
|
|
buffer.put(0.0f);
|
|
|
buffer.put(0.0f);
|
|
|
- buffer.put(1.0f);
|
|
|
+ buffer.put(-1.0f / height);
|
|
|
buffer.put(0.0f);
|
|
|
|
|
|
buffer.put(-1.0f);
|
|
|
buffer.put(1.0f);
|
|
|
- buffer.put(0.0f);
|
|
|
+ buffer.put(0.5f);
|
|
|
buffer.put(1.0f);
|
|
|
|
|
|
buffer.flip();
|
|
@@ -188,11 +194,6 @@ public final class Shader
|
|
|
modelMatrix.rotate(angle);
|
|
|
}
|
|
|
|
|
|
- public static void setDepth(float depth)
|
|
|
- {
|
|
|
- glUniform1f(unifDepth, depth);
|
|
|
- }
|
|
|
-
|
|
|
public static void setAmbientLight(float r, float g, float b)
|
|
|
{
|
|
|
glUniform3f(unifAmbientLight, r, g, b);
|
|
@@ -224,21 +225,48 @@ public final class Shader
|
|
|
glUniform1f(unifLight[index][2], strength);
|
|
|
}
|
|
|
|
|
|
- public static void setTextureUsing(boolean use)
|
|
|
+ public static void setTextureEnabled(boolean use)
|
|
|
{
|
|
|
glUniform1i(unifUseTexture, use ? 1 : 0);
|
|
|
}
|
|
|
|
|
|
- public static void setColorUsing(boolean use)
|
|
|
+ public static void setColorEnabled(boolean use)
|
|
|
{
|
|
|
glUniform1i(unifUseColor, use ? 1 : 0);
|
|
|
}
|
|
|
|
|
|
- public static void setLightUsing(boolean use)
|
|
|
+ public static void setLightEnabled(boolean use)
|
|
|
{
|
|
|
glUniform1i(unifUseLight, use ? 1 : 0);
|
|
|
}
|
|
|
|
|
|
+ public static void setDepthTestEnabled(boolean use)
|
|
|
+ {
|
|
|
+ if(use)
|
|
|
+ {
|
|
|
+ glEnable(GL_DEPTH_TEST);
|
|
|
+ glDepthFunc(GL_LEQUAL);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ glDisable(GL_DEPTH_TEST);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setBlendingEnabled(boolean use)
|
|
|
+ {
|
|
|
+ if(use)
|
|
|
+ {
|
|
|
+ glEnable(GL_BLEND);
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ glDisable(GL_BLEND);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// -------------------------------------------------------------------------
|
|
|
// general stuff
|
|
|
// -------------------------------------------------------------------------
|