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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ignore editors
.vscode
.idea
*.iml

# mac ignoreable
.DS_Store

bin
8 changes: 6 additions & 2 deletions shaders/pipe.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ uniform int top;

void main()
{
vec2 tc_temp = fs_in.tc;

if (top == 1)
fs_in.tc.y = 1.0 - fs_in.tc.y;
tc_temp.y = 1.0 - fs_in.tc.y;

color = texture(tex, fs_in.tc);
color = texture(tex, tc_temp);

if (color.w < 1.0)
discard;

color *= 2.0 / (length(bird - fs_in.position.xy) + 1.5) + 0.5;
color.w = 1.0;
}
16 changes: 7 additions & 9 deletions src/com/thecherno/flappy/Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.thecherno.flappy;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.system.MemoryUtil.*;

import java.nio.ByteBuffer;

import org.lwjgl.glfw.GLFWvidmode;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.glfw.GLFWVidMode;

import com.thecherno.flappy.graphics.Shader;
import com.thecherno.flappy.input.Input;
Expand All @@ -34,7 +32,7 @@ public void start() {
}

private void init() {
if (glfwInit() != GL_TRUE) {
if (!glfwInit()) {
System.err.println("Could not initialize GLFW!");
return;
}
Expand All @@ -46,14 +44,14 @@ private void init() {
return;
}

ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2);
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);

glfwSetKeyCallback(window, new Input());

glfwMakeContextCurrent(window);
glfwShowWindow(window);
GLContext.createFromCurrent();
createCapabilities();

glEnable(GL_DEPTH_TEST);
glActiveTexture(GL_TEXTURE1);
Expand Down Expand Up @@ -101,7 +99,7 @@ public void run() {
updates = 0;
frames = 0;
}
if (glfwWindowShouldClose(window) == GL_TRUE)
if (glfwWindowShouldClose(window))
running = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/thecherno/flappy/graphics/Shader.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void setUniform3f(String name, Vector3f vector) {

public void setUniformMat4f(String name, Matrix4f matrix) {
if (!enabled) enable();
glUniformMatrix4(getUniform(name), false, matrix.toFloatBuffer());
glUniformMatrix4fv(getUniform(name), false, matrix.toFloatBuffer());
}

public void enable() {
Expand Down
4 changes: 3 additions & 1 deletion src/com/thecherno/flappy/input/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWKeyCallback;

import static org.lwjgl.glfw.GLFW.*;

public class Input extends GLFWKeyCallback {

public static boolean[] keys = new boolean[65536];
public static boolean[] keys = new boolean[GLFW_KEY_LAST];

public void invoke(long window, int key, int scancode, int action, int mods) {
keys[key] = action != GLFW.GLFW_RELEASE;
Expand Down