Ofbox2d and offbo

#1

hi, I’m new to the forum and I’m trying to make an application that combines various applications already made (some with processing) rendering them in the fbo, my problem is in box2d, is there a way to render the world of box2d in fbo? Sorry for English but it is provided by google
I tried this:
in ofapp:
"Fbo1.begin ();
ofClear (255, 0, 0, 0);
fbo1.end ();
fbo1 = box.boxDraw (false);
fbo1.draw (0, 0); "
and so in the I fbo class:
"ofFbo myBox :: boxDraw (bool seBordi)
{
ofFbo temp;
temp.allocate (640, 480, GL_RGBA);
temp.begin ();
ofClear (0, 255, 0, 0);
edge.draw ();

if (seBordi)
{
bordi.draw ();
}
temp.end ();
return temp;

} "

for ofopencv it worked

#2

Welcome to the forum!

I am not familiar with box2d, but in trying your code, I notice:

  • I don’t know what your “box” object is.

  • I don’t think you mentioned what the problem you were having was.

  • myBox::boxDraw() is a bit confusing name because OF already has ofBox and ofDrawBox.

Often when something doesn’t appear, it can be that ofSetcolor is the same as the background, or the position isn’t on-screen, etc.

#3

thanks for the answer, the background subtration passes the polylinia to the box2d which should draw it, what leaves me in doubt is that the green screen is not even displayed (ofclear should do that) my ultimate goal was to try to implement various video effects, and get them inside a fbo to be able to draw with transparency and more, my main problem is that fbo that is out of the 2d box does not display anything, with the same technique I can visualize all the images of the open cv, another problem, am i forced to do opencv setup in app setup? I thought the screen displays an effect, in the meantime I decide (with a random) the next one and launch the necessary setup (box2d or opencv) when I start changing the effect
another problem, am i forced to do opencv setup in app setup? I thought the screen visualizes an effect, in the meantime I decide (with a random) the next one and launch the necessary setup (box2d or opencv) when the effect change is started
this is my box class, the parts commented are by experiment: (edge came from opencv)

#4
#pragma once

#include "myBox.h"
myBox::myBox()
{
}
myBox::~myBox()
{
}
void myBox::boxSetup()
{
	//ofxBox2d box2d;
	box2d.init();
	//box2d.createBounds(0.0,640.0,640,480);
	box2d.setGravity(0, 10);
//	box2d.createGround();
	//box2d.setFPS(30.0);
	edge.create(box2d.getWorld());
//	bordi.create(box2d.getWorld());
	
//	bordi.addVertex(0, 0);
	//bordi.addVertex(640, 0);
 //  bordi.addVertex(640, 0);
	//bordi.addVertex(640, 480);
	//bordi.addVertex(0, 480);
	//bordi.addVertex(0, 0);
//	bordi.setDensity(100);
//	bordi.create(box2d.getWorld());
}
void myBox::boxUpdate(ofPolyline poly)
{
	cout << (poly.size()) << endl;;
	if(poly.size()!=0) {
	for (int i = 0; i < poly.size(); i++) {
		edge.addVertices(poly.getVertices());
		edgeEsiste = true;
	//	cout << ("e") << endl;;
		
	//	edge.draw();
	}
	}
	else
	{
		
			edgeEsiste = false;
		}

	box2d.update();
	
}
	ofFbo myBox::boxDraw(bool seBordi)
	{
		ofFbo temp;
		temp.allocate(640, 480, GL_RGBA);
		temp.begin();
		//ofClear(0, 255, 0, 0);
		cout << ("edgeEsiste");
			ofSetColor(255, 255, 255);
cout << (edgeEsiste) << endl;
	if (edgeEsiste) {
		edge.draw();
		}
	if (seBordi)
	{
		bordi.draw();
	}
	//box2d.world;
	//box2d.draw();
//	box2d.draw();
	//box2d.getWorld;
	temp.end();
	return temp;
	
	}