Hi All
I’m building an application that analyses the camera images and builds up a layer of text + graphics. I’ve noticed that when the application loses focus to another window it begins to flicker/shudder. This will continue even when the window returns to focus. Are there any FOCUS_LOST and FOCUS_FOUND type events I can listen to on order to pause everything and get round this. Or alternatively, is there anything standing out below that might cause the problem?
Thanks in advance
James
testApp.h
#ifndef _TEST_APP
#define _TEST_APP
#define BALL_AMOUNT 500
#include "ofMain.h"
#include <iostream>
#include <ctime>
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
private:
bool _isFirstFrame;
ofVideoGrabber vidGrabber;
unsigned char * pixels;
int camWidth;
int camHeight;
int shapesPerFrame;
ofTrueTypeFont franklinBook;
};
#endif
testApp.cpp
#include "testApp.h"
void testApp::setup()
{
ofSetFrameRate(31);
ofEnableAlphaBlending();
ofEnableSmoothing();
ofSetCircleResolution(8);
ofSetBackgroundAuto(false);
franklinBook.loadFont("frabk.ttf", 36);
ofBackground(255, 255, 255);
camWidth = 320; // try to grab at this size.
camHeight = 240;
shapesPerFrame = 1500;
vidGrabber.setVerbose(true);
vidGrabber.initGrabber(camWidth, camHeight);
}
void testApp::update()
{
vidGrabber.grabFrame();
}
void testApp::draw()
{
ofSetColor(0, 0, 0, 7);
ofRect(0, 0, 1600, 960);
ofSetColor(0xffffff);
vidGrabber.draw(1280, 0);
char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
if (vidGrabber.isFrameNew())
{
pixels = vidGrabber.getPixels();
int i;
int n = shapesPerFrame;
for (i = 0; i < n; i++)
{
int x = (int)ofRandom(0, camWidth);
int y = (int)ofRandom(0, camHeight);
int r = pixels[(x * 3) + (y * camWidth * 3)];
int g = pixels[(x * 3) + (y * camWidth * 3) + 1];
int b = pixels[(x * 3) + (y * camWidth * 3) + 2];
float brightness = r + g + b;
ofSetColor(r, g, b, ofRandom(0, 255));
float scale = 0.4 + brightness / 600;
stringstream ss;
string s;
char c = chars[(int)ofRandom(0, sizeof(chars) - 1)];
ss << c;
ss >> s;
glPushMatrix();
glTranslatef(x * 4, y * 4, 0.0f);
ofScale(scale, scale, 1);
franklinBook.drawString(s, 0, 0);
glPopMatrix();
}
}
}