Browse Source

Create res directory

Also includes Environment and Path
Geert Custers 1 year ago
parent
commit
d102e798a8

+ 2
- 37
Makefile View File

@@ -38,42 +38,7 @@ all: $(SOURCES) netrunner
38 38
 netrunner: $(OBJECTS)
39 39
 	$(LINK) $(LDFLAGS) -o $@ $^ $(LIBS)
40 40
 
41
-# make make 3.81 happy (since it can't parse any echo parameters)
42
-ifeq ($(UNAME), Darwin)
43
-shaders:
44
-ifneq ($(shell cat src/graphics/opengl/shaders/FontShader.vert src/graphics/opengl/shaders/FontShader.frag src/graphics/opengl/shaders/TextureShader.vert src/graphics/opengl/shaders/TextureShader.frag | $(MD5SUM)), $(shell cat src/graphics/opengl/shaders/gen/hashsum))
45
-	@mkdir -p "src/graphics/opengl/shaders/gen"
46
-	@echo "#ifndef FONTSHADER_H\n#define FONTSHADER_H\n\nconst char *fontVertexShaderSource =\n" > src/graphics/opengl/shaders/gen/FontShader.h;
47
-	@cat src/graphics/opengl/shaders/FontShader.vert | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/FontShader.h;
48
-	@echo "const char *fontFragmentShaderSource =\n" >> src/graphics/opengl/shaders/gen/FontShader.h;
49
-	@cat src/graphics/opengl/shaders/FontShader.frag | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/FontShader.h;
50
-	@echo "#endif\n" >> src/graphics/opengl/shaders/gen/FontShader.h;
51
-	@echo "#ifndef TEXTURESHADER_H\n#define TEXTURESHADER_H\n\nconst char *textureVertexShaderSource =\n" > src/graphics/opengl/shaders/gen/TextureShader.h;
52
-	@cat src/graphics/opengl/shaders/TextureShader.vert | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/TextureShader.h;
53
-	@echo "const char *textureFragmentShaderSource =\n" >> src/graphics/opengl/shaders/gen/TextureShader.h;
54
-	@cat src/graphics/opengl/shaders/TextureShader.frag | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/TextureShader.h;
55
-	@echo "#endif\n" >> src/graphics/opengl/shaders/gen/TextureShader.h;
56
-	@cat src/graphics/opengl/shaders/FontShader.vert src/graphics/opengl/shaders/FontShader.frag src/graphics/opengl/shaders/TextureShader.vert src/graphics/opengl/shaders/TextureShader.frag | $(MD5SUM) > src/graphics/opengl/shaders/gen/hashsum;
57
-endif
58
-else
59
-shaders:
60
-ifneq ($(shell cat src/graphics/opengl/shaders/FontShader.vert src/graphics/opengl/shaders/FontShader.frag src/graphics/opengl/shaders/TextureShader.vert src/graphics/opengl/shaders/TextureShader.frag | $(MD5SUM)), $(shell cat src/graphics/opengl/shaders/gen/hashsum))
61
-	@mkdir -p "src/graphics/opengl/shaders/gen"
62
-	@cat src/graphics/opengl/shaders/FontShader.vert src/graphics/opengl/shaders/FontShader.frag src/graphics/opengl/shaders/TextureShader.vert src/graphics/opengl/shaders/TextureShader.frag | $(MD5SUM) > src/graphics/opengl/shaders/gen/hashsum;
63
-	@/bin/echo -ne "#ifndef FONTSHADER_H\n#define FONTSHADER_H\n\nconst char *fontVertexShaderSource =\n" > src/graphics/opengl/shaders/gen/FontShader.h;
64
-	@cat src/graphics/opengl/shaders/FontShader.vert | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/FontShader.h;
65
-	@/bin/echo -ne "const char *fontFragmentShaderSource =\n" >> src/graphics/opengl/shaders/gen/FontShader.h;
66
-	@cat src/graphics/opengl/shaders/FontShader.frag | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/FontShader.h;
67
-	@/bin/echo -ne "#endif\n" >> src/graphics/opengl/shaders/gen/FontShader.h;
68
-	@/bin/echo -ne "#ifndef TEXTURESHADER_H\n#define TEXTURESHADER_H\n\nconst char *textureVertexShaderSource =\n" > src/graphics/opengl/shaders/gen/TextureShader.h;
69
-	@cat src/graphics/opengl/shaders/TextureShader.vert | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/TextureShader.h;
70
-	@/bin/echo -ne "const char *textureFragmentShaderSource =\n" >> src/graphics/opengl/shaders/gen/TextureShader.h;
71
-	@cat src/graphics/opengl/shaders/TextureShader.frag | awk '{if ($$0!="}") {print "\t\""$$0"\\n\""} else {print "\t\""$$0"\";\n"}}' >> src/graphics/opengl/shaders/gen/TextureShader.h;
72
-	@/bin/echo -ne "#endif\n" >> src/graphics/opengl/shaders/gen/TextureShader.h;
73
-endif
74
-endif
75
-
76
-$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | shaders
41
+$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
77 42
 	@mkdir -p $(@D)
