Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;

import com.project.physics.engine.graphic.window.DynamicRenderer;
import com.project.physics.engine.graphic.window.Window;
import com.project.physics.engine.graphic.DynamicCamera;
import com.project.physics.engine.graphic.Window;
import com.project.physics.engine.state.PhysicsEngineState;
import com.project.physics.engine.state.PongGameState;
import com.project.physics.engine.state.SpinningTriangleState;
Expand Down Expand Up @@ -71,7 +71,7 @@ public abstract class Game {
/**
* Used for rendering.
*/
protected DynamicRenderer renderer;
protected DynamicCamera renderer;
/**
* Stores the current state.
*/
Expand All @@ -82,7 +82,7 @@ public abstract class Game {
*/
public Game() {
timer = new Timer();
renderer = new DynamicRenderer();
renderer = new DynamicCamera();
state = new StateMachine();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package com.project.physics.engine.game;

import com.project.physics.engine.graphic.DynamicCamera;
import com.project.physics.engine.graphic.shader.Color;
import com.project.physics.engine.graphic.shader.Texture;
import com.project.physics.engine.graphic.window.DynamicRenderer;
import com.project.physics.engine.math.Vector2f;

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ public void changeSpeed(float newSpeed) {
* @param renderer Renderer for batching
* @param alpha Alpha value, needed for interpolation
*/
public void render(DynamicRenderer renderer, float alpha) {
public void render(DynamicCamera renderer, float alpha) {
Vector2f interpolatedPosition = previousPosition.lerp(position, alpha);
float x = interpolatedPosition.x;
float y = interpolatedPosition.y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.project.physics.engine.game;

import com.project.physics.engine.graphic.DynamicCamera;
import com.project.physics.engine.graphic.shader.Color;
import com.project.physics.engine.graphic.shader.Texture;
import com.project.physics.engine.graphic.window.DynamicRenderer;
import com.project.physics.engine.math.Vector2f;

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ public void update(float delta) {
position = position.add(difference).add(new Vector2f(0.0f, -150f).scale(delta * delta));
}

public void render(DynamicRenderer renderer, float alpha) {
public void render(DynamicCamera renderer, float alpha) {
Vector2f interpolatedPosition = previousPosition.lerp(position, alpha);
float x = interpolatedPosition.x;
float y = interpolatedPosition.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.project.physics.engine.graphic.window;
package com.project.physics.engine.graphic;

import java.awt.FontFormatException;
import java.io.FileInputStream;
Expand Down Expand Up @@ -50,12 +50,13 @@
import org.lwjgl.system.MemoryUtil;

import com.project.physics.engine.core.Game;
import com.project.physics.engine.graphic.VertexArrayObject;
import com.project.physics.engine.graphic.VertexBufferObject;
import com.project.physics.engine.graphic.shader.Color;
import com.project.physics.engine.graphic.shader.Shader;
import com.project.physics.engine.graphic.shader.ShaderProgram;
import com.project.physics.engine.graphic.shader.ShaderProgram.ShaderLocations;
import com.project.physics.engine.graphic.shader.Texture;
import com.project.physics.engine.graphic.shader.VertexArrayObject;
import com.project.physics.engine.graphic.shader.VertexBufferObject;
import com.project.physics.engine.math.Matrix4f;
import com.project.physics.engine.text.Font;

Expand All @@ -64,7 +65,7 @@
*
* @author Heiko Brumme
*/
public class DynamicRenderer {
public class DynamicCamera {

private VertexArrayObject vao;
private VertexBufferObject vbo;
Expand All @@ -90,7 +91,7 @@ public void init() {
try {
font = new Font(new FileInputStream("resources/Inconsolata.ttf"), 16);
} catch (FontFormatException | IOException ex) {
Logger.getLogger(DynamicRenderer.class.getName()).log(Level.CONFIG, null, ex);
Logger.getLogger(DynamicCamera.class.getName()).log(Level.CONFIG, null, ex);
font = new Font();
}
debugFont = new Font(12, false);
Expand Down Expand Up @@ -457,17 +458,17 @@ private void setupShaderProgram() {
specifyVertexAttributes();

/* Set texture uniform */
int uniTex = program.getUniformLocation("texImage");
int uniTex = program.getUniformLocation(ShaderLocations.TEX_IMAGE);
program.setUniform(uniTex, 0);

/* Set model matrix to identity matrix */
Matrix4f model = new Matrix4f();
int uniModel = program.getUniformLocation("model");
int uniModel = program.getUniformLocation(ShaderLocations.MODEL);
program.setUniform(uniModel, model);

/* Set view matrix to identity matrix */
Matrix4f view = new Matrix4f();
int uniView = program.getUniformLocation("view");
int uniView = program.getUniformLocation(ShaderLocations.VIEW);
program.setUniform(uniView, view);

setProjection(width, height);
Expand All @@ -476,7 +477,7 @@ private void setupShaderProgram() {
public void setProjection(int width, int height) {
/* Set projection matrix to an orthographic projection */
Matrix4f projection = Matrix4f.orthographic(0f, width, 0f, height, -1f, 1f);
int uniformProjection = program.getUniformLocation("projection");
int uniformProjection = program.getUniformLocation(ShaderLocations.PROJECTION);
program.setUniform(uniformProjection, projection);
}

Expand All @@ -485,17 +486,17 @@ public void setProjection(int width, int height) {
*/
private void specifyVertexAttributes() {
/* Specify Vertex Pointer */
int posAttrib = program.getAttributeLocation("position");
int posAttrib = program.getAttributeLocation(ShaderLocations.POSITION);
program.enableVertexAttribute(posAttrib);
program.pointVertexAttribute(posAttrib, 2, 8 * Float.BYTES, 0);

/* Specify Color Pointer */
int colAttrib = program.getAttributeLocation("color");
int colAttrib = program.getAttributeLocation(ShaderLocations.COLOR);
program.enableVertexAttribute(colAttrib);
program.pointVertexAttribute(colAttrib, 4, 8 * Float.BYTES, 2 * Float.BYTES);

/* Specify Texture Pointer */
int texAttrib = program.getAttributeLocation("texcoord");
int texAttrib = program.getAttributeLocation(ShaderLocations.TEX_COORD);
program.enableVertexAttribute(texAttrib);
program.pointVertexAttribute(texAttrib, 2, 8 * Float.BYTES, 6 * Float.BYTES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.project.physics.engine.graphic.window;
package com.project.physics.engine.graphic;

import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public void link() {
}

/**
* Gets the location of an attribute variable with specified name.
* Gets the location of an attribute variable with specified dataLocation.
*
* @param name Attribute name
* @param dataLocation Attribute dataLocation
*
* @return Location of the attribute
*/
public int getAttributeLocation(CharSequence name) {
return glGetAttribLocation(id, name);
public int getAttributeLocation(ShaderLocations dataLocation) {
return glGetAttribLocation(id, dataLocation.toString());
}

/**
Expand Down Expand Up @@ -154,8 +154,8 @@ public void pointVertexAttribute(int location, int size, int stride, int offset)
*
* @return Location of the uniform
*/
public int getUniformLocation(CharSequence name) {
return glGetUniformLocation(id, name);
public int getUniformLocation(ShaderLocations name) {
return glGetUniformLocation(id, name.toString());
}

/**
Expand Down Expand Up @@ -276,4 +276,13 @@ public void delete() {
glDeleteProgram(id);
}

public enum ShaderLocations {
TEX_IMAGE,
MODEL,
VIEW,
PROJECTION,
POSITION,
COLOR,
TEX_COORD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.project.physics.engine.graphic;
package com.project.physics.engine.graphic.shader;

import static org.lwjgl.opengl.GL30.glBindVertexArray;
import static org.lwjgl.opengl.GL30.glDeleteVertexArrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.project.physics.engine.graphic;
package com.project.physics.engine.graphic.shader;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import com.project.physics.engine.game.CircleConstraint;
import com.project.physics.engine.game.PhysicsEntity;
import com.project.physics.engine.graphic.DynamicCamera;
import com.project.physics.engine.graphic.shader.Color;
import com.project.physics.engine.graphic.shader.Texture;
import com.project.physics.engine.graphic.window.DynamicRenderer;
import com.project.physics.engine.math.Vector2f;

/**
Expand All @@ -28,15 +28,15 @@
*/
public class PhysicsEngineState implements State {

private final DynamicRenderer renderer;
private final DynamicCamera renderer;
private Texture texture;
private final ArrayList<PhysicsEntity> physicsEntities = new ArrayList<>();
private int gameWidth;
private int gameHeight;
private GLFWMouseButtonCallback mouseCallback;
private final float deltaStep = 8f;

public PhysicsEngineState(DynamicRenderer renderer) {
public PhysicsEngineState(DynamicCamera renderer) {
this.renderer = renderer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

import com.project.physics.engine.game.Ball;
import com.project.physics.engine.game.Paddle;
import com.project.physics.engine.graphic.DynamicCamera;
import com.project.physics.engine.graphic.shader.Color;
import com.project.physics.engine.graphic.shader.Texture;
import com.project.physics.engine.graphic.window.DynamicRenderer;

/**
* This class contains a simple game.
Expand All @@ -43,7 +43,7 @@
public class PongGameState implements State {

private Texture texture;
private final DynamicRenderer renderer;
private final DynamicCamera renderer;

private Paddle player;
private Paddle opponent;
Expand All @@ -54,7 +54,7 @@ public class PongGameState implements State {
private int gameWidth;
private int gameHeight;

public PongGameState(DynamicRenderer renderer) {
public PongGameState(DynamicCamera renderer) {
this.renderer = renderer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
import static org.lwjgl.opengl.GL20.GL_VERTEX_SHADER;
import org.lwjgl.system.MemoryStack;

import com.project.physics.engine.graphic.VertexArrayObject;
import com.project.physics.engine.graphic.VertexBufferObject;
import com.project.physics.engine.graphic.shader.Shader;
import com.project.physics.engine.graphic.shader.ShaderProgram;
import com.project.physics.engine.graphic.shader.ShaderProgram.ShaderLocations;
import com.project.physics.engine.graphic.shader.VertexArrayObject;
import com.project.physics.engine.graphic.shader.VertexBufferObject;
import com.project.physics.engine.math.Matrix4f;

/**
Expand Down Expand Up @@ -149,11 +150,11 @@ public void enter() {
specifyVertexAttributes();

/* Get uniform location for the model matrix */
uniModel = program.getUniformLocation("model");
uniModel = program.getUniformLocation(ShaderLocations.MODEL);

/* Set view matrix to identity matrix */
Matrix4f view = new Matrix4f();
int uniView = program.getUniformLocation("view");
int uniView = program.getUniformLocation(ShaderLocations.VIEW);
program.setUniform(uniView, view);

/* Get width and height for calculating the ratio */
Expand All @@ -168,7 +169,7 @@ public void enter() {

/* Set projection matrix to an orthographic projection */
Matrix4f projection = Matrix4f.orthographic(-ratio, ratio, -1f, 1f, -1f, 1f);
int uniProjection = program.getUniformLocation("projection");
int uniProjection = program.getUniformLocation(ShaderLocations.PROJECTION);
program.setUniform(uniProjection, projection);
}

Expand All @@ -186,12 +187,12 @@ public void exit() {
*/
private void specifyVertexAttributes() {
/* Specify Vertex Pointer */
int posAttrib = program.getAttributeLocation("position");
int posAttrib = program.getAttributeLocation(ShaderLocations.POSITION);
program.enableVertexAttribute(posAttrib);
program.pointVertexAttribute(posAttrib, 3, 6 * Float.BYTES, 0);

/* Specify Color Pointer */
int colAttrib = program.getAttributeLocation("color");
int colAttrib = program.getAttributeLocation(ShaderLocations.COLOR);
program.enableVertexAttribute(colAttrib);
program.pointVertexAttribute(colAttrib, 3, 6 * Float.BYTES, 3 * Float.BYTES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

import org.lwjgl.system.MemoryUtil;

import com.project.physics.engine.graphic.DynamicCamera;
import com.project.physics.engine.graphic.shader.Color;
import com.project.physics.engine.graphic.shader.Texture;
import com.project.physics.engine.graphic.window.DynamicRenderer;

/**
* This class contains a font texture for drawing text.
Expand Down Expand Up @@ -364,7 +364,7 @@ public int getHeight(CharSequence text) {
* @param y Y coordinate of the text position
* @param c Color to use
*/
public void drawText(DynamicRenderer renderer, CharSequence text, float x, float y, Color c) {
public void drawText(DynamicCamera renderer, CharSequence text, float x, float y, Color c) {
int textHeight = getHeight(text);

float drawX = x;
Expand Down Expand Up @@ -402,7 +402,7 @@ public void drawText(DynamicRenderer renderer, CharSequence text, float x, float
* @param x X coordinate of the text position
* @param y Y coordinate of the text position
*/
public void drawText(DynamicRenderer renderer, CharSequence text, float x, float y) {
public void drawText(DynamicCamera renderer, CharSequence text, float x, float y) {
drawText(renderer, text, x, y, Color.WHITE);
}

Expand Down