dialogging boob

This commit is contained in:
Alec Obradovich 2018-09-03 22:33:20 -05:00
parent 8f1662e862
commit 34539fff01
6 changed files with 48 additions and 40 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 MiB

After

Width:  |  Height:  |  Size: 48 MiB

View file

@ -6,10 +6,9 @@ uniform vec4 fontColor;
uniform sampler2D fontBitmap; uniform sampler2D fontBitmap;
void main() { void main() {
/*vec4 outColor = texture(fontBitmap, texCoords); vec4 outColor = texture(fontBitmap, texCoords);
if(outColor.xyz == vec3(0.0, 0.0, 0.0)) if(outColor.xyz == vec3(0.0, 0.0, 0.0))
discard;*/ discard;
//fragColor = fontColor * vec4(0, 1, 0, 1); fragColor = fontColor * outColor;
fragColor = vec4(0, 1, 0, 1);
} }

View file

@ -8,6 +8,6 @@ uniform mat4 transMatrix;
uniform mat4 orthoMatrix; uniform mat4 orthoMatrix;
void main() { void main() {
gl_Position = orthoMatrix * vec4(aScreenCoords, 1.0, 1.0); gl_Position = orthoMatrix * transMatrix * vec4(aScreenCoords, 1.0, 1.0);
texCoords = aTexCoords; texCoords = aTexCoords;
} }

View file

