aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simplegame
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-24 21:04:38 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-24 21:04:38 +0000
commit16915d86d4b866c1fcce7523b0d34e8343ff52fc (patch)
treefdc07bff71840f7336ed5d2e751155635e8ff96a /examples/simplegame
parentddd26ed83d3ac0335562f762ced273a1d62bd959 (diff)
downloadYAGE-16915d86d4b866c1fcce7523b0d34e8343ff52fc.tar.gz
YAGE-16915d86d4b866c1fcce7523b0d34e8343ff52fc.zip
[Code] Simple game example furthered
Diffstat (limited to 'examples/simplegame')
-rw-r--r--examples/simplegame/dngn_blood_fountain.pngbin955 -> 0 bytes
-rw-r--r--examples/simplegame/main.cpp32
-rw-r--r--examples/simplegame/textureshader.frag16
-rw-r--r--examples/simplegame/textureshader.vert23
4 files changed, 21 insertions, 50 deletions
diff --git a/examples/simplegame/dngn_blood_fountain.png b/examples/simplegame/dngn_blood_fountain.png
deleted file mode 100644
index 7214fd47..00000000
--- a/examples/simplegame/dngn_blood_fountain.png
+++ /dev/null
Binary files differ
diff --git a/examples/simplegame/main.cpp b/examples/simplegame/main.cpp
index a631e45b..06200661 100644
--- a/examples/simplegame/main.cpp
+++ b/examples/simplegame/main.cpp
@@ -17,17 +17,19 @@ using namespace yage;
int main()
{
Window window;
- GlslProgram program;
+ GlslProgram textureProgram;
window.create("Simple Game", 800, 640);
SpriteBatch sp;
- program.compileShadersFromFile("examples/simplegame/textureshader.vert",
- "examples/simplegame/textureshader.frag");
- program.linkShaders();
+ textureProgram.compileShadersFromFile("examples/resources/textureshader.vert",
+ "examples/resources/textureshader.frag");
+ textureProgram.linkShaders();
Texture fountain = ResourceManager::getTexture(
- "examples/simplegame/dngn_blood_fountain.png");
+ "examples/resources/dngn_blood_fountain.png");
+ Texture breast_plate =
+ ResourceManager::getTexture("examples/resources/breast_black.png");
cout << "texture: " << fountain.width << ", " << fountain.height << '\n';
@@ -35,23 +37,31 @@ int main()
while (!window.shouldClose()) {
window.clearBuffer();
+ Texture texture = fountain;
- program.use();
- camera.update(program);
+ window.pollEvents();
+ if (window.keyPressed(yage::key::SPACE)) {
+ cout << "Pressed A" << '\n';
+ }
+ if (window.keyPressed(yage::key::E)) {
+ texture = breast_plate;
+ }
+
+ textureProgram.use();
+ camera.update(textureProgram);
glActiveTexture(GL_TEXTURE0);
- GLint texture_location = program.getUniformLocation("texture_sampler");
+ GLint texture_location = textureProgram.getUniformLocation("texture_sampler");
glUniform1i(texture_location, 0);
- sp.draw({0.f, 0.f, 64.f, 64.f}, {0, 0, 1, 1}, fountain.id,
+ sp.draw({0.f, 0.f, 64.f, 64.f}, {0, 0, 1, 1}, texture.id,
Colour(255, 0, 255, 255), 0);
sp.render();
glBindTexture(GL_TEXTURE_2D, 0);
- program.unuse();
+ textureProgram.unuse();
window.swapBuffer();
- window.pollEvents();
}
}
diff --git a/examples/simplegame/textureshader.frag b/examples/simplegame/textureshader.frag
deleted file mode 100644
index ef728b04..00000000
--- a/examples/simplegame/textureshader.frag
+++ /dev/null
@@ -1,16 +0,0 @@
-#version 450
-
-layout(location = 0) in vec2 fragment_position;
-layout(location = 1) in vec4 fragment_colour;
-layout(location = 2) in vec2 fragment_uv;
-
-out vec4 colour;
-
-uniform sampler2D texture_sampler;
-
-void main()
-{
- vec4 texture_color = texture(texture_sampler, fragment_uv);
-
- colour = texture_color * fragment_colour;
-}
diff --git a/examples/simplegame/textureshader.vert b/examples/simplegame/textureshader.vert
deleted file mode 100644
index 3277d8b0..00000000
--- a/examples/simplegame/textureshader.vert
+++ /dev/null
@@ -1,23 +0,0 @@
-#version 450
-
-layout(location = 0) in vec2 vertex_position;
-layout(location = 1) in vec4 vertex_colour;
-layout(location = 2) in vec2 vertex_uv;
-
-layout(location = 0) out vec2 fragment_position;
-layout(location = 1) out vec4 fragment_colour;
-layout(location = 2) out vec2 fragment_uv;
-
-uniform mat4 P;
-
-void main()
-{
- gl_Position.xy = (P*vec4(vertex_position, 0.0, 1.0)).xy;
- gl_Position.z = 0.0;
- gl_Position.w = 1.0;
-
- fragment_position = vertex_position;
- fragment_colour = vertex_colour;
- fragment_uv = vec2(vertex_uv.x, 1-vertex_uv.y);
-
-}