Fullscreen with OpenGL and live Video

I have an OpenGL application working perfectly in OF_WINDOW mode, but making it Fullscreen has proven to be very difficult. I have tried many approaches, but they either leave me with a blank screen in Fullscreen mode, or, more commonly, make the background window fullscreen, leaving my video at the original size in top left corner of my screen. The following is some code from my .cpp file that I have tried to manipulate to change the sizes of the openGL to the screenWidth and screenHeight. This one plays my video in OF_FULLSCREEN mode, but doesn’t allow the face capture/live video/openGL portion to work. The ofSetFullscreen() method simply moves the window fullscreen but not the video and objects. Any suggestions will be helpful as I am installing this piece in the middle of July! Thanks.

  
  
#include "testApp.h"  
  
  
//--------------------------------------------------------------  
void testApp::setup(){	   
  
//FULLSCREEN  
	int windowMode = ofGetWindowMode();  
	if(windowMode == OF_FULLSCREEN){  
		this -> windowWidth = ofGetScreenWidth();  
		this -> windowHeight = ofGetScreenHeight();  
		}  
		else if(windowMode == OF_WINDOW){  
		this -> windowWidth = ofGetWidth();  
		this -> windowHeight = ofGetHeight();  
		}  
	int screenW = ofGetScreenWidth();  
	int screenH = ofGetScreenHeight();  
	ofSetWindowPosition(screenW/2-300/2, screenH/2-300/2);  
	bFullscreen	= 0;  
  
//OPEN GL SETUP	  
    ofSetVerticalSync(false);  
	  
    ofSetLogLevel(OF_LOG_ERROR);  
  
    mask.loadImage("mask6.png"); //must be the same size as the open GL dims for this to work  
	  
	boarMovie.loadMovie("video/boarShort.mp4");  
	boarMovie.play();  
  
//FACES  
	webcam.setVerbose(true);  
	webcam.initGrabber(720,480);  
		  
    colorImg.allocate(720,480);  
	grayImage.allocate(720,480);  
	  
	haarFinder.setup("haarXML/haarcascade_frontalface_default.xml");  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
//FULLSCREEN	  
	if(bFullscreen){  
		ofHideCursor();  
	}else{  
		ofShowCursor();  
	}  
//FACES 	  
	ofBackground(0,0,0);  
      
	bool bNewFrame = false;  
	webcam.grabFrame();  
	bNewFrame = webcam.isFrameNew();  
      
	  
	if (bNewFrame){  
		  
		colorImg.setFromPixels(webcam.getPixels(), windowWidth,windowHeight);  
		  
        grayImage = colorImg;  
		  
		haarFinder.findHaarObjects(grayImage);  
		  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
  
	//int W = ofGetScreenWidth();  
	//int H = ofGetScreenHeight();  
	ofSetupScreen();  
	// draw the incoming & the grayscale  
	//ofSetColor(0xffffff);  
	//colorImg.draw(220,20);	  
	//grayImage.draw(360,20);  
	  
	// how many matches did you find?  
	int numMatches = haarFinder.blobs.size();  
	  
if (numMatches >= 1) {  
	boarMovie.draw(0,0, windowWidth, windowHeight);  
	  
	ofEnableAlphaBlending();  
	  
    // set up multi-texturing  
	glActiveTexture(GL_TEXTURE0); //this sets the live image as "GL_TEXTURE0"***  
	webcam.getTextureReference().bind(); // may generate an allocation warning  
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);  
    glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);  
	  
	glActiveTexture(GL_TEXTURE1); //this sets the mask image as "GL_TEXTURE1"***  
	mask.getTextureReference().bind(); // may generate an allocation warning  
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);  
    glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_BLEND);  
	  
	// render masked and mask images as one multi-textured quad  
	glPushMatrix();  
	glTranslated(378,55,0);//this moves the matrix over to the boar's face, will be affected by video size  
	glRotated(20,0,0,0);//rotates the matrix  
	glBegin(GL_QUADS);  
	glMultiTexCoord2f(GL_TEXTURE0, 0.0f, windowHeight);  
	glMultiTexCoord2f(GL_TEXTURE1, 0.0f, windowHeight);  
	glVertex3f(0.0f, windowHeight, 0);  
	glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);  
	glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f);  
	glVertex3f(0.0f, 0.0f, 0);  
	glMultiTexCoord2f(GL_TEXTURE0, windowWidth, 0.0f);  
	glMultiTexCoord2f(GL_TEXTURE1, windowWidth, 0.0f);  
	glVertex3f(windowWidth, 0.0f, 0);  
	glMultiTexCoord2f(GL_TEXTURE0, windowWidth, windowHeight);  
	glMultiTexCoord2f(GL_TEXTURE1, windowWidth, windowHeight);  
	glVertex3f(windowWidth, windowHeight, 0);  
	glEnd();  
	glPopMatrix();  
	  
    // properly unbind the textures  
    mask.getTextureReference().unbind();  
	glActiveTexture(GL_TEXTURE0);  
	masked.getTextureReference().unbind();  
	  
	  
	// disable alpha blending again  
	ofDisableAlphaBlending();  
  
	}  
	  
if (numMatches == 0) {  
	boarMovie.draw(0,0, windowWidth, windowHeight);  
}  
	  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed(int key){   
  
	if(key == 'f' ){  
	  
		bFullscreen = !bFullscreen;  
		  
		if(!bFullscreen){  
			ofSetWindowShape(720,480);  
			ofSetFullscreen(false);  
			// figure out how to put the window in the center:  
			int screenW = ofGetScreenWidth();  
			int screenH = ofGetScreenHeight();  
			ofSetWindowPosition(screenW/2-300/2, screenH/2-300/2);  
		} else if(bFullscreen == 1){  
			ofSetFullscreen(true);  
			//ofToggleFullscreen();  
		}  
	}  
}  
  

What system are you on?

usually something like this should work to render a video fullscreen:

  
void testApp::setup(){  
    boarMovie.loadMovie("video/boarShort.mp4");    
    boarMovie.play();   
}  
  
void testApp::draw(){  
    boarMovie.draw(0,0, ofGetWidth(), ofGetHeight());  
}  
  
void testApp::keyPressed(int key){     
    if(key == 'f' ){    
       ofToggleFullscreen();  
    }  
}  

1 Like

Many thanks underdoeg. The video goes fullscreen.
I just need to manually move the openGL face to resize with the video @fullscreen (it stays in the window size and location).

All working! Thanks again!

It would be nice if you shared your solution, so others can also profit from it when they fnid this thread in the future. :slight_smile:

I followed underoeg’s suggestion and added:

boarMovie.draw(0,0, ofGetWidth(), ofGetHeight());

in draw();

I also have to manually change the location of the openGL floating face based on the screen resolution of whatever monitor/projector I am using. I haven’t figured out how to do this an easier way.

HTH.

hi

I sometimes do resolution independent scaling with ofScale();

If you align and scale everything according to your video for example, you’d have to calculate how much bigger your screen is compared to your video.

When it’s 640x480 pixels you calculate the ratio which is ofGetWidth()/640.f then you can apply this number in the beginning of draw to the scale();

  
void testApp::draw(){  
  float videoW=video.getWidth();  
  float ratio=ofGetWidth()/videoW;  
  ofScale(ratio, ratio);  
  video.draw(0,0);  
  //draw you opengl stuff according to video size  
  //a fullscreen rectangle for example  
  ofRect(0,0,video.getWidth(), video.getHeight());  
}  

This assumes though that your screen resolution has the same proportions as the video.

Smart solution. I will give this a shot.
Thanks.