How to put a texture on a box?

Hi everyone,

I have a question about textures.

I’m a totally noob with OpenFrameworks and I don’t know how to put a texture on a mesh. I first draw a box (with ofBoxPrimitive) and I get the mesh with the getMesh function (myBox->getMesh()). After, I load on a ofImage variable my texture, which is part of an image (JPEG). After that, I don’t know how to proceed to put the content of the ofImage variable on the mesh.

Does anyone have an idea how to do this easily?

Thanks a lot for your help!

Hi antineta

The easiest way to go is:

In .h

class testApp : public ofBaseApp
{
public:
	testApp();

	void setup();
	void update();
	void draw();

	ofEasyCam cam;
	ofBoxPrimitive m_box;
	ofImage m_image;
};

In .cpp

#include "testApp.h"

testApp::testApp()
{
	cam.setDistance(30);
	ofEnableDepthTest();
}

void testApp::setup()
{
	m_image.loadImage("test.png");
	m_box = ofBoxPrimitive(100,100,100);
}

void testApp::update()
{
}

void testApp::draw()
{
	ofClear(50);
	
	cam.begin();
		m_image.getTextureReference().bind();
			m_box.draw();
		m_image.getTextureReference().unbind();
	cam.end();
}

Hi Hennio,

Thanks a lot for your answer!

It works, but I have only a color from the texture. It looks like the color of one pixel has applied to the whole texture. I don’t know why.

Any idea?

Thanks a lot!

Hi antineta,

My bad! I was missing the “disableARBTextures”

testApp::testApp()
{
    ofDisableArbTex();
	cam.setDistance(200);
	ofEnableDepthTest();
}

OK thanks!