Skip to content

funatsufumiya/ofxScreenScale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

openFrameworks addon / get screen scale on HiDPI display

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published