78 43
 	@mkdir -p $(subst gen,d,$(@D))
79 44
 	$(CXX) -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td $(CXXFLAGS) $(INCPATH) $(WARNINGS) -c -o $@ $<
@@ -89,6 +54,6 @@ ntr-run-tests: test-url.o $(OBJDIR)/URL.o $(OBJDIR)/StringUtils.o
89 54
 	$(LINK) $(LDFLAGS) -o $@ test-url.o $(OBJDIR)/URL.o $(OBJDIR)/StringUtils.o $(LIBS)
90 55
 
91 56
 clean:
92
-	-@rm -rf src/graphics/opengl/shaders/gen $(OBJDIR) $(EXECUTABLE) 2>/dev/null || true
57
+	-@rm -rf $(OBJDIR) $(EXECUTABLE) 2>/dev/null || true
93 58
 
94 59
 include $(addsuffix .d,$(subst $(SRCDIR),$(DEPDIR),$(basename $(SOURCES))))

DejaVuSerif-Bold.ttf → res/DejaVuSerif-Bold.ttf View File


DejaVuSerif.ttf → res/DejaVuSerif.ttf View File


anime.pnm → res/anime.pnm View File


src/graphics/opengl/shaders/FontShader.frag → res/shaders/FontShader.frag View File


src/graphics/opengl/shaders/FontShader.vert → res/shaders/FontShader.vert View File


src/graphics/opengl/shaders/TextureShader.frag → res/shaders/TextureShader.frag View File


src/graphics/opengl/shaders/TextureShader.vert → res/shaders/TextureShader.vert View File


+ 35
- 0
src/environment/Environment.cpp View File

@@ -0,0 +1,35 @@
1
+#include "Environment.h"
2
+
3
+#include <vector>
4
+
5
+#include "Path.h"
6
+#include "../Log.h"
7
+
8
+std::string Environment::resourceDir = "";
9
+
10
+void Environment::init() {
11
+	if (!resourceDir.empty())
12
+		return; // already initialized O_o
13
+
14
+	std::vector<std::string> paths = {
15
+		"res"
16
+	};
17
+#ifndef _WIN32
18
+	// linux or osx
19
+	paths.push_back("/usr/share/netrunner/resources");
20
+#else
21
+	paths.push_back(""); //TODO: place it somewhere for windows
22
+#endif
23
+
24
+	for (std::string &path : paths) {
25
+		if (Path::directoryExists(path)) {
26
+			resourceDir = path;
27
+			logInfo() << "Found resource dir at " << path << "!" << std::endl;
28
+			break;
29
+		}
30
+	}
31
+}
32
+
33
+std::string Environment::getResourceDir() {
34
+	return resourceDir;
35
+}

+ 16
- 0
src/environment/Environment.h View File

@@ -0,0 +1,16 @@
1
+#ifndef ENVIRONMENT_H
2
+#define ENVIRONMENT_H
3
+
4
+#include <string>
5
+
6
+class Environment {
7
+public:
8
+	static void init();
9
+
10
+	static std::string getResourceDir();
11
+
12
+	static void setResourceDir();
13
+private:
14
+	static std::string resourceDir;
15
+};
16
+#endif

+ 21
- 0
src/environment/Path.cpp View File

