Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vandalo committed Mar 15, 2018
2 parents 29a17ee + 94211fe commit 40fe179
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
8 changes: 5 additions & 3 deletions LCSEngine/ModuleGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ ModuleGameUI::~ModuleGameUI() {}

void ModuleGameUI::printGameUI()
{
glDisable(GL_DEPTH_TEST);

GLuint program = App->sceneMain->shader->programs[App->sceneMain->shader->defaultShaders[DEFAULTSHADER]];
glUseProgram(program);

Expand All @@ -39,6 +37,8 @@ void ModuleGameUI::printGameUI()
GLint projectLoc = glGetUniformLocation(program, "projection");
glUniformMatrix4fv(projectLoc, 1, GL_FALSE, &identity[0][0]);

glDisable(GL_DEPTH_TEST);

for (vector<ElementGameUI*>::iterator it = elements.begin(); it != elements.end(); ++it)
{

Expand Down Expand Up @@ -103,7 +103,7 @@ void ModuleGameUI::printGameUI()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, image->idIdxVAO);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);

UILabel* label = (UILabel*)((UIButton*)(*it))->label;
UIImage* imageLabel = (UIImage*)label->textImage;

Expand Down Expand Up @@ -131,6 +131,8 @@ void ModuleGameUI::printGameUI()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, imageLabel->idIdxVAO);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);
glEnable(GL_DEPTH_TEST);

break;
}
case EDITTEXT:
Expand Down
4 changes: 2 additions & 2 deletions LCSEngine/ModuleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ void ModuleType::loadFont(const char * path)
}
}

FontData* ModuleType::renderFont( const char * text, const char * path)
FontData* ModuleType::renderFont( const char * text, const char * path, SDL_Color color)
{
if (fonts.count(path))
{
AssetFont* fontAsset = fonts[path];
TTF_Font * fontTtf = fontAsset->font;
SDL_Surface *surface = TTF_RenderUTF8_Blended(fontAsset->font, text, { 255, 255 ,255 });
SDL_Surface *surface = TTF_RenderUTF8_Blended(fontAsset->font, text, color);
SDL_Surface *flipSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);

if (SDL_MUSTLOCK(surface))
Expand Down
2 changes: 1 addition & 1 deletion LCSEngine/ModuleType.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ModuleType : public Module
bool cleanUp() override;
update_status update(float deltaTime) override;
void loadFont(const char* path);
FontData* renderFont(const char* text, const char* path);
FontData* renderFont(const char* text, const char* path, SDL_Color color);

public:
FT_Library library;
Expand Down
35 changes: 26 additions & 9 deletions LCSEngine/UILabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ UILabel::UILabel(GameObject* parent, int x, int y, int h, int w, bool isVisible)

static ElementFactory* factoryElements = ElementFactory::getInstance();
textImage = (UIImage*)factoryElements->getComponent(IMAGE, nullptr, x, y, h, w, true);

glGenTextures(1, &idTexture);
fillBufferData();
}

UILabel::~UILabel() {}
Expand Down Expand Up @@ -48,6 +51,15 @@ void UILabel::drawGUI()
ImGui::DragInt("Width", &rect.w, 1);
ImGui::PopID();

if (ImGui::ColorEdit4("color 2", textColor))
{
color.r = textColor[0] * 255;
color.g = textColor[1] * 255;
color.b = textColor[2] * 255;
color.a = textColor[3] * 255;
fillBufferData();
}

fillGUI();
}
}
Expand All @@ -61,15 +73,7 @@ void UILabel::fillGUI()
if (ImGui::InputText("", aux1, 64))
{
text = aux1;
fontData = App->type->renderFont(text.c_str(), fontPath.c_str());

glGenTextures(1, &fontData->idTexture);
glBindTexture(GL_TEXTURE_2D, fontData->idTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fontData->width, fontData->height, 0,
GL_BGRA, GL_UNSIGNED_BYTE, fontData->data);
glBindTexture(GL_TEXTURE_2D, 0);
fillBufferData();
}
ImGui::PopID();

Expand All @@ -84,6 +88,19 @@ void UILabel::fillGUI()

}

void UILabel::fillBufferData()
{
fontData = App->type->renderFont(text.c_str(), fontPath.c_str(), color);

fontData->idTexture = idTexture;
glBindTexture(GL_TEXTURE_2D, fontData->idTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fontData->width, fontData->height, 0,
GL_BGRA, GL_UNSIGNED_BYTE, fontData->data);
glBindTexture(GL_TEXTURE_2D, 0);
}

void UILabel::update()
{
textImage->rect = rect;
Expand Down
4 changes: 4 additions & 0 deletions LCSEngine/UILabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class UILabel : public ElementGameUI
~UILabel();
void drawGUI() override;
void fillGUI();
void fillBufferData();
void update();

public:
std::string text;
std::string fontPath;
float textColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
SDL_Color color = {255, 255, 255, 255};
GLuint idTexture;
FontData* fontData = nullptr;
UIImage* textImage = nullptr;
};
Expand Down

0 comments on commit 40fe179

Please sign in to comment.