Offline Rendering with OFF

Hello all,

I am wondering if Offline Rendering is posible with Openframeworks. By that I mean, where the program is run only once instead of 60 times per second, and ends up giving me an array of pixels or an image at any resolution?

Thank you very much.

Hi

I’m not sure, but maybe this will help you? ofxFBO http://forum.openframeworks.cc/t/ofxfbotexture/3143/0

cheers ph

Hi
yes, it depends on what you want to do, but you could for example write your application code in setup, instead of the update so that it would run only once.
Then you draw in the draw function just like you would and at the end of draw you save an image by grabbing the screen with an ofImage and saving to a file or by using ofxTileSaver.
Just make sure that you save your image only once, you can do that with, for example, if(ofGetFrameNum() == 0) { //grab screen and save image… }

hope that helps

Rui

Thank you for your replies. I have looked into both the posts and it looks like there are many ways to get the image data. But, I couldn’t find anything that runs the program only once. I even removed the update() function from the code. Still the programs runs many times a second. ( I put a cout >> framenumber in the draw loop). In processing there is a command called noLoop() which does the thing. Is there any equivalent function in OFF?

Thank you again.

Hi,

i dont think there is an equivalent to noLoop() in OF,
but there are other ways of achieving that, you can for example execute your code only if you’re in the first frame

  
  
if(ofGetFrameNum() == 0){  
     //place code here...  
}  
  

should be roughly the same as calling noLoop()

hope that helps

rui

1 Like

Hello Rui,

Thanks for the reply. My idea was to use OFF as a backend rendering engine, so that it executes the code only when it is called. If I do it in the way as you suggested above, will the App still run in the background? Also, How can I terminate the Application automatically from the application, without having to press Command Q or any other user input. Thank you again for helping me out!

regards,
Satya.

Yes, the app would still run in background. But if you don’t calculate and draw anything you can probably ignore that, because the performance needed is quite low.

To exit you application simply call

  
OF_EXIT_APP(0);  

Thank you for the info. I’ll try that out.

if you want your OF app to sit in the background waiting for ‘render’ messages, then you will need to keep it running. If you just put a big if() {} inside your update and draw and cleanup accordingly it shouldn’t take up much resources. i.e.

  
  
void testApp::update() {  
   // read network / osc / xml or wherever you are to receive notification from  
     
   if(receivedRenderMessage) {  
      // allocate memory required  
      // do all processing for the info received  
   }    
}  
  
void testApp::update() {  
   if(receivedRenderMessage) {  
      // render scene and save  
      // cleanup all allocated memory  
      receivedRenderMessage = false;  
   }    
}  
  

You can also set your framerate quite low, ofSetFrameRate(10); so update/draw is called quite infrequently.

if you do want your app to just run once and quit you can call OF_EXIT_APP at the end of your setup(), update(), or draw() method as stated above.

Memo,

Thanks for answering the question. Now, how can I make the app window hide? Or is there a way to do headless rendering?

Thank you!

I don’t think you can just have no window at all? Because a lot of openframeworks internal stuff depend on the creation of a window, the OpenGL context, etc…

But what you can do, depending on your needs, is to use e.g. an ofAddon without the window. But then you’d have to create you own program loop and can’t use the whole openFrameworks environment no more. This complicates a lot of things and needs a lot of manual setup of stuff that of would do automatically for you.

The following is a very basic example (untested) of this concept, not sure if you’re looking for this though…

  
  
//modified main.cpp  
#include "ofMain.h"  
#include "ofxNetwork.h"  
  
//========================================================================  
int main( ){	  
	ofxUDPManager udpConnection;  
	udpConnection.Create();  
	udpConnection.Bind(11999);  
	udpConnection.SetNonBlocking(true);  
	while(true){  
		char udpMessage[100000];  
		udpConnection.Receive(udpMessage,100000);  
		string message=udpMessage;  
		if(message!=""){  
			//do something  
		}  
                //maybe add a delay here to save CPU  
	}  
}  
  

cheers ph

there are some examples of windowless OF that CJ created, but without a graphics context, you need to be careful not to draw or use textures (use setUseTexture(false) for all objects that have a texture like ofVideoGrabber):

http://forum.openframeworks.cc/t/ofxstl/3015/0

I’ve also long thought this could be a good system to try for non graphics context needing to draw:

http://bellard.org/TinyGL/

which is a tiny subset of opengl… it could maybe be useful to do opengl completely in RAM, which would be necessary for a completely headless renderer.

alternatively, you can make a window super small – I think CCV does this (a larger setup window, then a small window so it can run in the background and not have to draw) and it might be a good approach.

  • z
1 Like

Thank you very much for all of your replies. The problem here is I want to use OFF as a backend renderer for a plugin (like After Effects or Motion or something), and I am not sure if I can launch an application from the plugin. But, I have seen people using OpenGL as a renderer. Does that mean, there is an OpenGL app running behind the scenes too?

Anyways, you guys have helped me a lot already. Thank you!

this might be overkill, but the OF -> quartz composer work Vade is doing might help:

http://forum.openframeworks.cc/t/ofxqcplugin—use-open-frameworks-with-quartz-composer/2743/0

And finally and I think most interesting, is allowing you to use Open Frameworks within 3rd party applications that currently leverages Quartz Composer, like VJ apps, iChat, Photo booth, (even Final Cut and After Effects if you have 3rd party programs to convert Quartz Composer documents to plugins).

might be interesting or one way to get OF working in AE ?

I think there might be some other AE work around

this is work from DR woohoo on OF <-> air, and he’s done quite alot of OF -> adobe products hook up, might be interesting:

search.php?keywords=adobe&terms=all&author=&sc=1&sf=all&sk=t&sd=d&sr=posts&st=0&ch=300&t=0&submit=Search
http://www.drwoohoo.com/

funny but searching online lead me back to your posts :wink:

http://forums.adobe.com/thread/531038?tstart=0
http://forum.openframeworks.cc/t/after-effects-plugins/2655/7

def happy to help – do you have any progress with the hacking w/ the SDK?

  • z

Hello again,

Lol, yes. I have been trying desperately to use OFF with AE SDK. In my previous thread, user named ‘jroge’ told me that he used OFF for an Apple Motion plugin. I wonder how he pulled it off.

I did see vade’s QC<->OFF code, but aren’t QC compositions like applications too? I mean they keep on refreshing all the time.

I have been messing around with the AE SDK for quite a while and I can pretty much do a lot of image manipulations. But, the SDK doesn’t provide any drawing tools and thats why I want to use OFF. I am so used to Processing Like syntax where drawing commands are so easy.

Atleast can I just access the OFF drawing commands? Or are they related to the window context?

Thank you!