diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-06-01 07:57:25 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-06-01 07:57:25 -0400 |
commit | 11b8e727e04ed6095164bb826541409f88047625 (patch) | |
tree | a4fd635025564419cee686f75a0c80d1c62ba2fc | |
parent | 70eced563f3ba4d98ed0a7952a81b69903ed1803 (diff) |
font color fix
-rw-r--r-- | include/font.hpp | 14 | ||||
-rw-r--r-- | src/font.cpp | 37 | ||||
-rw-r--r-- | src/ui_menu.cpp | 2 | ||||
-rw-r--r-- | src/world.cpp | 197 |
4 files changed, 96 insertions, 154 deletions
diff --git a/include/font.hpp b/include/font.hpp index 7dc7fc6..0a6e38b 100644 --- a/include/font.hpp +++ b/include/font.hpp @@ -2,7 +2,6 @@ #define FONT_HPP_ #include <map> -#include <memory> #include <vector> #include <color.hpp> @@ -22,6 +21,17 @@ struct FT_Info { : tex(0) {} }; +struct DrawData { + GLuint tex; + Color color; + GLfloat verts[30]; + + DrawData(GLuint t, Color c, std::initializer_list<GLfloat> v) + : tex(t), color(c) { + std::copy(v.begin(), v.end(), verts); + } +}; + class FontSystem { private: static FT_Library ftLibrary; @@ -29,7 +39,7 @@ private: static std::string fontFamily; static std::map<int, std::vector<FT_Info>> fontData; - static std::vector<std::unique_ptr<GLfloat>> drawData; + static std::vector<DrawData> drawData; static int currentSize; static Color currentColor; diff --git a/src/font.cpp b/src/font.cpp index 3fdd928..a7df99a 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -6,7 +6,7 @@ FT_Library FontSystem::ftLibrary; FT_Face FontSystem::ftFace; std::string FontSystem::fontFamily; std::map<int, std::vector<FT_Info>> FontSystem::fontData; -std::vector<std::unique_ptr<GLfloat>> FontSystem::drawData; +std::vector<DrawData> FontSystem::drawData; int FontSystem::currentSize = 0; Color FontSystem::currentColor; float FontSystem::currentZ = -8.0f; @@ -82,17 +82,19 @@ vec2 FontSystem::putChar(float x, float y, char c) vec2 c1 (static_cast<float>(floor(x) + ch.bl.x), static_cast<float>(floor(y) + ch.bl.y)); vec2 c2 (c1.x + ch.wh.x, c1.y - ch.wh.y); - GLfloat verts[31] = { - static_cast<GLfloat>(ch.tex), - c1.x, c1.y, currentZ, 0, 0, - c2.x, c1.y, currentZ, 1, 0, - c2.x, c2.y, currentZ, 1, 1, - c2.x, c2.y, currentZ, 1, 1, - c1.x, c2.y, currentZ, 0, 1, - c1.x, c1.y, currentZ, 0, 0, - }; - - drawData.emplace_back(reinterpret_cast<GLfloat*>(std::memcpy(new GLfloat[31], verts, 31 * sizeof(GLfloat)))); + drawData.push_back( DrawData { + ch.tex, + currentColor, + { + c1.x, c1.y, currentZ, 0, 0, + c2.x, c1.y, currentZ, 1, 0, + c2.x, c2.y, currentZ, 1, 1, + c2.x, c2.y, currentZ, 1, 1, + c1.x, c2.y, currentZ, 0, 1, + c1.x, c1.y, currentZ, 0, 0, + } + }); + return ch.ad; } @@ -101,14 +103,13 @@ void FontSystem::render(void) Render::textShader.use(); Render::textShader.enable(); - glUniform4f(Render::textShader.uniform[WU_tex_color], - currentColor.red, currentColor.green, currentColor.blue, currentColor.alpha); - for (const auto& d : drawData) { + glUniform4f(Render::textShader.uniform[WU_tex_color], + d.color.red, d.color.green, d.color.blue, d.color.alpha); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(d.get()[0])); - glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), d.get() + 1); - glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), d.get() + 4); + glBindTexture(GL_TEXTURE_2D, d.tex); + glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), d.verts); + glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), d.verts + 3); glDrawArrays(GL_TRIANGLES, 0, 6); } diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index 138a281..11c10a7 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -297,7 +297,6 @@ namespace ui { break; } - SDLReceiver::clicked = false; } } @@ -365,6 +364,7 @@ namespace ui { } } + SDLReceiver::clicked = false; FontSystem::setFontSize(16); FontSystem::setFontZ(-8.0); } diff --git a/src/world.cpp b/src/world.cpp index 80c92fb..fb2e5f5 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -72,18 +72,6 @@ constexpr const char* bgPaths[1][8] = { } }; -// pathnames of structure textures -constexpr const char* buildPaths[] = { - "townhall.png", - "house1.png", - "house2.png", - "house1.png", - "house1.png", - "fountain1.png", - "lampPost1.png", - "brazzier.png" -}; - /* ---------------------------------------------------------------------------- ** Functions section ** --------------------------------------------------------------------------*/ @@ -614,6 +602,11 @@ void WorldSystem::render(void) thAmbient.detach(); }); + auto push5 = [](GLfloat *&vec, GLfloat *five) { + for (int i = 0; i < 5; i++) + *vec++ = *five++; + }; + // shade value for GLSL float shadeAmbient = std::max(0.0f, static_cast<float>(-worldShade) / 50 + 0.5f); // 0 to 1.5f @@ -621,34 +614,20 @@ void WorldSystem::render(void) shadeAmbient = 1; // TODO scroll backdrop - //GLfloat bgOff = game::time::getTickCount() / static_cast<float>(DAY_CYCLE * 2); - GLfloat bgOff = -0.5f * cos(PI / DAY_CYCLE * game::time::getTickCount()) + 0.5f; - - static const vec2 bg_tex_coord[] = { - vec2(0.0f, 0.0f), - vec2(1.0f, 0.0f), - vec2(1.0f, 1.0f), - - vec2(1.0f, 1.0f), - vec2(0.0f, 1.0f), - vec2(0.0f, 0.0f) - }; - - GLfloat bottomS = bgOff; - if (bottomS < 0.0f) - bottomS += 1.0f; - - GLfloat farBack[] = { - offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, 0, bottomS, - offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f, 1, bottomS, - offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, 1, bottomS, - offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, 1, bottomS, - offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f, 0, bottomS, - offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, 0, bottomS + GLfloat skyOffset = -0.5f * cos(PI / DAY_CYCLE * game::time::getTickCount()) + 0.5f; + if (skyOffset < 0) + skyOffset++; + + GLfloat skyverts[] = { + offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, 0, skyOffset, + offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f, 1, skyOffset, + offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, 1, skyOffset, + offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, 1, skyOffset, + offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f, 0, skyOffset, + offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, 0, skyOffset, }; // rendering!! - glActiveTexture(GL_TEXTURE0); Render::worldShader.use(); glUniform1i(Render::worldShader.uniform[WU_texture], 0); @@ -661,8 +640,8 @@ void WorldSystem::render(void) bgTex(0); glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0); - glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), farBack); - glVertexAttribPointer(Render::worldShader.tex , 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), farBack + 3); + glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), skyverts); + glVertexAttribPointer(Render::worldShader.tex , 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), skyverts + 3); glDrawArrays(GL_TRIANGLES, 0, 6); if (worldShade > 0) { @@ -696,108 +675,68 @@ void WorldSystem::render(void) delete[] star_coord; } - Render::worldShader.disable(); - glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0); glUniform4f(Render::worldShader.uniform[WU_ambient], ambient.red, ambient.green, ambient.blue, 1.0); - Render::worldShader.unuse(); - - std::vector<vec3> bg_items; - std::vector<vec2> bg_tex; - - bgTex++; - auto mountainDim = bgTex.getTextureDim(); - mountainDim.x = HLINES(mountainDim.x); - mountainDim.y = HLINES(mountainDim.y); - auto xcoord = width / 2 * -1 + offset.x * 0.85f; - for (int i = 0; i <= width / mountainDim.x; i++) { - bg_items.emplace_back(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f); - bg_items.emplace_back(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f); - bg_items.emplace_back(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f); - - bg_items.emplace_back(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f); - bg_items.emplace_back(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f); - bg_items.emplace_back(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f); - } - - for (uint i = 0; i < bg_items.size()/6; i++) { - for (auto &v : bg_tex_coord) - bg_tex.push_back(v); - } - - Render::worldShader.use(); - glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.01); - - Render::worldShader.enable(); - - glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, &bg_items[0]); - glVertexAttribPointer(Render::worldShader.tex , 2, GL_FLOAT, GL_FALSE, 0, &bg_tex[0]); - glDrawArrays(GL_TRIANGLES, 0, bg_items.size()); - Render::worldShader.disable(); - - Render::worldShader.unuse(); - // draw the remaining layers - static const float alphas[4] = { - 0.6, 0.4, 0.25, 0.1 + constexpr float parallax[5] = { + 0.85f, 0.60f, 0.40f, 0.25f, 0.10f }; - for (int i = 0; i < 4; i++) { + float z = 8.0f; + for (int i = 0; i < 5; i++, z -= 0.1f) { bgTex++; - auto xcoord = offset.x * alphas[i]; - - bg_items.clear(); - bg_tex.clear(); - - vec2 dim = bgTex.getTextureDim() * game::HLINE; - - if (world.indoor && i == 3) { - world.indoorTex.use(); - - const auto& startx = world.startX; - dim = world.indoorTex.getDim() * game::HLINE; + auto mountainDim = bgTex.getTextureDim() * game::HLINE; + auto xcoord = width / 2 * -1 + offset.x * parallax[i]; - bg_items.emplace_back(startx, GROUND_HEIGHT_MINIMUM, 7 - (i * 0.1f)); - bg_items.emplace_back(startx + dim.x, GROUND_HEIGHT_MINIMUM, 7 - (i * 0.1f)); - bg_items.emplace_back(startx + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, 7 - (i * 0.1f)); + int count = width / mountainDim.x + 1; + GLfloat* bgItems = new GLfloat[count * 30]; + GLfloat* bgItemsFront = bgItems; - bg_items.emplace_back(startx + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, 7 - (i * 0.1f)); - bg_items.emplace_back(startx, GROUND_HEIGHT_MINIMUM + dim.y, 7 - (i * 0.1f)); - bg_items.emplace_back(startx, GROUND_HEIGHT_MINIMUM, 7 - (i * 0.1f)); - } else { - for (int j = world.startX; j <= -world.startX; j += dim.x) { - bg_items.emplace_back(j + xcoord, GROUND_HEIGHT_MINIMUM, 7 - (i * 0.1f)); - bg_items.emplace_back(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM, 7 - (i * 0.1f)); - bg_items.emplace_back(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7 - (i * 0.1f)); - - bg_items.emplace_back(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7 - (i * 0.1f)); - bg_items.emplace_back(j + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7 - (i * 0.1f)); - bg_items.emplace_back(j + xcoord, GROUND_HEIGHT_MINIMUM, 7 - (i * 0.1f)); - } - } + for (int i = 0; i < count; i++) { + GLfloat five[5] = { + 0, 0, mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, z + }; - for (uint i = 0; i < bg_items.size() / 6; i++) { - for (auto &v : bg_tex_coord) - bg_tex.push_back(v); + push5(bgItemsFront, five); + five[0]++, five[2] += mountainDim.x; + push5(bgItemsFront, five); + five[1]++, five[3] += mountainDim.y; + push5(bgItemsFront, five); + push5(bgItemsFront, five); + five[0]--, five[2] -= mountainDim.x; + push5(bgItemsFront, five); + five[1]--, five[3] -= mountainDim.y; + push5(bgItemsFront, five); } - Render::worldShader.use(); - glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.075f + (0.2f * i)); + glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.01); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), bgItems + 2); + glVertexAttribPointer(Render::worldShader.tex , 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), bgItems); + glDrawArrays(GL_TRIANGLES, 0, count * 6); - Render::worldShader.enable(); + delete[] bgItems; + } - glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, bg_items.data()); - glVertexAttribPointer(Render::worldShader.tex , 2, GL_FLOAT, GL_FALSE, 0, &bg_tex[0]); - glDrawArrays(GL_TRIANGLES, 0, bg_items.size()); + if (world.indoor) { + world.indoorTex.use(); + auto dim = world.indoorTex.getDim() * game::HLINE; + GLfloat verts[] = { + world.startX, GROUND_HEIGHT_MINIMUM, z - 0.1f, 0, 0, + world.startX + dim.x, GROUND_HEIGHT_MINIMUM, z - 0.1f, 1, 0, + world.startX + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, z - 0.1f, 1, 1, + world.startX + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, z - 0.1f, 1, 1, + world.startX, GROUND_HEIGHT_MINIMUM + dim.y, z - 0.1f, 0, 1, + world.startX, GROUND_HEIGHT_MINIMUM, z - 0.1f, 0, 0, + }; - Render::worldShader.disable(); - Render::worldShader.unuse(); + glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts); + glVertexAttribPointer(Render::worldShader.tex , 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts + 3); + glDrawArrays(GL_TRIANGLES, 0, 6); } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + //glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.075f + (0.2f * i)); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // get the line that the player is currently standing on pOffset = (offset.x - world.startX) / game::HLINE; @@ -819,11 +758,6 @@ void WorldSystem::render(void) dirt.resize(world.data.size() * 30); } - auto push5 = [](GLfloat *&vec, GLfloat *five) { - for (int i = 0; i < 5; i++) - *vec++ = *five++; - }; - GLfloat *dirtp = &dirt[0]; for (int i = iStart; i < iEnd; i++) { if (world.data[i].groundHeight <= 0) { // TODO holes (andy) TODO TODO TODO @@ -854,11 +788,8 @@ void WorldSystem::render(void) world.data[i].groundHeight = 0; } - Render::worldShader.use(); glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.45f); - Render::worldShader.enable(); - glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &dirt[2]); glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &dirt[0]); glDrawArrays(GL_TRIANGLES, 0 , dirt.size() / 5); |