Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated example src for screen saver or app conditionals

  • Loading branch information...
commit 22fafbf1e675ff1912a4f0dd4ce138bfbb1adaa7 1 parent c7d5d8e
@NickHardeman authored
View
39 apps/examples/ofxScreenSaver Dual Build/src/main.cpp
@@ -0,0 +1,39 @@
+/**
+ * main.cpp
+ *
+ * Created by Marek Bereza on 06/01/2012.
+ */
+
+#include "main.h"
+
+#ifdef OF_SCREEN_SAVER
+ #include "ofxAppMacScreenSaver.h"
+#else
+ #include "ofAppGlutWindow.h"
+#endif
+#include "testApp.h"
+
+#ifdef OF_SCREEN_SAVER
+ ofxAppMacScreenSaver *ofxScreensaver_main() {
+ cout << "---------------------------------------------------" << endl;
+ cout << "main.cpp :: ofxAppMacScreenSaver : creating instance" << endl;
+ cout << "---------------------------------------------------" << endl;
+
+ ofxAppMacScreenSaver *screensaver = new ofxAppMacScreenSaver();
+ screensaver->setApp(new testApp());
+ return screensaver;
+ }
+#else
+ //========================================================================
+ int main( ){
+
+ ofAppGlutWindow window;
+ window.setGlutDisplayString("rgb double depth alpha samples>=4");
+ ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ ofRunApp( new testApp());
+
+ }
+#endif
View
5 apps/examples/ofxScreenSaver Dual Build/src/main.h
@@ -0,0 +1,5 @@
+
+#pragma once
+#include "ofxAppMacScreenSaver.h"
+
+ofxAppMacScreenSaver *ofxScreensaver_main();
View
48 apps/examples/ofxScreenSaver Dual Build/src/testApp.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxQTKitVideoGrabber.h"
+#include "ofxOpenCv.h"
+
+#ifdef OF_APPLICATION
+ // include control panels, etc. for application only //
+#endif
+
+#ifdef OF_SCREEN_SAVER
+ // includes for screen saver only
+#endif
+
+class testApp : public ofBaseApp {
+
+public:
+
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed( int key );
+ void keyReleased( int key );
+
+ void exit();
+
+#ifdef OF_APPLICATION
+ // only include these functions for application, since mouse movement awakes screen saver //
+ 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);
+#endif
+
+ ofxQTKitVideoGrabber vidGrabber;
+ ofxCvColorImage colorImg;
+ ofxCvGrayscaleImage greyImg;
+
+ ofVec2f pos;
+
+ string userInputString;
+
+};
+
+
+
+
View
131 apps/examples/ofxScreenSaver Dual Build/src/testApp.mm
@@ -0,0 +1,131 @@
+
+#include "testApp.h"
+#ifdef OF_SCREEN_SAVER
+ #include "ofxScreenSaver.h"
+#endif
+
+//--------------------------------------------------------------
+void testApp::setup() {
+ ofSetFrameRate(60);
+ ofSetVerticalSync(true);
+ #ifdef OF_APPLICATION
+ // if you are making an application, this emulates the screen saver, since screen savers launch in full screen //
+ // but if your app crashes, it is hard to get out of full screen //
+ // ofSetFullscreen(true);
+ #endif
+ ofBackground(0,0,0);
+
+ pos = ofVec2f(500, 500);
+
+ vidGrabber.initGrabber(640, 480);
+ vidGrabber.setUseTexture(true);
+
+ colorImg.allocate(640, 480);
+ greyImg.allocate(640, 480);
+
+ cout << "---------------------------------------------------" << endl;
+ cout << "testApp :: setup : calling setup " << ofGetWidth() << " x " << ofGetHeight() << endl;
+ cout << "---------------------------------------------------" << endl;
+
+}
+
+
+//--------------------------------------------------------------
+void testApp::update() {
+
+ #ifdef OF_SCREEN_SAVER
+ int threshold = [ofxScreenSaver getConfigureInteger:@"thresholdValue"];
+ #else
+ int threshold = 100;
+ #endif
+
+
+ vidGrabber.update();
+ if(vidGrabber.isFrameNew()) {
+ colorImg.setFromPixels(vidGrabber.getPixels(), 640, 480);
+ greyImg = colorImg;
+ greyImg.threshold(threshold);
+ }
+
+ pos = ofVec2f((ofGetWidth()-100)*.5, 500) + ofVec2f(sin(ofGetElapsedTimef())*((ofGetWidth()-100)*.5), 0);
+}
+
+//--------------------------------------------------------------
+void testApp::draw() {
+ ofSetColor(ofRandom(0, 255), ofRandom(0, 255), ofRandom(0, 255));
+ ofRect(pos.x, pos.y, 100, 100);
+
+
+#ifdef OF_SCREEN_SAVER
+ float red = [ofxScreenSaver getConfigureFloat:@"redValue"];
+ float green = [ofxScreenSaver getConfigureFloat:@"greenValue"];
+ float blue = [ofxScreenSaver getConfigureFloat:@"blueValue"];
+#else
+ float red = ofRandom(0, 255);
+ float green = ofRandom(0, 255);
+ float blue = ofRandom(0, 255);
+#endif
+
+ ofSetHexColor(0xFFFFFF);
+ vidGrabber.draw(0, 0);
+ ofSetColor(red, green, blue);
+ greyImg.draw(640, 0);
+
+#ifdef OF_SCREEN_SAVER
+ ofSetColor(255);
+ userInputString = [ofxScreenSaver getConfigureString:@"userInputText"];
+ ofDrawBitmapString(userInputString, 20, 20);
+#endif
+
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed( int key ) {
+#ifdef OF_APPLICATION
+ if(key == 'f') {
+ ofToggleFullscreen();
+ }
+#endif
+}
+
+//--------------------------------------------------------------
+void testApp::keyReleased( int key ) {
+
+}
+
+#ifdef OF_APPLICATION
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+}
+#endif
+
+//--------------------------------------------------------------
+void testApp::exit() {
+ cout << "testApp :: exit : " << endl;
+}
+
+
+
+
+
+
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.