diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index e2789a3..1722e8c 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -84,7 +84,7 @@ void GPUFontAtlasLayerCombo::draw(){ float worldSize = targetFontSize / (float)width; - font->setWorldSize(worldSize); + font->setWorldSize(targetFontSize); float width_unit = 1; float height_unit = (float)height / width; @@ -92,7 +92,9 @@ void GPUFontAtlasLayerCombo::draw(){ //ofClear(125, 255, 125, 255); //glm::mat4 projection = transform.getProjectionMatrix((float)width / height); - glm::mat4 projection = transform.getOrthoProjectionMatrix(width_unit, height_unit); + glm::mat4 projection = transform.getOrthoProjectionMatrix(width, + height, + Transform::TOP_LEFT); glm::mat4 view = transform.getViewMatrix(); glm::mat4 model = glm::mat4(1.0f); @@ -150,7 +152,7 @@ void GPUFontAtlasLayerCombo::draw(){ cy = 0.5f * (bb.minY + bb.maxY); //ofRectangle rectangle(0, 0, width, height); //ofDrawRectangle(rectangle); - font->draw(mx, my, 0, mainText, vFlip == V_FLIP_ON); + font->draw(mouse.x, mouse.y, 0, mainText, vFlip == V_FLIP_ON); glUseProgram(currentProgram); } diff --git a/src/GPUFontAtlasLayerCombo.h b/src/GPUFontAtlasLayerCombo.h index 1231128..62d15cd 100644 --- a/src/GPUFontAtlasLayerCombo.h +++ b/src/GPUFontAtlasLayerCombo.h @@ -12,6 +12,10 @@ namespace ofxVariableLab { class GPUFontAtlasLayerCombo : public AtlasLayerCombo { struct Transform { + enum Origin { + CENTERED, + TOP_LEFT + }; float fovy = glm::radians(60.0f); float distance = 0.42f; glm::mat3 rotation = glm::mat3(1.0f); @@ -20,8 +24,27 @@ class GPUFontAtlasLayerCombo : public AtlasLayerCombo { glm::mat4 getProjectionMatrix(float aspect){ return glm::perspective( /* fovy = */ glm::radians(60.0f), aspect, 0.002f, 12.000f); } - glm::mat4 getOrthoProjectionMatrix(float w, float h){ - return glm::ortho(-(w * 0.5f), (w * 0.5f), -(h * 0.5f), (h * 0.5f), 0.002f, 12.000f); + glm::mat4 getOrthoProjectionMatrix(float w, float h, Origin origin = Origin::CENTERED){ + switch(origin){ + default: + case Origin::CENTERED: + return glm::ortho(-(w * 0.5f), + (w * 0.5f), + -(h * 0.5f), + (h * 0.5f), + 0.002f, + 12.000f); + break; + + case Origin::TOP_LEFT: + return glm::ortho(0.0f, + w, + 0.0f, + h, + 0.002f, + 12.000f); + break; + } } glm::mat4 getViewMatrix(){