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;
void main() {
/*vec4 outColor = texture(fontBitmap, texCoords);
vec4 outColor = texture(fontBitmap, texCoords);
if(outColor.xyz == vec3(0.0, 0.0, 0.0))
discard;*/
discard;
//fragColor = fontColor * vec4(0, 1, 0, 1);
fragColor = vec4(0, 1, 0, 1);
fragColor = fontColor * outColor;
}

View file

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

View file

@ -61,20 +61,21 @@ int main(int argc, char* argv[]) {
);
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_DEPTH_TEST);
bool running = true;
while(running) {
SDL_GL_SwapWindow(window);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1, 1, 1, 1);
glClearColor(.25, .25, .25, 1);
text.Render();
SDL_GL_SwapWindow(window);
SDL_Event event;
while(SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT)

View file

@ -8,17 +8,20 @@
namespace sosc {
namespace ui {
class FontShader;
}}
// STATE STRUCT //
class FontShader;
static struct {
sosc::ui::FontShader* shader;
sosc::ui::Font* default_font;
glm::mat4 orthoMatrix;
} _font_ctx;
// FONT SHADER CLASS //
namespace sosc {
namespace ui {
class FontShader : public sosc::shdr::Shader {
public:
enum Uniforms {
@ -33,10 +36,11 @@ public:
int 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(
(*this)[ORTHO_MATRIX], 1, GL_FALSE,
glm::value_ptr(_font_ctx.orthoMatrix)
glm::value_ptr(orthoMatrix)
);
this->Stop();
@ -87,7 +91,8 @@ void sosc::ui::font_deinit_subsystem() {
// FONT CLASS //
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;
if(!this->Load(bitmapPath, dataPath))
@ -95,14 +100,15 @@ sosc::ui::Font::Font
}
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)
this->Unload();
SDL_RWops* rwop = SDL_RWFromFile(filePath.c_str(), "rb");
this->image = SDL_LoadBMP_RW(rwop, 1);
if(!this->image)
SDL_RWops* rwop = SDL_RWFromFile(bitmapPath.c_str(), "rb");
SDL_Surface* image = SDL_LoadBMP_RW(rwop, 1);
if(!image)
return false;
char buffer[0x111];
@ -115,11 +121,11 @@ bool sosc::ui::Font::Load
if(buffer[0x10] != 0)
return false;
this->width = (uint32_t)this->image->w;
this->height = (uint32_t)this->image->h;
this->width = (uint32_t)image->w;
this->height = (uint32_t)image->h;
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) {
auto glyph = &this->glyphs[i];
@ -151,25 +157,35 @@ bool sosc::ui::Font::Load
glGenTextures(1, &this->texture);
glBindTexture(GL_TEXTURE_2D, this->texture);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA,
GL_TEXTURE_2D, 0, 3,
this->width, this->height, 0,
(this->image->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB),
GL_UNSIGNED_BYTE, this->image->pixels
GL_BGR,
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);
SDL_FreeSurface(image);
this->loaded = true;
return true;
}
void sosc::ui::Font::BindBitmap() {
void sosc::ui::Font::BindBitmap() const {
if(!this->loaded)
return;
glBindTexture(GL_TEXTURE_2D, this->texture);
}
void sosc::ui::Font::UnbindBitmap() {
void sosc::ui::Font::UnbindBitmap() const {
if(!this->loaded)
return;
@ -178,7 +194,6 @@ void sosc::ui::Font::UnbindBitmap() {
void sosc::ui::Font::Unload() {
glDeleteTextures(1, &this->texture);
SDL_FreeSurface(this->image);
this->loaded = false;
}
@ -313,14 +328,6 @@ void sosc::ui::Text::Redraw() {
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 ///
// TOP LEFT
this->vertices[i*12] = top_x;

View file

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