Skip to content

Commit

Permalink
exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexian123 committed Jun 15, 2024
1 parent 1df1914 commit 4956b4e
Show file tree
Hide file tree
Showing 89 changed files with 66 additions and 81 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="lib" path="lib/jars/lwjgl_util.jar"/>
<classpathentry kind="lib" path="lib/jars/lwjgl.jar"/>
<classpathentry kind="lib" path="lib/jars/slick-util.jar"/>
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 1 addition & 3 deletions src/com/alexian123/font/FontType.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.alexian123.font;

import java.io.File;

/**
* Represents a font. It holds the font's texture atlas as well as having the
* ability to create the quad vertices for any text using this font.
Expand All @@ -24,7 +22,7 @@ public class FontType {
* - the font file containing information about each character in
* the texture atlas.
*/
public FontType(int textureAtlas, File fontFile) {
public FontType(int textureAtlas, String fontFile) {
this.textureAtlas = textureAtlas;
this.loader = new TextMeshCreator(fontFile);
}
Expand Down
12 changes: 6 additions & 6 deletions src/com/alexian123/font/MetaFile.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.alexian123.font;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -47,9 +46,9 @@ public class MetaFile {
* @param file
* - the font file.
*/
protected MetaFile(File file) {
protected MetaFile(String fileName) {
this.aspectRatio = (double) Display.getWidth() / (double) Display.getHeight();
openFile(file);
openFile(fileName);
loadPaddingData();
loadLineSizes();
int imageWidth = getValueOfVariable("scaleW");
Expand Down Expand Up @@ -135,9 +134,10 @@ private void close() {
* @param file
* - the font file.
*/
private void openFile(File file) {
private void openFile(String fileName) {
try {
reader = new BufferedReader(new FileReader(file));
InputStreamReader isr = new InputStreamReader(MetaFile.class.getResourceAsStream(fileName));
reader = new BufferedReader(isr);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Couldn't read font meta file!");
Expand Down
3 changes: 1 addition & 2 deletions src/com/alexian123/font/TextMeshCreator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.alexian123.font;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -11,7 +10,7 @@ public class TextMeshCreator {

private MetaFile metaData;

protected TextMeshCreator(File metaFile) {
protected TextMeshCreator(String metaFile) {
metaData = new MetaFile(metaFile);
}

Expand Down
1 change: 0 additions & 1 deletion src/com/alexian123/game/TestGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;

import com.alexian123.engine.ShadowManager;
import com.alexian123.entity.Camera;
import com.alexian123.entity.Entity;
import com.alexian123.entity.LightEntity;
Expand Down
13 changes: 6 additions & 7 deletions src/com/alexian123/loader/Loader.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.alexian123.loader;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
Expand Down Expand Up @@ -114,7 +113,7 @@ public RawModel loadToVao(ModelDataNM data) {
public int loadTexture(String fileName) {
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG", new FileInputStream("res/textures/" + fileName + ".png"));
texture = TextureLoader.getTexture("PNG", Loader.class.getResourceAsStream("/res/textures/" + fileName + ".png"));
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0f);
Expand All @@ -137,7 +136,7 @@ public int loadTexture(String fileName) {
public FontType loadFont(String fontName) {
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG", new FileInputStream("res/fonts/" + fontName + ".png"));
texture = TextureLoader.getTexture("PNG", Loader.class.getResourceAsStream("/res/fonts/" + fontName + ".png"));
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0f);
Expand All @@ -148,7 +147,7 @@ public FontType loadFont(String fontName) {
}
int textureID = texture.getTextureID();
textures.add(textureID);
return new FontType(textureID, new File("res/fonts/" + fontName + ".fnt"));
return new FontType(textureID, "/res/fonts/" + fontName + ".fnt");
}

/**
Expand All @@ -161,7 +160,7 @@ public int loadCubeMap(String[] fileNames) {
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, id);
for (int i = 0; i < fileNames.length; ++i) {
TextureData data = decodeTexture("res/textures/" + fileNames[i] + ".png");
TextureData data = decodeTexture("/res/textures/" + fileNames[i] + ".png");
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA,
data.getWidth(), data.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffer());

Expand Down Expand Up @@ -241,7 +240,7 @@ private TextureData decodeTexture(String fileName) {
int width = 0, height = 0;
ByteBuffer buffer = null;
try {
FileInputStream in = new FileInputStream(fileName);
InputStream in = Loader.class.getResourceAsStream(fileName);
PNGDecoder decoder = new PNGDecoder(in);
width = decoder.getWidth();
height = decoder.getHeight();
Expand Down
16 changes: 3 additions & 13 deletions src/com/alexian123/loader/OBJFileLoader.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.alexian123.loader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -13,18 +11,10 @@

public class OBJFileLoader {

private static final String RES_LOC = "res/models/regular/";
private static final String RES_LOC = "/res/models/regular/";

public static ModelData loadOBJ(String objFileName) {
FileReader isr = null;
File objFile = new File(RES_LOC + objFileName + ".obj");
try {
isr = new FileReader(objFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.err.println("File not found in res; don't use any extention");
System.exit(-1);
}
InputStreamReader isr = new InputStreamReader(OBJFileLoader.class.getResourceAsStream(RES_LOC + objFileName + ".obj"));
BufferedReader reader = new BufferedReader(isr);
String line;
List<Vertex> vertices = new ArrayList<>();
Expand Down
16 changes: 3 additions & 13 deletions src/com/alexian123/loader/OBJFileLoaderNM.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.alexian123.loader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -13,18 +11,10 @@

public class OBJFileLoaderNM {

private static final String RES_LOC = "res/models/normal_mapping/";
private static final String RES_LOC = "/res/models/normal_mapping/";

public static ModelDataNM loadOBJ(String objFileName) {
FileReader isr = null;
File objFile = new File(RES_LOC + objFileName + ".obj");
try {
isr = new FileReader(objFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.err.println("File not found in res; don't use any extention");
System.exit(-1);
}
InputStreamReader isr = new InputStreamReader(OBJFileLoader.class.getResourceAsStream(RES_LOC + objFileName + ".obj"));
BufferedReader reader = new BufferedReader(isr);
String line;
List<VertexNM> vertices = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/EntityShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class EntityShader extends ShaderProgram {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/entity.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/entity.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/entity.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/entity.frag";

public EntityShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/EntityShaderNM.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

public class EntityShaderNM extends EntityShader {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/entity_nm.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/entity_nm.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/entity_nm.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/entity_nm.frag";

public EntityShaderNM() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/FontShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

public class FontShader extends ShaderProgram {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/font.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/font.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/font.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/font.frag";

public FontShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/GUIShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class GUIShader extends ShaderProgram {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/gui.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/gui.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/gui.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/gui.frag";

public GUIShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/ParticleShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class ParticleShader extends ShaderProgram{

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/particle.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/particle.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/particle.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/particle.frag";

public ParticleShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
39 changes: 21 additions & 18 deletions src/com/alexian123/shader/ShaderProgram.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.alexian123.shader;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -133,30 +134,32 @@ protected static List<Integer> createNewUniformArray(int size) {
return new ArrayList<>(Collections.nCopies(size, NEW_UNIFORM));
}

@SuppressWarnings("deprecation")
private static int loadShader(String fileName, int type) {
private static int loadShader(String fileName, int type) {
final String SHADER_TYPE_NAME = type == GL20.GL_VERTEX_SHADER ? "vertex" : "fragment";
StringBuilder shaderCode = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line;
while ((line = reader.readLine()) != null) {
shaderCode.append(line).append("\n");
}
reader.close();

try (InputStream in = ShaderProgram.class.getResourceAsStream(fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = reader.readLine()) != null) {
shaderCode.append(line).append(System.lineSeparator());
}
} catch (IOException e) {
System.err.println("Error loading " + SHADER_TYPE_NAME + " shader: " + fileName);
e.printStackTrace();
System.exit(-1);
System.err.println("Error loading " + SHADER_TYPE_NAME + " shader: " + fileName);
e.printStackTrace();
System.exit(-1);
}

int shaderID = GL20.glCreateShader(type);
GL20.glShaderSource(shaderID, shaderCode);
GL20.glCompileShader(shaderID);
if (GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
System.err.println("Error compiling " + SHADER_TYPE_NAME + " shader: " + fileName);
System.exit(-1);

if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
System.err.println("Error compiling " + SHADER_TYPE_NAME + " shader: " + fileName);
System.err.println(GL20.glGetShaderInfoLog(shaderID, 500));
System.exit(-1);
}

return shaderID;
}
}
}
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/ShadowShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class ShadowShader extends ShaderProgram {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/shadow.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/shadow.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/shadow.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/shadow.frag";

public ShadowShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/SkyBoxShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

public class SkyBoxShader extends ShaderProgram{

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/skybox.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/skybox.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/skybox.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/skybox.frag";

private static final float ROTATION_INCREMENT = 0.1f;

Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/TerrainShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

public class TerrainShader extends ShaderProgram {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/terrain.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/terrain.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/terrain.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/terrain.frag";

public TerrainShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
4 changes: 2 additions & 2 deletions src/com/alexian123/shader/WaterShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class WaterShader extends ShaderProgram {

private static final String VERTEX_SHADER_FILE = "src/com/alexian123/shader/glsl/vertex/water.vert";
private static final String FRAGMENT_SHADER_FILE = "src/com/alexian123/shader/glsl/fragment/water.frag";
private static final String VERTEX_SHADER_FILE = "/com/alexian123/shader/glsl/vertex/water.vert";
private static final String FRAGMENT_SHADER_FILE = "/com/alexian123/shader/glsl/fragment/water.frag";

public WaterShader() {
super(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
Expand Down
6 changes: 6 additions & 0 deletions src/com/alexian123/shader/glsl/fragment/font.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ uniform float characterEdge;
uniform float borderWidth;
uniform float borderEdge;

// use in case 'smoothstep' makes the game crash
float smoothlyStep(float edge0, float edge1, float x) {
float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}

void main(void) {
float charDistance = 1.0 - texture(fontAtlas, passTextureCoord).a;
float charAlpha = 1.0 - smoothstep(characterWidth, characterWidth + characterEdge, charDistance);
Expand Down

0 comments on commit 4956b4e

Please sign in to comment.