|
@@ -1,59 +1,47 @@
|
|
package me.hammerle.snuviengine.api;
|
|
package me.hammerle.snuviengine.api;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.net.URL;
|
|
|
|
import java.nio.FloatBuffer;
|
|
import java.nio.FloatBuffer;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Scanner;
|
|
|
|
import org.lwjgl.BufferUtils;
|
|
import org.lwjgl.BufferUtils;
|
|
import static org.lwjgl.opengl.GL11.*;
|
|
import static org.lwjgl.opengl.GL11.*;
|
|
import static org.lwjgl.opengl.GL14.*;
|
|
import static org.lwjgl.opengl.GL14.*;
|
|
import static org.lwjgl.opengl.GL20.*;
|
|
import static org.lwjgl.opengl.GL20.*;
|
|
|
|
|
|
-public final class Renderer
|
|
|
|
-{
|
|
|
|
- private final int program;
|
|
|
|
-
|
|
|
|
|
|
+public final class Renderer {
|
|
private float width;
|
|
private float width;
|
|
private float height;
|
|
private float height;
|
|
private int scale;
|
|
private int scale;
|
|
-
|
|
|
|
- private final FontRenderer fontRenderer;
|
|
|
|
|
|
+ private final FontRenderer fontRenderer = new FontRenderer();
|
|
private final ColorRenderer colorRenderer = new ColorRenderer();
|
|
private final ColorRenderer colorRenderer = new ColorRenderer();
|
|
private final DirectTextureRenderer textureRenderer = new DirectTextureRenderer();
|
|
private final DirectTextureRenderer textureRenderer = new DirectTextureRenderer();
|
|
-
|
|
|
|
|
|
+
|
|
// uniform stuff
|
|
// uniform stuff
|
|
private final int unifViewMatrix;
|
|
private final int unifViewMatrix;
|
|
private final int unifModelMatrix;
|
|
private final int unifModelMatrix;
|
|
private final MatrixStack modelMatrix = new MatrixStack(20);
|
|
private final MatrixStack modelMatrix = new MatrixStack(20);
|
|
-
|
|
|
|
|
|
+
|
|
private final int unifAmbientLight;
|
|
private final int unifAmbientLight;
|
|
private final int[][] unifLight = new int[32][3];
|
|
private final int[][] unifLight = new int[32][3];
|
|
-
|
|
|
|
- private final int unifUseTexture;
|
|
|
|
- private final int unifUseColor;
|
|
|
|
- private final int unifUseLight;
|
|
|
|
- private final int unifUseMixColor;
|
|
|
|
|
|
+
|
|
|
|
+ private final UniformBoolean useTexture;
|
|
|
|
+ private final UniformBoolean useColor;
|
|
|
|
+ private final UniformBoolean useLight;
|
|
|
|
+ private final UniformBoolean useMixColor;
|
|
private final int unifMixColorLoc;
|
|
private final int unifMixColorLoc;
|
|
- private final float[] unifMixColor = new float[] {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
-
|
|
|
|
- protected Renderer(int width, int height)
|
|
|
|
- {
|
|
|
|
- program = createShaderProgram("vertex.vs", "fragment.fs");
|
|
|
|
|
|
+ private final float[] unifMixColor = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
+
|
|
|
|
+ protected Renderer(int program, int width, int height) {
|
|
glUseProgram(program);
|
|
glUseProgram(program);
|
|
-
|
|
|
|
|
|
+
|
|
unifViewMatrix = glGetUniformLocation(program, "viewMatrix");
|
|
unifViewMatrix = glGetUniformLocation(program, "viewMatrix");
|
|
- fontRenderer = new FontRenderer();
|
|
|
|
- setViewPort(width, height);
|
|
|
|
-
|
|
|
|
|
|
+ setSize(width, height);
|
|
|
|
+
|
|
unifModelMatrix = glGetUniformLocation(program, "modelMatrix");
|
|
unifModelMatrix = glGetUniformLocation(program, "modelMatrix");
|
|
updateMatrix();
|
|
updateMatrix();
|
|
-
|
|
|
|
|
|
+
|
|
unifAmbientLight = glGetUniformLocation(program, "ambientLight");
|
|
unifAmbientLight = glGetUniformLocation(program, "ambientLight");
|
|
setAmbientLight(1.0f, 1.0f, 1.0f);
|
|
setAmbientLight(1.0f, 1.0f, 1.0f);
|
|
-
|
|
|
|
- for(int index = 0; index < unifLight.length; index++)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ for(int index = 0; index < unifLight.length; index++) {
|
|
unifLight[index][0] = glGetUniformLocation(program, String.format("lights[%d].color", index));
|
|
unifLight[index][0] = glGetUniformLocation(program, String.format("lights[%d].color", index));
|
|
unifLight[index][1] = glGetUniformLocation(program, String.format("lights[%d].pos", index));
|
|
unifLight[index][1] = glGetUniformLocation(program, String.format("lights[%d].pos", index));
|
|
unifLight[index][2] = glGetUniformLocation(program, String.format("lights[%d].strength", index));
|
|
unifLight[index][2] = glGetUniformLocation(program, String.format("lights[%d].strength", index));
|
|
@@ -61,337 +49,168 @@ public final class Renderer
|
|
setLightLocation(index, 0.0f, 0.0f);
|
|
setLightLocation(index, 0.0f, 0.0f);
|
|
setLightStrength(index, 0.0f);
|
|
setLightStrength(index, 0.0f);
|
|
}
|
|
}
|
|
-
|
|
|
|
- unifUseTexture = glGetUniformLocation(program, "useTexture");
|
|
|
|
- setTextureEnabled(false);
|
|
|
|
-
|
|
|
|
- unifUseColor = glGetUniformLocation(program, "useColor");
|
|
|
|
- setColorEnabled(false);
|
|
|
|
-
|
|
|
|
- unifUseLight = glGetUniformLocation(program, "useLight");
|
|
|
|
- setLightEnabled(false);
|
|
|
|
-
|
|
|
|
- unifUseMixColor = glGetUniformLocation(program, "useMixColor");
|
|
|
|
- setMixColorEnabled(false);
|
|
|
|
|
|
+
|
|
|
|
+ useTexture = new UniformBoolean(program, "useTexture", false);
|
|
|
|
+ useColor = new UniformBoolean(program, "useColor", false);
|
|
|
|
+ useLight = new UniformBoolean(program, "useLight", false);
|
|
|
|
+ useMixColor = new UniformBoolean(program, "useMixColor", false);
|
|
|
|
+
|
|
unifMixColorLoc = glGetUniformLocation(program, "mixColor");
|
|
unifMixColorLoc = glGetUniformLocation(program, "mixColor");
|
|
setMixColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
setMixColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
-
|
|
|
|
- setViewPort(width, height);
|
|
|
|
|
|
+
|
|
|
|
+ setSize(width, height);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public FontRenderer getFontRenderer()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public FontRenderer getFontRenderer() {
|
|
return fontRenderer;
|
|
return fontRenderer;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public ColorRenderer getColorRenderer()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public ColorRenderer getColorRenderer() {
|
|
return colorRenderer;
|
|
return colorRenderer;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public DirectTextureRenderer getTextureRenderer()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public DirectTextureRenderer getTextureRenderer() {
|
|
return textureRenderer;
|
|
return textureRenderer;
|
|
}
|
|
}
|
|
-
|
|
|
|
- private void updateViewMatrix()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ private void updateViewMatrix() {
|
|
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
|
|
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
|
|
-
|
|
|
|
- buffer.put(2.0f / width);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
-
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
- buffer.put(-2.0f / height);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
-
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
- buffer.put(-1.0f / height);
|
|
|
|
- buffer.put(0.0f);
|
|
|
|
-
|
|
|
|
- buffer.put(-1.0f);
|
|
|
|
- buffer.put(1.0f);
|
|
|
|
- buffer.put(0.5f);
|
|
|
|
- buffer.put(1.0f);
|
|
|
|
-
|
|
|
|
|
|
+ addToBuffer(buffer, 2.0f / width, 0.0f, 0.0f, 0.0f);
|
|
|
|
+ addToBuffer(buffer, 0.0f, -2.0f / height, 0.0f, 0.0f);
|
|
|
|
+ addToBuffer(buffer, 0.0f, 0.0f, -1.0f / height, 0.0f);
|
|
|
|
+ addToBuffer(buffer, -1.0f, 1.0f, 0.5f, 1.0f);
|
|
buffer.flip();
|
|
buffer.flip();
|
|
-
|
|
|
|
glUniformMatrix4fv(unifViewMatrix, false, buffer);
|
|
glUniformMatrix4fv(unifViewMatrix, false, buffer);
|
|
}
|
|
}
|
|
-
|
|
|
|
- protected void setViewPort(float width, float height)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ private void addToBuffer(FloatBuffer buffer, float a, float b, float c, float d) {
|
|
|
|
+ buffer.put(a);
|
|
|
|
+ buffer.put(b);
|
|
|
|
+ buffer.put(c);
|
|
|
|
+ buffer.put(d);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void setSize(int width, int height) {
|
|
scale = 1;
|
|
scale = 1;
|
|
- while(width / (scale + 1) >= 400 && height / (scale + 1) >= 300)
|
|
|
|
- {
|
|
|
|
|
|
+ while(width / (scale + 1) >= 400 && height / (scale + 1) >= 300) {
|
|
scale++;
|
|
scale++;
|
|
}
|
|
}
|
|
-
|
|
|
|
fontRenderer.setScale(scale);
|
|
fontRenderer.setScale(scale);
|
|
-
|
|
|
|
this.width = width / scale;
|
|
this.width = width / scale;
|
|
this.height = height / scale;
|
|
this.height = height / scale;
|
|
-
|
|
|
|
updateViewMatrix();
|
|
updateViewMatrix();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public int getViewScale()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public int getViewScale() {
|
|
return scale;
|
|
return scale;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public float getViewWidth()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public float getViewWidth() {
|
|
return width;
|
|
return width;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public float getViewHeight()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public float getViewHeight() {
|
|
return height;
|
|
return height;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void updateMatrix()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void updateMatrix() {
|
|
glUniformMatrix4fv(unifModelMatrix, false, modelMatrix.getData());
|
|
glUniformMatrix4fv(unifModelMatrix, false, modelMatrix.getData());
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void pushMatrix()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void pushMatrix() {
|
|
modelMatrix.push();
|
|
modelMatrix.push();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void popMatrix()
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void popMatrix() {
|
|
modelMatrix.pop();
|
|
modelMatrix.pop();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void translate(float tx, float ty)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void translate(float tx, float ty) {
|
|
modelMatrix.translate(tx, ty);
|
|
modelMatrix.translate(tx, ty);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void translateTo(float tx, float ty)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void translateTo(float tx, float ty) {
|
|
modelMatrix.translateTo(tx, ty);
|
|
modelMatrix.translateTo(tx, ty);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void scale(float sx, float sy)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void scale(float sx, float sy) {
|
|
modelMatrix.scale(sx, sy);
|
|
modelMatrix.scale(sx, sy);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void rotate(float angle)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void rotate(float angle) {
|
|
modelMatrix.rotate(angle);
|
|
modelMatrix.rotate(angle);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setAmbientLight(float r, float g, float b)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void setAmbientLight(float r, float g, float b) {
|
|
glUniform3f(unifAmbientLight, r, g, b);
|
|
glUniform3f(unifAmbientLight, r, g, b);
|
|
}
|
|
}
|
|
-
|
|
|
|
- private void checkLightIndex(int index)
|
|
|
|
- {
|
|
|
|
- if(index < 0 || index > unifLight.length)
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("'%d' is not a valid light index", index);
|
|
|
|
|
|
+
|
|
|
|
+ private boolean isValidLightIndex(int index) {
|
|
|
|
+ return index >= 0 && index < unifLight.length;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setLightColor(int index, float r, float g, float b) {
|
|
|
|
+ if(isValidLightIndex(index)) {
|
|
|
|
+ glUniform3f(unifLight[index][0], r, g, b);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setLightLocation(int index, float x, float y) {
|
|
|
|
+ if(isValidLightIndex(index)) {
|
|
|
|
+ glUniform2f(unifLight[index][1], x, y);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setLightStrength(int index, float strength) {
|
|
|
|
+ if(isValidLightIndex(index)) {
|
|
|
|
+ glUniform1f(unifLight[index][2], strength);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setLightColor(int index, float r, float g, float b)
|
|
|
|
- {
|
|
|
|
- checkLightIndex(index);
|
|
|
|
- glUniform3f(unifLight[index][0], r, g, b);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setLightLocation(int index, float x, float y)
|
|
|
|
- {
|
|
|
|
- checkLightIndex(index);
|
|
|
|
- glUniform2f(unifLight[index][1], x, y);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setLightStrength(int index, float strength)
|
|
|
|
- {
|
|
|
|
- checkLightIndex(index);
|
|
|
|
- glUniform1f(unifLight[index][2], strength);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setTextureEnabled(boolean use)
|
|
|
|
- {
|
|
|
|
- glUniform1i(unifUseTexture, use ? 1 : 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setColorEnabled(boolean use)
|
|
|
|
- {
|
|
|
|
- glUniform1i(unifUseColor, use ? 1 : 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setMixColorEnabled(boolean use)
|
|
|
|
- {
|
|
|
|
- glUniform1i(unifUseMixColor, use ? 1 : 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setMixColor(float r, float g, float b, float a)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ public void setTextureEnabled(boolean use) {
|
|
|
|
+ useTexture.set(use);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setColorEnabled(boolean use) {
|
|
|
|
+ useColor.set(use);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setMixColorEnabled(boolean use) {
|
|
|
|
+ useMixColor.set(use);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setMixColor(float r, float g, float b, float a) {
|
|
unifMixColor[0] = r;
|
|
unifMixColor[0] = r;
|
|
unifMixColor[1] = g;
|
|
unifMixColor[1] = g;
|
|
unifMixColor[2] = b;
|
|
unifMixColor[2] = b;
|
|
unifMixColor[3] = a;
|
|
unifMixColor[3] = a;
|
|
glUniform4fv(unifMixColorLoc, unifMixColor);
|
|
glUniform4fv(unifMixColorLoc, unifMixColor);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setLightEnabled(boolean use)
|
|
|
|
- {
|
|
|
|
- glUniform1i(unifUseLight, use ? 1 : 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setDepthTestEnabled(boolean use)
|
|
|
|
- {
|
|
|
|
- if(use)
|
|
|
|
- {
|
|
|
|
- glEnable(GL_DEPTH_TEST);
|
|
|
|
- glDepthFunc(GL_LEQUAL);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- glDisable(GL_DEPTH_TEST);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ public void setLightEnabled(boolean use) {
|
|
|
|
+ useLight.set(use);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public 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);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ public void enableDepthTest() {
|
|
|
|
+ glEnable(GL_DEPTH_TEST);
|
|
|
|
+ glDepthFunc(GL_LEQUAL);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public float round(float f)
|
|
|
|
- {
|
|
|
|
- return ((int) (f * scale)) / scale;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // -------------------------------------------------------------------------
|
|
|
|
- // general stuff
|
|
|
|
- // -------------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
- private String[] readFile(String name)
|
|
|
|
- {
|
|
|
|
- URL url = Renderer.class.getClassLoader().getResource("me/hammerle/snuviengine/shader/" + name);
|
|
|
|
- if(url == null)
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed reading shader '%s'", name);
|
|
|
|
- }
|
|
|
|
- ArrayList<String> strings = new ArrayList<>();
|
|
|
|
- try(Scanner scanner = new Scanner(url.openStream()))
|
|
|
|
- {
|
|
|
|
- while(scanner.hasNext())
|
|
|
|
- {
|
|
|
|
- strings.add(scanner.nextLine() + "\n");
|
|
|
|
- }
|
|
|
|
- return strings.toArray(new String[strings.size()]);
|
|
|
|
- }
|
|
|
|
- catch(IOException ex)
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed reading shader '%s'", name);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ public void disableDepthTest() {
|
|
|
|
+ glDisable(GL_DEPTH_TEST);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void enableBlending() {
|
|
|
|
+ glEnable(GL_BLEND);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void disableBlending() {
|
|
|
|
+ glDisable(GL_BLEND);
|
|
}
|
|
}
|
|
-
|
|
|
|
- private String getError()
|
|
|
|
- {
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
|
-
|
|
|
|
- int glErr = glGetError();
|
|
|
|
- while(glErr != GL_NO_ERROR)
|
|
|
|
- {
|
|
|
|
- sb.append(glErr);
|
|
|
|
- sb.append(" ");
|
|
|
|
- glErr = glGetError();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return sb.toString();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private int createShaderProgram(String vertex, String fragment)
|
|
|
|
- {
|
|
|
|
- // ---------------------------------------------------------------------
|
|
|
|
- // vertex shader
|
|
|
|
- // ---------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
- String vShaderSource[] = readFile(vertex);
|
|
|
|
-
|
|
|
|
- int vShader = glCreateShader(GL_VERTEX_SHADER);
|
|
|
|
- glShaderSource(vShader, vShaderSource);
|
|
|
|
- glCompileShader(vShader);
|
|
|
|
-
|
|
|
|
- String error = getError();
|
|
|
|
- if(!error.isEmpty())
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed compiling vertex shader '%s' %s", vertex, error);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int compiled = glGetShaderi(vShader, GL_COMPILE_STATUS);
|
|
|
|
- if(compiled != 1)
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed compiling vertex shader '%s' %d %s", vertex, compiled, glGetShaderInfoLog(vShader));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ---------------------------------------------------------------------
|
|
|
|
- // fragment shader
|
|
|
|
- // ---------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
- String fShaderSource[] = readFile(fragment);
|
|
|
|
-
|
|
|
|
- int fShader = glCreateShader(GL_FRAGMENT_SHADER);
|
|
|
|
- glShaderSource(fShader, fShaderSource);
|
|
|
|
- glCompileShader(fShader);
|
|
|
|
-
|
|
|
|
- error = getError();
|
|
|
|
- if(!error.isEmpty())
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed compiling fragment shader '%s' %s", fragment, error);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- compiled = glGetShaderi(fShader, GL_COMPILE_STATUS);
|
|
|
|
- if(compiled != 1)
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed compiling fragment shader '%s' %d %s", fragment, compiled, glGetShaderInfoLog(fShader));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ---------------------------------------------------------------------
|
|
|
|
- // linking
|
|
|
|
- // ---------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
- int vfprogram = glCreateProgram();
|
|
|
|
- glAttachShader(vfprogram, vShader);
|
|
|
|
- glAttachShader(vfprogram, fShader);
|
|
|
|
- glLinkProgram(vfprogram);
|
|
|
|
-
|
|
|
|
- error = getError();
|
|
|
|
- if(!error.isEmpty())
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed linking shaders '%s' and '%s' %s", vertex, fragment, error);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- compiled = glGetProgrami(vfprogram, GL_LINK_STATUS);
|
|
|
|
- if(compiled != 1)
|
|
|
|
- {
|
|
|
|
- throw new ShaderException("failed linking shaders '%s' and '%s' %d %s", vertex, fragment, compiled, glGetProgramInfoLog(vfprogram));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- glDeleteShader(vShader);
|
|
|
|
- glDeleteShader(fShader);
|
|
|
|
-
|
|
|
|
- return vfprogram;
|
|
|
|
- }
|
|
|
|
|
|
+ public float round(float f) {
|
|
|
|
+ return ((int) (f * scale)) / (float) scale;
|
|
|
|
+ }
|
|
}
|
|
}
|