diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 2e1e174..d312fa1 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -31,7 +31,9 @@ namespace VariableEditor { //-------------------------------------------------------------- void ofApp::setup(){ OFX_PROFILER_FUNCTION(); - EM_ASM({window.setLoadingTask('setting up rendering', 0)}); + #ifdef TARGET_EMSCRIPTEN + EM_ASM({window.setLoadingTask('setting up rendering', 0)}); + #endif { ofFile sf("appSettings.json"); @@ -58,7 +60,9 @@ void ofApp::setup(){ 10000000, // farDist glm::vec2(0, 0) // lensOffset ); - EM_ASM({window.setLoadingTask('setting up rendering', 10)}); + #ifdef TARGET_EMSCRIPTEN + EM_ASM({window.setLoadingTask('setting up rendering', 10)}); + #endif ofDisableArbTex(); fboSettings.width = ofGetWidth() * AA; @@ -79,25 +83,26 @@ void ofApp::setup(){ //fbo.allocate(ofGetWidth() * AA, ofGetHeight() * AA, GL_RGB); - EM_ASM({window.setLoadingTask('setting up rendering', 30)}); + #ifdef TARGET_EMSCRIPTEN + EM_ASM({window.setLoadingTask('setting up rendering', 30)}); + #endif layerComposition.setup(); - EM_ASM({window.setLoadingTask('setting up rendering', 90)}); + #ifdef TARGET_EMSCRIPTEN + EM_ASM({window.setLoadingTask('setting up rendering', 90)}); + #endif layerComposition.setVFlip(true); - #ifndef TARGET_OPENGLES + #ifndef TARGET_EMSCRIPTEN { - std::string fontPath = "data/fonts/Version-2-var.ttf"; - ofxVariableLab::LayerType type = ofxVariableLab::LayerType::GPUFONT; + std::string fontPath = "data/fonts/Version-2.ttf"; ofxVariableLab::Layer::Props props; props.fontPath = fontPath; props.text = "yo, whatever you want, and especially pancakes"; props.y = 120; props.x = 95; - layerComposition.addLayer( - {fontPath, type}, - props, - {{"Weight", 100.0}, {"Weight", 700.0}} - ); + if(ofFile(fontPath).exists()){ + layerComposition.addLayer(props, "layer-0"); + } } #endif @@ -130,7 +135,9 @@ void ofApp::setup(){ << " | Minor(" << ofToString(glMajor) << ")" << endl; artboard.setup(); - EM_ASM({window.setLoadingTask('setting up rendering', 100)}); + #ifdef TARGET_EMSCRIPTEN + EM_ASM({window.setLoadingTask('setting up rendering', 100)}); + #endif } //-------------------------------------------------------------- diff --git a/src/ofApp.h b/src/ofApp.h index d2ae3ec..791ca2a 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -5,6 +5,7 @@ #include "conversion.h" #include "Artboard.h" #include "ofEasyCam.h" +#include "ofFileUtils.h" #include "ofMain.h" #include "ofQuaternion.h" #include "ofTrueTypeFont.h" @@ -58,10 +59,14 @@ class ZipProjectSaver : void update(){ if(freshDownload.load()){ - emscripten_browser_file::download(filename.c_str(), - "application/zip", - buffer, - buffer_size); + #ifdef TARGET_EMSCRIPTEN + emscripten_browser_file::download(filename.c_str(), + "application/zip", + buffer, + buffer_size); + #else + ofBufferToFile(filename.c_str(), ofBuffer(buffer, buffer_size)); + #endif freshDownload.store(false); } } @@ -155,7 +160,8 @@ class ZipSaver : public ofThread { void update(){ if(freshDownload.load()){ - EM_ASM({ + #ifdef TARGET_EMSCRIPTEN + EM_ASM({ document.getElementById('export_progress_task').innerHTML = 'rendering'; let innerHTML = "|"; for(let i = 0; i < 100; i++){ @@ -167,10 +173,13 @@ class ZipSaver : public ofThread { let progress_task = document.getElementById("export_progress_task"); progress_task.innerHTML = "idle"; }); - emscripten_browser_file::download(filename.c_str(), - "application/zip", - buffer, - buffer_size); + emscripten_browser_file::download(filename.c_str(), + "application/zip", + buffer, + buffer_size); + #else + ofBufferToFile(filename.c_str(), ofBuffer(buffer, buffer_size)); + #endif freshDownload.store(false); }else if(isThreadRunning()){ setProgress(percent.load()); @@ -178,7 +187,8 @@ class ZipSaver : public ofThread { } void setProgress(int percent){ - EM_ASM_INT({ + #ifdef TARGET_EMSCRIPTEN + EM_ASM_INT({ let percent = $0; document.getElementById('export_progress_task').innerHTML = 'rendering'; let innerHTML = "|"; @@ -196,6 +206,9 @@ class ZipSaver : public ofThread { let progress_task = document.getElementById("export_progress_task"); progress_task.innerHTML = "creating zip file"; }, percent); + #else + std::cout << "progress: " << percent << "/100" << std::endl; + #endif } void threadedFunction(){ @@ -213,9 +226,9 @@ class ZipSaver : public ofThread { ofImage image; image.setUseTexture(false); image.load(filepath); - ofBuffer buffer; - ofSaveImage(image.getPixels(), buffer, OF_IMAGE_FORMAT_PNG); - zip.addBuffer(f + ".png", buffer.getData(), buffer.size()); + ofBuffer b; + ofSaveImage(image.getPixels(), b, OF_IMAGE_FORMAT_PNG); + zip.addBuffer(f + ".png", b.getData(), b.size()); percent.store((float(i) / float(total)) * 100.0f); i++; } @@ -257,7 +270,8 @@ class ZipUnpacker : public ofThread { } void setProgress(int percent){ - EM_ASM_INT({ + #ifdef TARGET_EMSCRIPTEN + EM_ASM_INT({ let percent = $0; document.getElementById('export_progress_task').innerHTML = 'uploading and unpacking'; let innerHTML = "|"; @@ -275,6 +289,9 @@ class ZipUnpacker : public ofThread { let progress_task = document.getElementById("import_progress_task"); progress_task.innerHTML = "creating zip file"; }, percent); + #else + std::cout << "progress: " << percent << "/100" << std::endl; + #endif } void threadedFunction(){