@ -61,20 +61,21 @@ int main(int argc, char* argv[]) {
); );
ui::font_set_default(&scapeFont); ui::font_set_default(&scapeFont);
ui::Text text(80, glm::vec4(1, 0, 0, 1), "test text", 0, 0); ui::Text text(75, glm::vec4(1, 0, 0, 1),
"test", 100, 100, 400);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
bool running = true; bool running = true;
while(running) { while(running) {
SDL_GL_SwapWindow(window);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1, 1, 1, 1); glClearColor(.25, .25, .25, 1);
text.Render(); text.Render();
SDL_GL_SwapWindow(window);
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&event)) { while(SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT) if(event.type == SDL_QUIT)

View file

@ -8,17 +8,20 @@
namespace sosc { namespace sosc {
namespace ui { namespace ui {
class FontShader;
}}
// STATE STRUCT // // STATE STRUCT //
class FontShader;
static struct { static struct {
sosc::ui::FontShader* shader; sosc::ui::FontShader* shader;
sosc::ui::Font* default_font; sosc::ui::Font* default_font;
glm::mat4 orthoMatrix;
} _font_ctx; } _font_ctx;
// FONT SHADER CLASS // // FONT SHADER CLASS //
namespace sosc {
namespace ui {
class FontShader : public sosc::shdr::Shader { class FontShader : public sosc::shdr::Shader {
public: public:
enum Uniforms { enum Uniforms {
@ -33,10 +36,11 @@ public:
int width, height; int width, height;
SDL_GetWindowSize(window, &width, &height); SDL_GetWindowSize(window, &width, &height);
_font_ctx.orthoMatrix = glm::ortho(0, width, height, 0); glm::mat4 orthoMatrix =
glm::ortho(0.f, (float)width, (float)height, 0.f);
glUniformMatrix4fv( glUniformMatrix4fv(
(*this)[ORTHO_MATRIX], 1, GL_FALSE, (*this)[ORTHO_MATRIX], 1, GL_FALSE,
glm::value_ptr(_font_ctx.orthoMatrix) glm::value_ptr(orthoMatrix)
); );
this->Stop(); this->Stop();
@ -87,7 +91,8 @@ void sosc::ui::font_deinit_subsystem() {
// FONT CLASS // // FONT CLASS //
sosc::ui::Font::Font sosc::ui::Font::Font
(const std::string& bitmapPath, const std::string& dataPath) (const std::string& bitmapPath, const std::string& dataPath,
bool useNearest)
{ {
this->loaded = false; this->loaded = false;
if(!this->Load(bitmapPath, dataPath)) if(!this->Load(bitmapPath, dataPath))
@ -95,14 +100,15 @@ sosc::ui::Font::Font
} }
bool sosc::ui::Font::Load bool sosc::ui::Font::Load
(const std::string& filePath, const std::string& dataPath) (const std::string& bitmapPath, const std::string& dataPath,
bool useNearest)
{ {
if(this->loaded) if(this->loaded)
this->Unload(); this->Unload();
SDL_RWops* rwop = SDL_RWFromFile(filePath.c_str(), "rb"); SDL_RWops* rwop = SDL_RWFromFile(bitmapPath.c_str(), "rb");
this->image = SDL_LoadBMP_RW(rwop, 1); SDL_Surface* image = SDL_LoadBMP_RW(rwop, 1);
if(!this->image) if(!image)
return false; return false;
char buffer[0x111]; char buffer[0x111];
@ -115,11 +121,11 @@ bool sosc::ui::Font::Load
if(buffer[0x10] != 0) if(buffer[0x10] != 0)
return false; return false;
this->width = (uint32_t)this->image->w; this->width = (uint32_t)image->w;
this->height = (uint32_t)this->image->h; this->height = (uint32_t)image->h;
this->cell_width = LILEND_UNPACK(buffer, 0x08); this->cell_width = LILEND_UNPACK(buffer, 0x08);
this->cell_width = LILEND_UNPACK(buffer, 0x0C); this->cell_height = LILEND_UNPACK(buffer, 0x0C);
for(int i = 0; i < 256; ++i) { for(int i = 0; i < 256; ++i) {
auto glyph = &this->glyphs[i]; auto glyph = &this->glyphs[i];
@ -151,25 +157,35 @@ bool sosc::ui::Font::Load
glGenTextures(1, &this->texture); glGenTextures(1, &this->texture);
glBindTexture(GL_TEXTURE_2D, this->texture); glBindTexture(GL_TEXTURE_2D, this->texture);
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, GL_TEXTURE_2D, 0, 3,
this->width, this->height, 0, this->width, this->height, 0,
(this->image->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB), GL_BGR,
GL_UNSIGNED_BYTE, this->image->pixels GL_UNSIGNED_BYTE, image->pixels
);
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
useNearest ? GL_NEAREST : GL_LINEAR
);
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
useNearest ? GL_NEAREST : GL_LINEAR
); );
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
SDL_FreeSurface(image);
this->loaded = true; this->loaded = true;
return true; return true;
} }
void sosc::ui::Font::BindBitmap() { void sosc::ui::Font::BindBitmap() const {
if(!this->loaded) if(!this->loaded)
return; return;
glBindTexture(GL_TEXTURE_2D, this->texture); glBindTexture(GL_TEXTURE_2D, this->texture);
} }
void sosc::ui::Font::UnbindBitmap() { void sosc::ui::Font::UnbindBitmap() const {
if(!this->loaded) if(!this->loaded)
return; return;
@ -178,7 +194,6 @@ void sosc::ui::Font::UnbindBitmap() {
void sosc::ui::Font::Unload() { void sosc::ui::Font::Unload() {
glDeleteTextures(1, &this->texture); glDeleteTextures(1, &this->texture);
SDL_FreeSurface(this->image);
this->loaded = false; this->loaded = false;
} }
@ -313,14 +328,6 @@ void sosc::ui::Text::Redraw() {
top_y += height; top_y += height;
} }
glm::vec4 result =
_font_ctx.orthoMatrix * glm::vec4(320.f, 240.f, 0.f, 1.f);
std::cout << "(" << result.x << "," << result.y
<< "," << result.z << "," << result.w << ")" << std::endl;
auto test = glm::to_string(_font_ctx.orthoMatrix);
std::cout << test << std::endl;
/// TRIANGLE 1 /// /// TRIANGLE 1 ///
// TOP LEFT // TOP LEFT
this->vertices[i*12] = top_x; this->vertices[i*12] = top_x;

View file

@ -54,8 +54,10 @@ public:
}; };
Font() : loaded(false) {} Font() : loaded(false) {}
Font(const std::string& bitmapPath, const std::string& dataPath); Font(const std::string& bitmapPath,
bool Load(const std::string& bitmapPath, const std::string& dataPath); const std::string& dataPath, bool useNearest = true);
bool Load(const std::string& bitmapPath,
const std::string& dataPath, bool useNearest = true);
inline const glyph_t& operator[] (char c) const { inline const glyph_t& operator[] (char c) const {
return this->glyphs[(uint8_t)c]; return this->glyphs[(uint8_t)c];
@ -63,12 +65,11 @@ public:
void Unload(); void Unload();
private: private:
void BindBitmap(); void BindBitmap() const;
void UnbindBitmap(); void UnbindBitmap() const;
bool loaded; bool loaded;
GLuint texture; GLuint texture;
SDL_Surface* image;
uint32_t uint32_t
width, height, width, height,
cell_width, cell_height; cell_width, cell_height;