coordinate system pixel correct

This commit is contained in:
jrkb 2023-04-12 16:06:51 +02:00
parent 5456033ccf
commit b4fe28b7d5
2 changed files with 30 additions and 5 deletions

View file

@ -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);
}

View file

@ -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(){