Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 1.28 KB

README.md

File metadata and controls

63 lines (44 loc) · 1.28 KB

ofxScreenScale

  • Get screen scale on HiDPI display (ex: if using 4K screen, but setting 200% display)
  • openFrameworks addon (tested on oF v0.12.0)

Usage

  • first, set proper window size on main.cpp:
#include "ofMain.h"
#include "ofApp.h"
#include "ofxScreenScale.h"

int main( ){

	float scale = ofxScreenScale::getScreenScale();
	ofLogNotice("main") << "Screen scale: " << scale;

	ofGLWindowSettings settings;
	settings.setSize(1024 * scale, 768 * scale); // <--
	settings.windowMode = OF_WINDOW;

	auto window = ofCreateWindow(settings);

	ofRunApp(window, make_shared<ofApp>());
	ofRunMainLoop();

}
  • if you want to apply scale, just ofScale on draw:
void ofApp::draw(){
    float scale = ofxScreenScale::getScreenScale();
    ofScale(scale, scale);

    // or just call
    // ofxScreenScale::applyDrawScale();

    // draw something...
}
  • if you using ofxImGui, you need additional settings on setup:
void ofApp::setup(){
    float scale = ofxScreenScale::getScreenScale();

    // apply scaling to imgui
    ImGuiStyle& style = ImGui::GetStyle();
    style.ScaleAllSizes(scale);

    // apply font scaling to imgui
    auto&& io = ImGui::GetIO();
    io.FontGlobalScale = scale;

    // or just call
    // ofxScreenScale::applyImGuiScale();
}