diff --git a/resources/client/fonts/scape.bmp b/resources/client/fonts/scape.bmp new file mode 100644 index 0000000..f5752e0 Binary files /dev/null and b/resources/client/fonts/scape.bmp differ diff --git a/resources/client/fonts/scape.dat b/resources/client/fonts/scape.dat new file mode 100644 index 0000000..5d0a857 Binary files /dev/null and b/resources/client/fonts/scape.dat differ diff --git a/src/client/ui/text.cpp b/src/client/ui/text.cpp new file mode 100644 index 0000000..f511576 --- /dev/null +++ b/src/client/ui/text.cpp @@ -0,0 +1,79 @@ +#include "text.hpp" + +// FONT CLASS // + +bool sosc::ui::Font::Load + (const std::string& filePath, const std::string& dataPath) +{ + if(this->loaded) + this->Unload(); + + SDL_RWops* rwop = SDL_RWFromFile(filePath.c_str(), "rb"); + this->image = SDL_LoadBMP_RW(rwop, 1); + if(!this->image) + return false; + + char buffer[0x111]; + std::ifstream dataFile(dataPath, std::ios::in | std::ios::binary); + if(!dataFile.is_open()) + return false; + dataFile.read(buffer, 0x111); + dataFile.close(); + std::string data(buffer, 0x111); + if(buffer[0x10] != 0) + return false; + + this->width = (uint32_t)this->image->w; + this->height = (uint32_t)this->image->h; + this->cell_width = sosc::net::ntohv(data, 0x08); + this->cell_height = sosc::net::ntohv(data, 0x0C); + + for(int i = 0; i < 256; ++i) { + auto glyph = &this->glyphs[i]; + auto width = (uint8_t)buffer[0x11 + i]; + + glyph->width = (double)width / (double)this->cell_width; + + int x = (this->cell_width * i) % this->width; + int y = ((this->cell_width * i) / this->width) * this->cell_height; + + glyph->top_left = glm::vec2( + (double)x / (double)this->width, + 1 - (double)y / (double)this->height + ); + glyph->top_right = glm::vec2( + (double)(x + width) / (double)this->width, + 1 - (double)y / (double)this->height + ); + glyph->bottom_left = glm::vec2( + (double)x / (double)this->width, + 1 - (double)(y + this->cell_height) / (double)this->height + ); + glyph->bottom_right = glm::vec2( + (double)(x + width) / (double)this->width, + 1 - (double)(y + this->cell_height) / (double)this->height + ); + } + + glGenTextures(1, &this->texture); + glBindTexture(GL_TEXTURE_2D, this->texture); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGBA, + this->width, this->height, 0, + (this->image->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB), + GL_UNSIGNED_BYTE, this->image->pixels + ); + glBindTexture(GL_TEXTURE_2D, 0); + + this->loaded = true; +} + +void sosc::ui::Font::Unload() { + glDeleteTextures(1, &this->texture); + SDL_FreeSurface(this->image); + + this->loaded = false; +} + +// TEXT CLASS // + diff --git a/src/client/ui/text.hpp b/src/client/ui/text.hpp new file mode 100644 index 0000000..593fdd8 --- /dev/null +++ b/src/client/ui/text.hpp @@ -0,0 +1,58 @@ +#ifndef SOSC_UI_TEXT_H +#define SOSC_UI_TEXT_H + +#include +#include +#include +#include + +#include +#include +#include "utils/net.hpp" + +namespace sosc { +namespace ui { +class Font { +public: + struct glyph_t { + double width; + glm::vec2 + top_left, + top_right, + bottom_left, + bottom_right; + }; + + Font() : loaded(false) {} + bool Load(const std::string& bitmapPath, const std::string& dataPath); + + inline const glyph_t& operator[] (char c) { + return this->glyphs[(uint8_t)c]; + } + + + + void Unload(); +private: + bool loaded; + GLuint texture; + SDL_Surface* image; + uint32_t + width, height, + cell_width, cell_height; + glyph_t glyphs[256]; +}; + +class Text { +public: + Text(Font* font) : loaded(false) {} + + +private: + Font* font; + GLuint vao, vbo[2]; + bool loaded; +}; +}} + +#endif diff --git a/src/client/views/ortho.cpp b/src/client/views/ortho.cpp new file mode 100644 index 0000000..c8555bb --- /dev/null +++ b/src/client/views/ortho.cpp @@ -0,0 +1,4 @@ +// +// Created by alec on 8/28/2018. +// + diff --git a/src/client/views/ortho.hpp b/src/client/views/ortho.hpp new file mode 100644 index 0000000..a410b40 --- /dev/null +++ b/src/client/views/ortho.hpp @@ -0,0 +1,12 @@ +#ifndef SOSC_VIEW_ORTHO_H +#define SOSC_VIEW_ORTHO_H + +#include +#include +#include +#include + +void setup_ortho_mode(); + + +#endif diff --git a/src/client/views/projection.cpp b/src/client/views/projection.cpp new file mode 100644 index 0000000..0a65187 --- /dev/null +++ b/src/client/views/projection.cpp @@ -0,0 +1 @@ +#include "projection.hpp" \ No newline at end of file diff --git a/src/client/views/projection.hpp b/src/client/views/projection.hpp new file mode 100644 index 0000000..e3ec9d8 --- /dev/null +++ b/src/client/views/projection.hpp @@ -0,0 +1,11 @@ +#ifndef SOSC_VIEW_PROJECTION_H +#define SOSC_VIEW_PROJECTION_H + +#include +#include +#include +#include + + + +#endif \ No newline at end of file