aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-08 01:23:27 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-08 01:23:27 +0000
commite6215e764bc149497ab5772d9ea136809d898993 (patch)
treebe10db001a2d4eedd611c7db2c5cf7907f55250c
parent4738752fd7633f68911f97aeda9954ee87b5ce6e (diff)
downloadYAGE-e6215e764bc149497ab5772d9ea136809d898993.tar.gz
YAGE-e6215e764bc149497ab5772d9ea136809d898993.zip
Improving api
-rw-r--r--.travis.yml71
-rw-r--r--CMakeLists.txt6
-rw-r--r--lib/CMakeLists.txt2
-rw-r--r--resources/defaultshader.vert1
-rw-r--r--tests/simplegame.cpp36
-rw-r--r--yage/core/camera2d.cpp8
-rw-r--r--yage/core/spritebatch.cpp19
-rw-r--r--yage/core/spritebatch.h1
8 files changed, 89 insertions, 55 deletions
diff --git a/.travis.yml b/.travis.yml
index 3bfce596..2a142f41 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,39 +1,48 @@
-language: cpp
-dist: trusty
-branches:
- only:
- - master
- - develop
-notifications:
- email: false
-git:
- depth: 1
-matrix:
- include:
- - os: linux
- env: UNIT_TESTS=1
- compiler: g++-6
-script:
-- g++-6 --version
-- cd $TRAVIS_BUILD_DIR
-- mkdir -p build
-- cd build
-- cmake ..
-- make
-- ctest
-- cd .. && ./scripts/update_docs
-addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- packages:
+---
+addons:
+ apt:
+ packages:
- g++-6
+ - gcc-6
+ - g++-7
+ - gcc-7
- libegl1-mesa-dev
- libgles2-mesa-dev
- libglm-dev
- xorg-dev
- libglu1-mesa-dev
- doxygen
-env:
- global:
+ sources:
+ - ubuntu-toolchain-r-test
+branches:
+ only:
+ - master
+ - develop
+dist: trusty
+env:
+ global:
secure: NGWn7hJAd/iYfJQmr8oDjTlwttldj8zB+X0gk2TqDhAJ2gLiZ2+b8Bp5FSzBlNIyhcbuhzRU+rzkbo03XSwXZXFRZK/gyPMGaB75ay8MLQBrN3L7THXbjQm1SZg2mO17/MKT+rJH/NvhmqPoUoJaYnoki1G6AZfhnDx+3bW4MNp5/g3u8trk1HNvXWTvjdqS99OH36bvoq8BsOi53Po1veeCIWza6JO61n2nRHzCC2sYWtsZyTQSi3B//iie5zF3gvuRorbzjA/ayc8lLmhUsTmoA1t9HJP52fKzv/q3mxllXzyzpWNRmUJCzf7I1wY9jp1FVwojfl0umofzYPCCjwSrKlRtmwQfi0peg7VOJVCCJx7Eh/i0hamGUnDEu0aZnfhgwzkqDDIgO1AwcEv5i9egt/73kK4mdm22sEDa3dWVu37tnj5dItaQesMm6TXKMy9+r7v0aaVJbQB2atvBaf3RlW71P9iy8mOZ+geKNwVFRuBdu5g3oQe5QrqXRi4inMv0bjN8HwOVs/f8ZTGZePnbHnxOnYRErxLnha/bsu7btfDT8Q8nmZ/Rhcu7QkMRNTm5L3+YHFUngiIygOs8wrH6HECtSYwmi9WejRuPgU2GnYR0Rzyi5dyaFok1iN+jsYsY9YFx5tRgxuX4H9CnUlfDabdFSLzqbmKRlbP79as=
+git:
+ depth: 1
+language: cpp
+matrix:
+ include:
+ -
+ compiler: g++-6
+ env: UNIT_TESTS=1
+ os: linux
+ -
+ compiler: g++-7
+ env: UNIT_TESTS=1
+ os: linux
+notifications:
+ email: false
+script:
+ - "g++-6 --version"
+ - "cd $TRAVIS_BUILD_DIR"
+ - "mkdir -p build"
+ - "cd build"
+ - "cmake .."
+ - make
+ - ctest
+ - "cd .. && ./scripts/update_docs"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c5e13ab4..08b9ec36 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,6 +5,10 @@ project(yage
VERSION 0.1.1.0
LANGUAGES CXX)
+if(NOT DEFINED UNIT_TESTS)
+ set(UNIT_TESTS 0)
+endif()
+
# set standard
set(CMAKE_CXX_STANDARD 14)
@@ -23,7 +27,7 @@ find_package(OpenGL REQUIRED)
include(${CMAKE_CURRENT_SOURCE_DIR}/lib/CMakeLists.txt)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/yage)
-if($ENV{UNIT_TESTS})
+if(UNIT_TESTS)
add_executable(simplegame tests/simplegame.cpp)
target_link_libraries(simplegame yage)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index fd89d4f2..017e8206 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -7,7 +7,7 @@
set(LIBRARY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
-if($ENV{UNIT_TESTS})
+if(UNIT_TESTS)
# Initializing google test
# prevents overriding the parent project's compiler/linter settings on windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
diff --git a/resources/defaultshader.vert b/resources/defaultshader.vert
index d591e4bf..2eba9bcf 100644
--- a/resources/defaultshader.vert
+++ b/resources/defaultshader.vert
@@ -19,4 +19,5 @@ void main()
fragment_position = vertex_position;
fragment_colour = vertex_colour;
fragment_uv = vec2(vertex_uv.x, 1-vertex_uv.y);
+
}
diff --git a/tests/simplegame.cpp b/tests/simplegame.cpp
index 54ead815..2968f4ba 100644
--- a/tests/simplegame.cpp
+++ b/tests/simplegame.cpp
@@ -8,32 +8,54 @@
#include <yage.cpp>
+#include <iostream>
+
+using std::cout;
+
using namespace yage;
int main()
{
Window window;
- SpriteBatch sp;
GlslProgram program;
window.create("Simple Game", 800, 640);
- sp.init();
+ SpriteBatch sp;
- program.compileShaders("/home/yannherklotz/Github/YAGE/resources/defaultshader.vert", "/home/yannherklotz/Github/YAGE/tests/resources/defaultshader.frag");
+ 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();
- Texture fountain = ResourceManager::getTexture("/home/yannherklotz/Github/YAGE/tests/resources/dngn_blood_fountain.png");
+ Texture fountain =
+ ResourceManager::getTexture("/home/yannherklotz/Github/YAGE/tests/"
+ "resources/dngn_blood_fountain.png");
+
+ cout << "texture: " << fountain.width << ", " << fountain.height << '\n';
- while(!window.shouldClose()) {
+ Camera2D camera(800, 640);
+
+ while (!window.shouldClose()) {
window.clearBuffer();
- sp.begin();
- sp.draw(std::vector<float>({0, 0, 50, 50}), std::vector<float>({0, 0, 1, 1}), fountain.id, Colour(), 0);
+ program.use();
+ camera.update(program);
+
+ glActiveTexture(GL_TEXTURE0);
+
+ GLint texture_location = program.getUniformLocation("texture_sampler");
+ glUniform1i(texture_location, 0);
+
+ sp.draw(std::vector<float>({0, 0, 64, 64}),
+ std::vector<float>({0, 0, 1, 1}), fountain.id, Colour(), 0);
sp.render();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ program.unuse();
+
window.pollEvents();
window.swapBuffer();
}
diff --git a/yage/core/camera2d.cpp b/yage/core/camera2d.cpp
index 52c5c50f..d5640c3f 100644
--- a/yage/core/camera2d.cpp
+++ b/yage/core/camera2d.cpp
@@ -6,14 +6,6 @@
* ----------------------------------------------------------------------------
*/
-/* ----------------------------------------------------------------------------
- * camera2d.cpp
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
#include "camera2d.h"
#include <glad/glad.h>
diff --git a/yage/core/spritebatch.cpp b/yage/core/spritebatch.cpp
index 00673c08..98213467 100644
--- a/yage/core/spritebatch.cpp
+++ b/yage/core/spritebatch.cpp
@@ -30,7 +30,10 @@ RenderBatch::RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture)
{
}
-SpriteBatch::SpriteBatch() = default;
+SpriteBatch::SpriteBatch()
+{
+ createVertexArray();
+}
SpriteBatch::~SpriteBatch()
{
@@ -43,11 +46,6 @@ SpriteBatch::~SpriteBatch()
}
}
-void SpriteBatch::init()
-{
- createVertexArray();
-}
-
void SpriteBatch::begin()
{
glyphs_.clear();
@@ -94,12 +92,21 @@ void SpriteBatch::draw(const yage::Vector4f &destination_rect,
void SpriteBatch::render()
{
+ // sort and create render batches
+ sortGlyphs();
+ createRenderBatches();
+
glBindVertexArray(vao_);
for (auto &&batch : render_batches_) {
glBindTexture(GL_TEXTURE_2D, batch.texture());
glDrawArrays(GL_TRIANGLES, batch.offset(), batch.num_vertices());
}
glBindVertexArray(0);
+
+ // clear and reset the vectors
+ glyphs_.clear();
+ glyph_ptrs_.clear();
+ render_batches_.clear();
}
void SpriteBatch::createVertexArray()
diff --git a/yage/core/spritebatch.h b/yage/core/spritebatch.h
index 9ec7cffb..d90d6d05 100644
--- a/yage/core/spritebatch.h
+++ b/yage/core/spritebatch.h
@@ -89,7 +89,6 @@ public:
SpriteBatch &operator=(SpriteBatch &&) = delete;
// initialize vaos and vbos
- void init();
void begin();
void end();