3D FreeFrame plugins not working

FFGL, OSC, GLSL. If you like abbreviations, this is the forum for you
Post Reply
marcusren
Met Resolume in a bar the other day
Posts: 10
Joined: Mon Nov 26, 2007 05:59

3D FreeFrame plugins not working

Post by marcusren »

I'm not sure if this is the right place for this question but I thought I would start here. I've been trying to create a suite of FreeFrame plugins using OpenFrameworks/ofxffglplugin and I'm running into some strange rendering issues when I run the applications as FreeFrame plugins in Resolume. I'm not sure if it's a Resolume issue or (more likely) if I'm not using ofxffglplugin correctly or missing some OpenGL nuance. The problem is as follows:

I've created a plugin that renders 10 points at random locations on screen. Ever 60 frames I move the points to new random locations. Before drawing the points, I call glBegin( GL_TRIANGLE_STRIP ) so that the points are connected to create an angular blob shape (here's what it should look like: http://www.vimeo.com/15401256). If I run my code as a standalone OpenFrameworks application, I can render my shape so that the points are all 2D (ie. have a z location of 0) or in 3D (ie. they have random z locations). However, when I run my code as a plugin in Resolume, only the 2D version renders as I expect. The 3D version either doesn't render or renders just the connecting lines between the points and not the planes (here's what it looks like: http://www.vimeo.com/15401278).

If anybody can suggest a reason why this might be happening, it would be much appreciated. If you want to see the code, it's available here: http://sffreeframe.svn.sourceforge.net/ ... oints/src/. The class that does most of the heavy lifting is SpiderPoints.cpp.

Thanks in advance for your help.

edwin
Team Resolume
Posts: 1202
Joined: Thu Oct 07, 2004 10:40

Re: 3D FreeFrame plugins not working

Post by edwin »

The problem you might have is that states that you set in OpenGL are set to other values by the host.
If you set opengl states in the setup function for instance it is not guaranteed to be in that state when draw is called. So in FFGL plugins it's best to set the required state on each render pass (draw), and of course set them back again. The host may have set the projection matrix to orthographic for instance.

marcusren
Met Resolume in a bar the other day
Posts: 10
Joined: Mon Nov 26, 2007 05:59

Re: 3D FreeFrame plugins not working

Post by marcusren »

Thanks for the response Edwin...that is a good thing to know. I've verified that all of my OpenGL calls are happening within the draw method of my application. I've also tried toggling the following OpenGL states to see if it makes any difference:

Code: Select all

glEnable(GL_BLEND);
glEnable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE );
glCullFace( GL_FRONT_AND_BACK );
None of these seem to have any effect. I've also tried specifying the MatrixModes and Perspective explicitly as follows:

Code: Select all

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfView, aspectRatio, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(posCoord[0], posCoord[1], posCoord[2], eyeCoord[0], eyeCoord[1], eyeCoord[2], upVec[0], upVec[1], upVec[2]);
And I've tried using gluLookAt() without preceding it with the glMatrixMode() and gluPerspective() calls. None of these made a difference either. Do you have any other thoughts as to what could be causing this (http://www.vimeo.com/15401278)? I'll also try setting up a hello world type application to see if I can duplicate the issue with less code.

Edit
I just created a really simple project that draws a 3D wireframe sphere and I'm having the same issue. When I run the application as a normal OpenFrameworks project, I get a wireframe sphere in the top right corner but when I compile and run it as a plugin in Resolume I only see the wireframe lines that lie on the z=0 plane. Here's my code (http://sffreeframe.svn.sourceforge.net/ ... World/src/):

Code: Select all

void testApp::setup()
{
	int vWindowW = 640;
	int vWindowH = 480;
	ofSetWindowShape( vWindowW, vWindowH );
	ofBackground( 0, 0, 0 );
	ofSetFrameRate( 30 );
	ofSetVerticalSync( true );
}

void testApp::update()
{
}

void testApp::draw()
{
//	ofCircle( 50, 50, 400 );
	glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
	GLUquadric* vQuadric = gluNewQuadric();
	gluSphere( vQuadric, 300, 10, 10 );
}
Thanks

edwin
Team Resolume
Posts: 1202
Joined: Thu Oct 07, 2004 10:40

Re: 3D FreeFrame plugins not working

Post by edwin »

I don't know of course what you expect to see. But when Avenue renders your plugin it does so in an FBO, this FBO is later used as a texture for future passes. So after the initial render you loose the depth. The result of your plugin is uses as a 2D texture further on in the application. So if you expect the clip rotation parameters to actually rotate your object for instance your outta luck. Please look at the build in Stingy Sphere effect and see if this behaves the same as your plugin.

The last code snippet you listed does not specify any projection matrix. Try putting that in and see if that makes a difference.

marcusren
Met Resolume in a bar the other day
Posts: 10
Joined: Mon Nov 26, 2007 05:59

Re: 3D FreeFrame plugins not working

Post by marcusren »

The last code snippet you listed does not specify any projection matrix. Try putting that in and see if that makes a difference.
Thanks for this suggestion Edwin...it put me on the right path. I played around with gluPerspective and glMatrixMode some more and I found that the following fixed my problem:

Code: Select all

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0, (float)ofGetWidth()/ofGetHeight(), 0.1, 100.0);
gluLookAt( 0, 0, 10, 0, 0, 0, 1, 1, 1 );

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
I think the main problem I was having was that I wasn't loading an identity matrix for either the projection or modelview matrices. I had actually tried this before, but I must have been zoomed in too close or out too far to see it.

Thanks for taking the time to help me debug :)

Post Reply