@@ -0,0 +1,21 @@
1
+#include "Path.h"
2
+
3
+#include <sys/stat.h>
4
+
5
+bool Path::directoryExists(const std::string &path) {
6
+	struct stat sb;
7
+
8
+	if (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
9
+		return true;
10
+	}
11
+	return false;
12
+}
13
+
14
+std::string Path::fromUnixPath(const std::string &path) {
15
+	std::string returnPath(path);
16
+#ifdef _WIN32
17
+	for (int i = 0; i < path.size(); i++)
18
+		if (path.at(i) == '/') path.at(i) = '\\';
19
+#endif
20
+	return returnPath;
21
+}

+ 13
- 0
src/environment/Path.h View File

@@ -0,0 +1,13 @@
1
+#ifndef PATH_H
2
+#define PATH_H
3
+
4
+#include <string>
5
+
6
+class Path {
7
+public:
8
+	static bool directoryExists(const std::string &path);
9
+
10
+	static std::string fromUnixPath(const std::string &path);
11
+};
12
+
13
+#endif

+ 4
- 6
src/graphics/components/DocumentComponent.cpp View File

@@ -7,8 +7,6 @@
7 7
 
8 8
 #include "../opengl/Shader.h"
9 9
 #include "../opengl/ShaderLoader.h"
10
-#include "../opengl/shaders/gen/TextureShader.h"
11
-#include "../opengl/shaders/gen/FontShader.h"
12 10
 
13 11
 void deleteComponent(std::shared_ptr<Component> &component);
14 12
 void deleteNode(std::shared_ptr<Node> node);
@@ -279,14 +277,14 @@ void DocumentComponent::render() {
279 277
     //if (transformMatrixDirty) {
280 278
         //const std::clock_t begin = clock();
281 279
 		
282
-		Shader *fontShader = ShaderLoader::getShader(VertexShader(fontVertexShaderSource),
283
-				FragmentShader(fontFragmentShaderSource));
280
+		Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
281
+				FragmentShader("FontShader.frag"));
284 282
 		GLint transformLocation = fontShader->uniform("transform");
285 283
         glUniformMatrix4fv(transformLocation, 1, GL_FALSE, transformMatrix);
286 284
         //const std::clock_t end = clock();
287 285
         //std::cout << "Updated font matrix in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
288
-		Shader *textureShader = ShaderLoader::getShader(VertexShader(textureVertexShaderSource),
289
-				FragmentShader(textureFragmentShaderSource));
286
+		Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
287
+				FragmentShader("TextureShader.frag"));
290 288
         GLint transformLocation2 = textureShader->uniform("transform");
291 289
         glUniformMatrix4fv(transformLocation2, 1, GL_FALSE, transformMatrix);
292 290
 

+ 4
- 6
src/graphics/components/InputComponent.cpp View File

@@ -5,8 +5,6 @@
5 5
 
6 6
 #include "../opengl/Shader.h"
7 7
 #include "../opengl/ShaderLoader.h"
8
-#include "../opengl/shaders/gen/TextureShader.h"
9
-#include "../opengl/shaders/gen/FontShader.h"
10 8
 
11 9
 extern TextRasterizerCache *rasterizerCache;
12 10
 extern std::unique_ptr<Scheduler> scheduler;
@@ -164,8 +162,8 @@ void InputComponent::render() {
164 162
     // can actuall delete vertices here
165 163
     if (userInputText) {
166 164
         // make sure we're using win's transformMatrix
167
-		Shader *fontShader = ShaderLoader::getShader(VertexShader(fontVertexShaderSource),
168
-				FragmentShader(fontFragmentShaderSource));
165
+		Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
166
+				FragmentShader("FontShader.frag"));
169 167
 		fontShader->bind();
170 168
         if (!boundToPage) {
171 169
             GLint transformLocation = fontShader->uniform("transform");
@@ -182,8 +180,8 @@ void InputComponent::render() {
182 180
         }
183 181
         //std::cout << "rendering some text" << std::endl;
184 182
         userInputText->render();
185
-		Shader *textureShader = ShaderLoader::getShader(VertexShader(textureVertexShaderSource),
186
-				FragmentShader(textureFragmentShaderSource));
183
+		Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
184
+				FragmentShader("TextureShader.frag"));
187 185
 		textureShader->bind();
188 186
     }
