Define projection matrix for the programmable renderer

Hi forum,

I want to define the perspective matrix for the programmable pipeline. I found that there is a function called setupScreenPerspective() inside the ofGLProgrammableRenderer . But i believe that you have create a object of type
ofGLProgrammableRenderer to use the function. I am a bit confused here. I am using the following snippet to enable the programmable pipeline:

// comment out the line below if you want to use a fixed pipeline opengl renderer,
// otherwise leave this line uncommented if you want to use a programmable pipeline opengl renderer.
#define USE_PROGRAMMABLE_RENDERER

#ifdef USE_PROGRAMMABLE_RENDERER
#include "ofGLProgrammableRenderer.h"
#endif
//========================================================================
int main( )
{
#ifdef USE_PROGRAMMABLE_RENDERER
   ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);
#endif   
   ofSetupOpenGL(1024,768,OF_WINDOW);			// <-------- setup the GL context
   
   // this kicks off the running of my app
   // can be OF_WINDOW or OF_FULLSCREEN
   // pass in width and height too:
   ofRunApp(new ofApp());
   
}

According to the example , it did not create any object of that type .

I want to define the projection matrix from the application that will be sent to the shader of programmable pipeline.
Without the object definition i end up with the following error:

src/ofApp.cpp: In member function ‘virtual void ofApp::draw()’:
src/ofApp.cpp:80:97: error: cannot call member function ‘virtual void ofGLProgrammableRenderer::setupScreenPerspective(float, float, float, float, float)’ without object
src/ofApp.cpp:72:10: warning: unused variable ‘f’ [-Wunused-variable]
make[1]: *** [obj/linux/Release/src/ofApp.o] Error 1

Any hint?

Thanks

That’s odd. Your snippet should work. What version of OF are you using?

Because in the recent stable ofGLProgrammableRenderer::setupScreenPerspective is not event declared as virtual.

Hello,

I could be wrong, but since it’s not a static funtion, you can only call it as a member function, so you would need an object indeed. And I don’t know if this is “good practice” because OF uses already a renderer object (in this case ofProgrammableRenderer) under the hood to take care of everything.

There is however a static function

void ofSetupScreenPerspective(float width, float height, float fov, float nearDist, float farDist)

that you can use that traces back to updating the projection matrix for the current renderer…
github link ofGraphics.h

I would like to know as well how to interact with the underlying matrices though…

Best, V

I am using the current release version

Since it is not possible to access the member functions of ofGLProgrammableRenderer without creating an object , some reference examples is requested from the community ?

I was thinking a way around. Lets create a camera and define the perpective projection there , send the matrix to the pipeline using ofLoadMatrix.

Any other better suggestion is most welcome.

Thanks

you shouldn’t be using the renderer directly, it’s an object that openframeworks creates and uses internally, most functions in the renderers are available from the functions in ofGraphics, in this case through ofSetupPerspective()

and yes, using

ofSetMatrixMode(OF_MATRIX_PERSPECTIVE)
ofLoadMatrix(matrix);
ofSetMatrixMode(OF_MATRIX_MODEL_VIEW);

will work too

I am sorry .

Which version of the OF do i have to use to get access to the function ?

I looked for it in the documentation and i did not find the reference to the function

ofSetupPerspective()

I think the function is actually called ofSetupScreenPerspective http://openframeworks.cc/documentation/graphics/ofGraphics.html#!show_ofSetupScreenPerspective