Skip to content

Commit

Permalink
Fix resource loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Nov 4, 2016
1 parent bc25bc4 commit d96b706
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/integeruser/jglsdk/glimg/DdsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class DdsLoader {
public static ImageSet loadFromFile(String ddsFilepath) throws IOException {
InputStream ddsInputStream = ClassLoader.class.getResourceAsStream(ddsFilepath);
InputStream ddsInputStream = DdsLoader.class.getResourceAsStream(ddsFilepath);
byte[] ddsFile = readDdsFile(ddsInputStream);

// Check the first 4 bytes.
Expand Down
2 changes: 1 addition & 1 deletion src/integeruser/jglsdk/glimg/StbLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static ImageSet buildImageSetFromIntegerData(ByteBuffer image, int width
}

public static ImageSet loadFromFile(String imagePath) throws IOException, URISyntaxException {
String path = Paths.get(ClassLoader.class.getResource(imagePath).toURI()).toString();
String path = Paths.get(StbLoader.class.getResource(imagePath).toURI()).toString();
int[] x = new int[1];
int[] y = new int[1];
int[] comp = new int[1];
Expand Down
6 changes: 3 additions & 3 deletions src/integeruser/jgltut/framework/Framework.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class Framework {

public static String findFileOrThrow(String fileName) {
// search the file in '/jgltut/tut##/data/'
InputStream fileStream = ClassLoader.class.getResourceAsStream(CURRENT_TUTORIAL_DATAPATH + fileName);
InputStream fileStream = Framework.class.getResourceAsStream(CURRENT_TUTORIAL_DATAPATH + fileName);
if (fileStream != null) return CURRENT_TUTORIAL_DATAPATH + fileName;

// search the file in '/jgltut/data/'
fileStream = ClassLoader.class.getResourceAsStream(COMMON_DATAPATH + fileName);
fileStream = Framework.class.getResourceAsStream(COMMON_DATAPATH + fileName);
if (fileStream != null) return COMMON_DATAPATH + fileName;

throw new RuntimeException("Could not find the file " + fileName);
Expand All @@ -43,7 +43,7 @@ private static String loadShaderFile(String shaderFilePath) {
StringBuilder text = new StringBuilder();

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(ClassLoader.class.getResourceAsStream(shaderFilePath)));
BufferedReader reader = new BufferedReader(new InputStreamReader(Framework.class.getResourceAsStream(shaderFilePath)));

String line;
while ((line = reader.readLine()) != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/integeruser/jgltut/framework/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Mesh(String filename) {
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

String meshPath = Framework.findFileOrThrow(filename);
doc = dBuilder.parse(ClassLoader.class.getResourceAsStream(meshPath));
doc = dBuilder.parse(Mesh.class.getResourceAsStream(meshPath));
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
System.exit(-1);
Expand Down
2 changes: 1 addition & 1 deletion src/integeruser/jgltut/framework/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private SceneImpl(String filename) {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

String xmlPath = Framework.findFileOrThrow(filename);
InputStream xmlInputStream = ClassLoader.class.getResourceAsStream(xmlPath);
InputStream xmlInputStream = Scene.class.getResourceAsStream(xmlPath);
document = documentBuilder.parse(xmlInputStream);
} catch (SAXException | ParserConfigurationException | IOException e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion src/integeruser/jgltut/tut16/LightEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LightEnv {

String filePath = Framework.findFileOrThrow(envFileName);

doc = dBuilder.parse(ClassLoader.class.getResourceAsStream(filePath));
doc = dBuilder.parse(LightEnv.class.getResourceAsStream(filePath));
} catch (SAXException | ParserConfigurationException | IOException e) {
e.printStackTrace();
System.exit(-1);
Expand Down

0 comments on commit d96b706

Please sign in to comment.