189 187
     if (focused) {

+ 4
- 6
src/graphics/components/MultiComponent.cpp View File

@@ -8,8 +8,6 @@
8 8
 
9 9
 #include "../opengl/Shader.h"
10 10
 #include "../opengl/ShaderLoader.h"
11
-#include "../opengl/shaders/gen/TextureShader.h"
12
-#include "../opengl/shaders/gen/FontShader.h"
13 11
 
14 12
 MultiComponent::MultiComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) {
15 13
     
@@ -220,14 +218,14 @@ void MultiComponent::resize(const int passedWindowWidth, const int passedWindowH
220 218
 
221 219
 void MultiComponent::render() {
222 220
     //std::cout << "MultiComponent::render" << std::endl;
223
-	Shader *fontShader = ShaderLoader::getShader(VertexShader(fontVertexShaderSource),
224
-			FragmentShader(fontFragmentShaderSource));
221
+	Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
222
+			FragmentShader("FontShader.frag"));
225 223
 	fontShader->bind();
226 224
     renderDocumentComponents(rootComponent);
227 225
 	fontShader->release();
228 226
 
229
-	Shader *textureShader = ShaderLoader::getShader(VertexShader(textureVertexShaderSource),
230
-			FragmentShader(textureFragmentShaderSource));
227
+	Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
228
+			FragmentShader("TextureShader.frag"));
231 229
 	textureShader->bind();
232 230
     renderBoxComponents(rootComponent);
233 231
 	textureShader->release();

+ 4
- 4
src/graphics/opengl/Shader.h View File

@@ -6,13 +6,13 @@
6 6
 #include <map>
7 7
 
8 8
 struct VertexShader {
9
-	VertexShader(std::string s) : source(s) { }
10
-	std::string source;
9
+	VertexShader(std::string n) : name(n) { }
10
+	std::string name;
11 11
 };
12 12
 
13 13
 struct FragmentShader {
14
-	FragmentShader(std::string s) : source(s) { }
15
-	std::string source;
14
+	FragmentShader(std::string n) : name(n) { }
15
+	std::string name;
16 16
 };
17 17
 
18 18
 class Shader {

+ 40
- 24
src/graphics/opengl/ShaderLoader.cpp View File

@@ -1,37 +1,53 @@
1 1
 #include "ShaderLoader.h"
2 2
 
3
+#include <stdlib.h>
3 4
 #include <fstream>
4 5
 #include <iostream>
5
-#include <memory>
6 6
 
7 7
 #include "Shader.h"
8 8
 #include "../../Log.h"
9
+#include "../../environment/Environment.h"
10
+#include "../../environment/Path.h"
9 11
 
10 12
 static constexpr GLint maxLogSize = 1024 * 1024 * 2; //2 MiB
11 13
 
12 14
 ShaderLoader::ShaderCache ShaderLoader::shaderCache;
13 15
 
14
-GLuint ShaderLoader::loadShader(const std::string &shaderSource, Shader::Type type) {
16
+GLuint ShaderLoader::loadShader(const std::string &shaderName, Shader::Type type) {
15 17
 	GLenum glType = getGlShaderType(type);
16 18
 	if (!glType) {
17 19
 		logError() << "Unknown shader type: " << type << std::endl;
18 20
 		return 0;
19 21
 	}
20 22
 	GLuint shader = glCreateShader(glType);
21
-	const char *source = shaderSource.c_str();
22
-	glShaderSource(shader, 1, &source, NULL);
23
+
24
+	std::string path = Path::fromUnixPath(Environment::getResourceDir() + "/shaders/" + shaderName);
25
+	std::ifstream file(path, std::ifstream::ate);
26
+	if (!file.is_open()) {
27
+		logError() << "Could not open shader " << shaderName << std::endl;
28
+		return 0;
29
+	}
30
+
31
+	int fileSize = file.tellg();
32
+	file.seekg(std::ifstream::beg);
33
+	char *buffer = (char*) malloc(fileSize + 1);
34
+	file.read(buffer, fileSize);
35
+	buffer[fileSize] = 0;
36
+	glShaderSource(shader, 1, &buffer, NULL);
23 37
 	glCompileShader(shader);
24 38
 
25
-	if(checkShader(shader, shaderSource, type))
39
+	free(buffer);
40
+
41
+	if(checkShader(shader, shaderName, type))
26 42
 		return 0;
27 43
 
28 44
 	return shader;
29 45
 }
30 46
 
31
-GLuint ShaderLoader::createProgram(const std::string &shader1Source, Shader::Type shader1Type,
32
-	   	const std::string &shader2Source, Shader::Type shader2Type) {
33
-	GLuint shader1 = loadShader(shader1Source, shader1Type);
34
-	GLuint shader2 = loadShader(shader2Source, shader2Type);
47
+GLuint ShaderLoader::createProgram(const std::string &shader1Name, Shader::Type shader1Type,
48
+	   	const std::string &shader2Name, Shader::Type shader2Type) {
49
+	GLuint shader1 = loadShader(shader1Name, shader1Type);
50
+	GLuint shader2 = loadShader(shader2Name, shader2Type);
35 51
 
36 52
 	if (!shader1 || !shader2)
37 53
 		return 0;
@@ -41,18 +57,18 @@ GLuint ShaderLoader::createProgram(const std::string &shader1Source, Shader::Typ
41 57
 	glAttachShader(program, shader2);
42 58
 
43 59
 	glLinkProgram(program);
44
-	if (checkProgram(program, GL_LINK_STATUS, shader1Source))
45
-		return 0;
46
-	glValidateProgram(program);
47
-	if (checkProgram(program, GL_VALIDATE_STATUS, shader1Source))
60
+	if (checkProgram(program, GL_LINK_STATUS, shader1Name))
48 61
 		return 0;
62
+	/* glValidateProgram(program);
63
+	if (checkProgram(program, GL_VALIDATE_STATUS, shader1Name))
64
+		return 0; */
49 65
 
50 66
 	return program;
51 67
 }
52 68
 
53 69
 Shader *ShaderLoader::getShader(VertexShader vertexShader, FragmentShader fragmentShader) {
54 70
 	// concatenate strings to create unique key for the shader
55
-	std::string key = vertexShader.source + fragmentShader.source;
71
+	std::string key = vertexShader.name + fragmentShader.name;
56 72
 
57 73
 	// has the shader been cached?
58 74
 	auto it = shaderCache.find(key);
@@ -60,8 +76,8 @@ Shader *ShaderLoader::getShader(VertexShader vertexShader, FragmentShader fragme
60 76
 		return it->second;
61 77
 
62 78
 	// Ok. It isn't. Let's create the shader Q.Q
63
-	GLuint program = createProgram(vertexShader.source, Shader::Type::Vertex,
64
-		   	fragmentShader.source, Shader::Type::Fragment);
79
+	GLuint program = createProgram(vertexShader.name, Shader::Type::Vertex,
80
+		   	fragmentShader.name, Shader::Type::Fragment);
65 81
 	if (!program) //reee it failed
66 82
 		return NULL;
67 83
 
@@ -70,23 +86,23 @@ Shader *ShaderLoader::getShader(VertexShader vertexShader, FragmentShader fragme
70 86
 	return shader;
71 87
 }
72 88
 
73
-int ShaderLoader::checkShader(GLuint shader, const std::string &source, Shader::Type type) {
89
+int ShaderLoader::checkShader(GLuint shader, const std::string &shaderName, Shader::Type type) {
74 90
 	GLint success = 0;
75 91
 	glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
76 92
 
77 93
 	if (success == GL_TRUE) {
78
-		logDebug() << "Shader " << source << " compiled successfully!" << std::endl;
94
+		logDebug() << "Shader " << shaderName << " compiled successfully!" << std::endl;
79 95
 	} else {
80 96
 		GLint logSize = 0;
81 97
 		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logSize);
82 98
 		if (logSize > maxLogSize) {
83
-			logError() << "Shader " << source << " failed to compile but \
99
+			logError() << "Shader " << shaderName << " failed to compile but \
84 100
 				the log is too long to show." << std::endl;
85 101
 			return 1;
86 102
 		}
87 103
 		char log[logSize];
88 104
 		glGetShaderInfoLog(shader, logSize, &logSize, &log[0]);
89
-		logError() << "Shader " << source << " failed to compile. GL log output: "
105
+		logError() << "Shader " << shaderName << " failed to compile. GL log output: "
90 106
 			<< log << std::endl;
91 107
 		glDeleteShader(shader);
92 108
 		return 1;
@@ -94,23 +110,23 @@ int ShaderLoader::checkShader(GLuint shader, const std::string &source, Shader::
94 110
 	return 0;
95 111
 }
96 112
 
97
-int ShaderLoader::checkProgram(GLuint program, GLenum pname, const std::string &source) {
113
+int ShaderLoader::checkProgram(GLuint program, GLenum pname, const std::string &shaderName) {
98 114
 	GLint success = 0;
99 115
 	glGetProgramiv(program, pname, &success);
100 116
 	if (success == GL_TRUE) {
101
-		logDebug() << "Program with shader1 " << source << " " << getProgramStatusString(pname)
117
+		logDebug() << "Program with shader1 " << shaderName << " " << getProgramStatusString(pname)
102 118
 			<< std::endl;
103 119
 	} else {
104 120
 		GLint logSize = 0;
105 121
 		glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logSize);
106 122
 		if (logSize > maxLogSize) {
107
-			logError() << "Program with shader1 " << source << " failed to be "
123
+			logError() << "Program with shader1 " << shaderName << " failed to be "
108 124
 				<< getProgramStatusString(pname) << " but the log is too long to show" << std::endl;
109 125
 			return 1;
110 126
 		}
111 127
 		char log[logSize];
112 128
 		glGetProgramInfoLog(program, logSize, &logSize, &log[0]);
113
-		logError() << "Program with shader1 " << source << " failed to be "
129
+		logError() << "Program with shader1 " << shaderName << " failed to be "
114 130
 			<< getProgramStatusString(pname) << ". GL log output: " << log << std::endl;
115 131
 		glDeleteProgram(program);
116 132
 		return 1;

+ 5
- 5
src/graphics/opengl/ShaderLoader.h View File

@@ -15,17 +15,17 @@ public:
15 15
 	static Shader *getShader(VertexShader vertexShader, FragmentShader fragmentShader);
16 16
 
17 17
 	// Load a shader from disk and return the its handle
18
-	static GLuint loadShader(const std::string &source, Shader::Type shaderType);
18
+	static GLuint loadShader(const std::string &shader, Shader::Type shaderType);
19 19
 
20
-	static GLuint createProgram(const std::string &shader1Source, Shader::Type shader1Type,
21
-			const std::string &shader2Source, Shader::Type shader2Type);
20
+	static GLuint createProgram(const std::string &shader1Name, Shader::Type shader1Type,
21
+			const std::string &shader2Name, Shader::Type shader2Type);
22 22
 private:
23 23
 	static ShaderCache shaderCache;
24 24
 
25 25
 	static int checkProgram(GLuint program, GLenum programName,
26
-			const std::string &source);
26
+			const std::string &shaderName);
27 27
 
28
-	static int checkShader(GLuint shader, const std::string &source, Shader::Type shaderType);
28
+	static int checkShader(GLuint shader, const std::string &shaderName, Shader::Type shaderType);
29 29
 
30 30
 	static constexpr GLenum getGlShaderType(const Shader::Type type);
31 31
 

+ 4
- 6
src/graphics/opengl/Window.cpp View File

@@ -17,8 +17,6 @@
17 17
 #include "../components/InputComponent.h"
18 18
 #include "../opengl/Shader.h"
19 19
 #include "../opengl/ShaderLoader.h"
20
-#include "../opengl/shaders/gen/TextureShader.h"
21
-#include "../opengl/shaders/gen/FontShader.h"
22 20
 
23 21
 #include <cmath>
24 22
 #include <ctime>
@@ -702,8 +700,8 @@ void Window::render() {
702 700
             std::cout << "window::render - box render start - not ok: " << glErr << std::endl;
703 701
         }
704 702
 
705
-		Shader *textureShader = ShaderLoader::getShader(VertexShader(textureVertexShaderSource),
706
-				FragmentShader(textureFragmentShaderSource));
703
+		Shader *textureShader = ShaderLoader::getShader(VertexShader("TextureShader.vert"),
704
+				FragmentShader("TextureShader.frag"));
707 705
 		textureShader->bind();
708 706
         glErr=glGetError();
709 707
         if(glErr != GL_NO_ERROR) {
@@ -724,8 +722,8 @@ void Window::render() {
724 722
         renderComponentType("input", rootComponent);
725 723
 
726 724
         // it's quick but done on scroll
727
-		Shader *fontShader = ShaderLoader::getShader(VertexShader(fontVertexShaderSource),
728
-				FragmentShader(fontFragmentShaderSource));
725
+		Shader *fontShader = ShaderLoader::getShader(VertexShader("FontShader.vert"),
726
+				FragmentShader("FontShader.frag"));
729 727
 		fontShader->bind();
730 728
         // reset both, since components can change this
731 729
         // god we may have to reset this after each component render...

+ 5
- 1
src/graphics/text/TextRasterizer.cpp View File

@@ -1,14 +1,18 @@
1 1
 #include "TextRasterizer.h"
2
+#include <string>
2 3
 #include <cmath>
3 4
 #include <limits>
4 5
 #include <iostream>
5 6
 
7
+#include "../../environment/Environment.h"
8
+
6 9
 TextRasterizer::TextRasterizer(const std::string &fontPath, const int size, const unsigned int resolution, const bool bold) {
7 10
     fontSize = size;
8 11
     FT_Init_FreeType(&lib);
9 12
 
10 13
     face = std::make_unique<FT_Face>();
11
-    if (FT_New_Face(lib, bold ? (fontPath.substr(0, fontPath.length() - 4) + "-Bold.ttf").c_str() : fontPath.c_str(), 0, face.get())) {
14
+	std::string path = Environment::getResourceDir() + "/" + fontPath;
15
+    if (FT_New_Face(lib, bold ? (path.substr(0, fontPath.length() - 4) + "-Bold.ttf").c_str() : path.c_str(), 0, face.get())) {
12 16
         std::cout << "Could not open font" << std::endl;
13 17
         return;
14 18
     }

+ 3
- 0
src/main.cpp View File

@@ -1,5 +1,6 @@
1 1
 #include "CommandLineParams.h"
2 2
 #include "graphics/opengl/Window.h"
3
+#include "environment/Environment.h"
3 4
 #include "html/HTMLParser.h"
4 5
 #include "Log.h"
5 6
 #include "URL.h"
@@ -82,6 +83,7 @@ int main(int argc, char *argv[]) {
82 83
     */
83 84
     std::cout << "/g/ntr - NetRunner build " << __DATE__ << std::endl;
84 85
 
86
+	Environment::init();
85 87
     // we need to set up OGL before we can setDOM (because component can't be constructed (currently) without OGL)
86 88
     // but should be after CommandLineParams incase we need to change some type of window config
87 89
     window->windowWidth = 1024;
@@ -90,6 +92,7 @@ int main(int argc, char *argv[]) {
90 92
     if (!window->window) {
91 93
         return 1;
92 94
     }
95
+
93 96
     //std::cout << "argc " << argc << std::endl;
94 97
     if (argc > 1) {
95 98
         initCLParams(argc, argv);

+ 4
- 1
src/pnm.cpp View File

@@ -1,8 +1,11 @@
1 1
 #include "pnm.h"
2
+#include <string>
2 3
 #include <iostream>
3 4
 #include <stdio.h>
4 5
 #include <string.h>
5 6
 
7
+#include "environment/Environment.h"
8
+
6 9
 // pnm
7 10
 // The PNM format is just an abstraction of the PBM, PGM, and PPM formats. I.e. the name "PNM" refers collectively to PBM, PGM, and PPM.
8 11
 // pam has the advanced header
@@ -10,7 +13,7 @@
10 13
 RGBAPNMObject * readPPM(const char* fileName) {
11 14
     RGBAPNMObject *data=new RGBAPNMObject;
12 15
     // open the file to read just the header reading
13
-    FILE* fr = fopen(fileName, "r");
16
+    FILE* fr = fopen(std::string(Environment::getResourceDir() + "/" + fileName).c_str(), "r");
14 17
     if (!fr) {
15 18
         std::cout << "Can't open " << fileName << std::endl;
16 19
         return nullptr;

Loading…
Cancel
Save