Calling draw functions outside of testApp.cpp?

Hello!

I have a “View” class which needs access to the drawing functions, like ofCircle, ofFill, etc. What I intend to do is something like this:

int main( ) {
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW);

ofRunApp( new testApp());
}

void testApp::draw() {
// Elsewhere I declare view as type View
view.DrawSomething();
}

and…

void View::DrawSomething() {
ofSetColor(255,130,0);
ofCircle(100,400,10);
}

Currently, my View class doesn’t know about ofSetColor or ofCircle. What’s the most graceful way of giving it access to these drawing functions? I’m wrote the beginnings of an MVC style application in Processing and I’m porting it over. In Processing, my custom classes somehow magically had access to the drawing functions.

Thanks!

  • Bret

OH, I think I figured it out after reading this post:

http://forum.openframeworks.cc/t/alternatives-to-the-draw-loop-/2987/0

What I did was inherit from obBaseApp, and my View class was then able to draw to the screen:

class View : public ofBaseApp {

public:

void DrawSomething();

};

it’s not necessary to inherit from ofBaseApp, indeed it’s not very correct. that class is just the base for the application.

what you want, is to include ofMain, that will give you access to every OF function and class:

#include “ofMain.h”

1 Like