textured boob
This commit is contained in:
parent
d29f25bc86
commit
699c9aa4ad
8 changed files with 165 additions and 0 deletions
BIN
resources/client/fonts/scape.bmp
Normal file
BIN
resources/client/fonts/scape.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 MiB |
BIN
resources/client/fonts/scape.dat
Normal file
BIN
resources/client/fonts/scape.dat
Normal file
Binary file not shown.
79
src/client/ui/text.cpp
Normal file
79
src/client/ui/text.cpp
Normal file
|
@ -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<uint32_t>(data, 0x08);
|
||||||
|
this->cell_height = sosc::net::ntohv<uint32_t>(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 //
|
||||||
|
|
58
src/client/ui/text.hpp
Normal file
58
src/client/ui/text.hpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef SOSC_UI_TEXT_H
|
||||||
|
#define SOSC_UI_TEXT_H
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GLM/glm.hpp>
|
||||||
|
#include <SDL_image.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#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
|
4
src/client/views/ortho.cpp
Normal file
4
src/client/views/ortho.cpp
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
//
|
||||||
|
// Created by alec on 8/28/2018.
|
||||||
|
//
|
||||||
|
|
12
src/client/views/ortho.hpp
Normal file
12
src/client/views/ortho.hpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef SOSC_VIEW_ORTHO_H
|
||||||
|
#define SOSC_VIEW_ORTHO_H
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GLM/glm.hpp>
|
||||||
|
#include <GLM/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
void setup_ortho_mode();
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
1
src/client/views/projection.cpp
Normal file
1
src/client/views/projection.cpp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#include "projection.hpp"
|
11
src/client/views/projection.hpp
Normal file
11
src/client/views/projection.hpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef SOSC_VIEW_PROJECTION_H
|
||||||
|
#define SOSC_VIEW_PROJECTION_H
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GLM/glm.hpp>
|
||||||
|
#include <GLM/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue