I am trying to run an app headlessly.
- Partially because for my use case I do not need to see the drawings being made only to generate them.
- Partially because I am trying to generate 6000, 6000 images and I do not have enough monitor space to support such a thing.
I have currently tried running as the following:
main.cpp:
#include "ofMain.h"
#include "ofApp.h"
#include "ofAppNoWindow.h"
//========================================================================
int main( ) {
ofAppNoWindow window;
ofSetupOpenGL(&window, 6000, 6000, OF_WINDOW);
ofRunApp(new ofApp());
}
ofApp.cpp:
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
cout << "setup has run" << endl; //Confirm execution of setup - This does print into the console.
ofBackground(0, 0, 0, 0); // set the background color to black
// Save transforamtion matrix
ofPushMatrix();
// Translate Canvas
ofTranslate(ofGetWidth() / 2, ofGetHeight() /2);
int AXIS_LENGTH = 3000;
ofSetColor(255, 255, 255);
// Draw Y Axis
ofDrawLine(0, 0, 0, AXIS_LENGTH);
ofDrawLine(0, 0, 0, -AXIS_LENGTH);
// Draw X Axis
ofDrawLine(0, 0, 0, AXIS_LENGTH);
ofDrawLine(0, 0, 0, -AXIS_LENGTH);
for(int i = 0; i <= AXIS_LENGTH; i++) {
if (i % 10 == 0) {
// Draw lines connecting each axis to its neighbor.
ofDrawLine(i, 0, 0, AXIS_LENGTH - i);
ofDrawLine(-i, 0, 0, AXIS_LENGTH - i);
ofDrawLine(i, 0, 0, i - AXIS_LENGTH);
ofDrawLine(-i, 0, 0, i - AXIS_LENGTH);
}
}
// ofSaveScreen("output.png"); - Segmentation Fault when running headless.
image.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA);
image.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
image.save("test.png");
ofExit();
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
}
// All other functions are empty. Omitting.
and lastly ofApp.h:
#pragma once
#include "ofMain.h"
class ofApp : 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 mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofImage image;
};
With this setup I do not get anything on the output, however it is the correct size. Some more info I am using:
image.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA);
image.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
image.save("test.png");
ofExit();
because ofSaveScreen("output.png);
will cause a SegFault in the code.
The line image.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA);
is particularly needed as otherwise the program returns that the image is not allocated.
When I execute this code the programs outputs the following in bin/data/test.png
:
Replacing my main.cpp with:
#include "ofMain.h"
#include "ofApp.h"
#include "ofAppNoWindow.h"
//========================================================================
int main( ) {
// Use ofGLFWWindowSettings for more options like multi-monitor fullscreen
ofGLWindowSettings settings;
settings.setSize(6000, 6000);
settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN
auto window = ofCreateWindow(settings);
ofRunApp(window, make_shared<ofApp>());
ofRunMainLoop();
}
I get a better but still not correct output for the application that is 6000x2103px "I believe this is just the maximum size that my monitors are able to hold. I have attached a snipping tool shot of it as the actual file is much to large to upload.
Is there some other way I can get the value of the "screen"
as I am now believing that the issues lies with the fact there is not technically a screen since I am running ofAppNoWindow. I am willing to run with the window, however I would still need to push the resolution to 6000x6000. Some guidance from anyone would be much appreciated!
Edit: Typos whoops