aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--docs/Doxyfile2
-rwxr-xr-xscripts/update_version38
-rw-r--r--tests/simplegame.cpp8
-rw-r--r--yage/core/glslprogram.cpp99
-rw-r--r--yage/core/glslprogram.h10
-rw-r--r--yage/yage.h1
7 files changed, 123 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8fd23f7e..0ea75fa1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
# yage library cmakelists.txt
project(yage
- VERSION 0.3.1.0
+ VERSION 0.1.3.0
LANGUAGES CXX)
if(NOT DEFINED UNIT_TESTS)
@@ -55,5 +55,4 @@ if(UNIT_TESTS)
make_test(syncqueuetest 1)
make_test(activetest 1)
make_test(structtest ${SIMULATION_RUNS})
- make_test(defaultfiletest ${SIMULATION_RUNS})
endif()
diff --git a/docs/Doxyfile b/docs/Doxyfile
index 3e499988..10422fba 100644
--- a/docs/Doxyfile
+++ b/docs/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME = "YAGE"
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = v0.3.1
+PROJECT_NUMBER = v0.1.3
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/scripts/update_version b/scripts/update_version
new file mode 100755
index 00000000..9c618fa6
--- /dev/null
+++ b/scripts/update_version
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# -----------------------------------------------------------------------------
+# @file: add_version_headers
+#
+# Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
+# MIT License, see LICENSE file for more details.
+# -----------------------------------------------------------------------------
+
+
+import os
+import re
+import sys
+
+
+def main(argv):
+ cwd = os.path.join(os.getcwd(), argv[2])
+ cmake = os.path.join(cwd, "CMakeLists.txt")
+ doxyfile = os.path.join(cwd, "docs", "Doxyfile")
+
+ with open(cmake, "r+") as f_:
+ src = f_.read()
+ f_.seek(0)
+ src = re.sub(r"(project\(\w+\s+VERSION\s+)[0-9.]+", r"\g<1>{0}.0".format(argv[1]), src, re.MULTILINE)
+ f_.write(src)
+ f_.truncate()
+
+ with open(doxyfile, "r+") as f_:
+ src = f_.read()
+ f_.seek(0)
+ src = re.sub(r"(PROJECT_NUMBER\s+=\s+v)[0-9.]+", r"\g<1>{0}".format(argv[1]), src, re.MULTILINE)
+ f_.write(src)
+ f_.truncate()
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/tests/simplegame.cpp b/tests/simplegame.cpp
index 08f9f8c5..d4c7b266 100644
--- a/tests/simplegame.cpp
+++ b/tests/simplegame.cpp
@@ -22,13 +22,7 @@ int main()
window.create("Simple Game", 800, 640);
SpriteBatch sp;
- program.compileShaders(
- "/home/yannherklotz/Github/YAGE/resources/defaultshader.vert",
- "/home/yannherklotz/Github/YAGE/resources/defaultshader.frag");
- program.addAttribute("vertex_position");
- program.addAttribute("vertex_colour");
- program.addAttribute("vertex_uv");
- program.linkShaders();
+ program.defaultSetup();
Texture fountain =
ResourceManager::getTexture("/home/yannherklotz/Github/YAGE/tests/"
diff --git a/yage/core/glslprogram.cpp b/yage/core/glslprogram.cpp
index 769eb4eb..c47de808 100644
--- a/yage/core/glslprogram.cpp
+++ b/yage/core/glslprogram.cpp
@@ -17,7 +17,7 @@ namespace yage
GlslProgram::~GlslProgram()
{
- // cleanup all the shaders and the program
+ /// cleans up all the shaders and the program
if (fragment_shader_id_ != 0) {
glDeleteShader(fragment_shader_id_);
}
@@ -31,26 +31,11 @@ GlslProgram::~GlslProgram()
}
}
-void GlslProgram::compileShader(const GLuint &shader,
- const std::string &file_path)
+void GlslProgram::compileShader(GLuint shader, const std::string &shaderContent)
{
- // get a string with the input from the shader file
- std::ifstream file(file_path);
- if (!file.is_open()) {
- throw std::runtime_error("Failed to open '" + file_path + "'");
- }
-
- std::string content = "";
- std::string line;
-
- while (std::getline(file, line)) {
- content += line + "\n";
- }
- file.close();
-
// cast source to a c string to get the address of it and input it for
// compilation
- const auto *vertex_source = (const GLchar *)content.c_str();
+ const auto *vertex_source = (const GLchar *)shaderContent.c_str();
glShaderSource(shader, 1, &vertex_source, nullptr);
glCompileShader(shader);
@@ -67,13 +52,38 @@ void GlslProgram::compileShader(const GLuint &shader,
glGetShaderInfoLog(shader, max_length, &max_length, &error_log[0]);
std::string error_log_str((const char *)&error_log[0]);
- throw std::runtime_error("Couldn't compile " + file_path + " : " +
+ std::string shaderName;
+ if (shader == vertex_shader_id_)
+ shaderName = "vertex shader";
+ else
+ shaderName = "fragment shader";
+
+ throw std::runtime_error("Couldn't compile the " + shaderName + " : " +
error_log_str);
}
}
-void GlslProgram::compileShaders(const std::string &vertex_shader_path,
- const std::string &fragment_shader_path)
+void GlslProgram::compileShaderFromFile(GLuint shader,
+ const std::string &file_path)
+{
+ // get a string with the input from the shader file
+ std::ifstream file(file_path);
+ if (!file.is_open()) {
+ throw std::runtime_error("Failed to open '" + file_path + "'");
+ }
+
+ std::string content = "";
+ std::string line;
+
+ while (std::getline(file, line)) {
+ content += line + "\n";
+ }
+ file.close();
+
+ compileShader(shader, content);
+}
+
+void GlslProgram::initShaderId()
{
// create the program that will be run on GPU
program_id_ = glCreateProgram();
@@ -89,10 +99,26 @@ void GlslProgram::compileShaders(const std::string &vertex_shader_path,
if (fragment_shader_id_ == 0) {
throw std::runtime_error("Fragment shader failed to be created");
}
+}
+
+void GlslProgram::compileShaders(const std::string &vertexShader,
+ const std::string fragmentShader)
+{
+ initShaderId();
+
+ compileShader(vertex_shader_id_, vertexShader);
+ compileShader(fragment_shader_id_, fragmentShader);
+}
+
+void GlslProgram::compileShadersFromFile(
+ const std::string &vertex_shader_path,
+ const std::string &fragment_shader_path)
+{
+ initShaderId();
// compile the two shaders
- compileShader(vertex_shader_id_, vertex_shader_path);
- compileShader(fragment_shader_id_, fragment_shader_path);
+ compileShaderFromFile(vertex_shader_id_, vertex_shader_path);
+ compileShaderFromFile(fragment_shader_id_, fragment_shader_path);
}
void GlslProgram::linkShaders()
@@ -159,6 +185,31 @@ void GlslProgram::unuse()
glUseProgram(0);
}
-void GlslProgram::defaultSetup() {}
+void GlslProgram::defaultSetup()
+{
+ std::string vertexShader =
+ "#version 130\n\nin vec2 vertex_position;\nin vec4 vertex_colour;\nin "
+ "vec2 vertex_uv;\n\nout vec2 fragment_position;\nout vec4 "
+ "fragment_colour;\nout vec2 fragment_uv;\n\nuniform mat4 P;\n\nvoid "
+ "main()\n{\n gl_Position.xy = (P*vec4(vertex_position, 0.0, "
+ "1.0)).xy;\n gl_Position.z = 0.0;\n gl_Position.w = 1.0;\n\n "
+ "fragment_position = vertex_position;\n fragment_colour = "
+ "vertex_colour;\n fragment_uv = vec2(vertex_uv.x, "
+ "1-vertex_uv.y);\n\n}";
+
+ std::string fragmentShader =
+ "#version 130\n\nin vec2 fragment_position;\nin vec4 "
+ "fragment_colour;\nin vec2 fragment_uv;\n\nout vec4 colour;\n\nuniform "
+ "sampler2D texture_sampler;\n\nvoid main()\n{\n vec4 texture_color "
+ "= texture(texture_sampler, fragment_uv);\n\n colour = "
+ "texture_color;\n}";
+
+ compileShaders(vertexShader, fragmentShader);
+ addAttribute("vertex_position");
+ addAttribute("vertex_colour");
+ addAttribute("vertex_uv");
+
+ linkShaders();
+}
} // namespace yage
diff --git a/yage/core/glslprogram.h b/yage/core/glslprogram.h
index 729ed427..9e49d329 100644
--- a/yage/core/glslprogram.h
+++ b/yage/core/glslprogram.h
@@ -28,8 +28,10 @@ public:
GlslProgram &operator=(GlslProgram &&) = delete;
/// compiles vertex and fragment shader
- void compileShaders(const std::string &vertex_shader_path,
- const std::string &fragment_shader_path);
+ void compileShaders(const std::string &vertexShader,
+ const std::string fragmentShader);
+ void compileShadersFromFile(const std::string &vertex_shader_path,
+ const std::string &fragment_shader_path);
void linkShaders();
void addAttribute(const std::string &attribute_name);
GLint getUniformLocation(const std::string &uniform_name);
@@ -46,7 +48,9 @@ private:
int attribute_index_ = 0;
/// compiles one shader
- void compileShader(const GLuint &shader, const std::string &file_path);
+ void compileShader(GLuint shader, const std::string &shaderContent);
+ void compileShaderFromFile(GLuint shader, const std::string &file_path);
+ void initShaderId();
};
} // namespace yage
diff --git a/yage/yage.h b/yage/yage.h
index 36729214..3dd27eb8 100644
--- a/yage/yage.h
+++ b/yage/yage.h
@@ -15,7 +15,6 @@
#define YAGE_YAGE_H
#include "core/camera2d.h"
-#include "core/defaultfile.h"
#include "core/glslprogram.h"
#include "core/imageloader.h"
#include "core/inputmanager.h"