[snippet] fullscreen or windowed screen dimensions

hello… this is a pretty simple post relating to screen dimensions.

The problem this snippet solves is that if you are running in fullscreen mode, ofGetWidth()/ofGetHeight() return the dimensions of the resolution you set with the ofSetupOpenGL call, rather than the actual screen dimensions.

Here is how I handle caching my window dimensions:

testApp.h

  
  
class testApp : public ofSimpleApp{  
	private:  
		int windowWidth, windowHeight;  
  
// rest of class-def code, etc...  
};  
  

testApp.cpp

  
  
void testApp::setup(){  
	int windowMode = ofGetWindowMode();  
	if(windowMode == OF_FULLSCREEN){  
		this->windowWidth = ofGetScreenWidth();  
		this->windowHeight = ofGetScreenHeight();  
	}  
	else if(windowMode == OF_WINDOW){  
		this->windowWidth = ofGetWidth();  
		this->windowHeight = ofGetHeight();  
	}  
  
// rest of app setup() code, etc...  
}  
  

Pretty simple, and effective for apps that might run in windowed or fullscreen mode :slight_smile: