Ofmesh [draw texture as one, over whole mesh]

Hello of-er

I am try to us the 3d engine to do some projector mapping, but my problem is that when i change a vert the texture
only changes in the triangle with that vert in it, so how would i move a vert and it updates the texture over the whole mesh?

not sure if i have explained that well, but here is an image showing the problem

here is the code i am using, any pointerwould be fantasist!
allso i have problems copying the code on to the forum using the preformatted button, so i have uploaded the files too

Best
Ben

tespApp.cpp

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){

texture.allocate(2000, 2000, GL_RGBA);
video.loadMovie("1.mov");
video.play();
videoProjection.set(200, 200, 2, 2);
texture.begin();
ofClear(255,255,255, 0);
texture.end();
mesh =videoProjection.getMesh();
   vector<ofVec3f>& verts = mesh.getVertices();
	verts[0].x -= 200.01;

}

//--------------------------------------------------------------
void testApp::update(){
video.update();

texture.begin();
ofClear(255,255,255, 0);
video.draw(0,0,2000,2000);
ofEnableArbTex();
texture.end();

}

//--------------------------------------------------------------
void testApp::draw(){
cam.begin();
bindMyTexture();
mesh.draw();
unbindMyTexture();
mesh.drawWireframe();
cam.end();
}

void testApp::bindMyTexture() {
ofTexture &tex = texture.getTextureReference();
tex.bind();
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
ofTextureData texData = tex.getTextureData();
if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
glScalef(tex.getWidth(), tex.getHeight(), 1.0f);
} else {
glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f);
}
glMatrixMode(GL_MODELVIEW);
}
void testApp::unbindMyTexture() {
texture.getTextureReference().unbind();
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){

}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){

}


testApp.h

#pragma once

#include “ofMain.h”
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void bindMyTexture();
void unbindMyTexture();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

ofPlanePrimitive videoProjection;
ofVideoPlayer video;
ofFbo texture;
ofEasyCam cam;
ofMesh mesh;

};

testApp.cpp (2.5 KB) testApp.h (654 Bytes)

HI strimbob !

not sure if i’m understanding what your problem is but … some ideas …

  • what is happening is “normal” … you have a plane that is made out of 4 vertexs, so 2 triangles … if you move one vertex, just the triangle that you’re moving it’s moved and so you get what you see …

  • maybe take a look at quad warping an entire OpenGL view (solved) or look on the forums for “quad” “quad mesh” and “quad warping” …

hope it helps a bit …

e*

1 Like

thanks for the pointers-) useful

this is the closes to thread i could find

and this shows the problem,
http://www.xyzw.us/~cass/qcoord/

i was hoping to do it with out using homography, if it possible. I will kept looking, or any point points would be great too

Best
Ben

there’s a way of doing this using 4 components for the texture coordinates so instead of x,y you need to use x,y,z,w there’s an answer in the forum to solve this somewhere but cannot find it. @tgfrerer do you remember the exact post?

That’s is tantalising, i have being looking some more
and found this tutorial Tutorial: OpenGL / GLSL flat shading using an indexed ofMesh
it uses provoking vertices, was this the solved thread you thinking of

no it didn’t required any shaders only using 4 components uv coordinates

i think i found it!
or maybe not as it is only 3.

so the code for it is this, just need to work it up, but thought i put it back on the forum

void testApp::draw(){

cam.begin();
video.getTextureReference().bind();
glBegin( GL_QUADS );
glTexCoord2f(0.f,  0.f);      glVertex3i(ofGetMouseX(),        100.f, 0);
glTexCoord2f(32.f, 0.f);      glVertex3i(100.f + 64.f, 100.f, 0);
glTexCoord2f(32.f, 64.f);     glVertex3i(100.f + 64.f, 100.f + 64.f, 0);
glTexCoord2f(0.f,  64.f);     glVertex3i(100.f,        100.f + 64.f, 0);
glEnd();
video.getTextureReference().unbind();

cam.end();

}
that is the most important bit, i still have problems in copying th code up,
and here is a zip of the rest of the scr

src.zip (2.6 KB)

thanks of the pointers
Ben

actually this is the post i was thinking of:

the last post has some links that explain how to solve this using projective texture mapping

thanks for the link, i have being looking through the link, but i am stuck,
I have put this together to see to show where i up too.

i am setting the four texcoords but i can’t seem to get it to work
i seems to only stretch the video a lot

any help but be fantastic

Best
Ben

testApp.cpp

  #include "testApp.h"

void testApp::setup(){
gui.setup(); 
gui.add(v0.setup("v0",ofVec4f(0,200,0,200),ofVec4f(0,0,0,0),ofVec4f(200,200,200,200)));
gui.add(v1.setup("v1",ofVec4f(200,200,0,200),ofVec4f(0,0,0,0),ofVec4f(200,200,200,200)));
gui.add(v2.setup("v2",ofVec4f(0,200,0,200),ofVec4f(0,0,0,0),ofVec4f(200,200,200,200)));
gui.add(v3.setup("v3",ofVec4f(200,200,0,200),ofVec4f(0,0,0,0),ofVec4f(200,200,200,200)));
video.loadMovie("1.mov");
video.play();
videoProjection.set(200, 200, 2, 2);
mesh =videoProjection.getMesh();}

void testApp::update(){

video.update();
mesh.setTexCoord(0, ofVec4f( v1));
mesh.setTexCoord(1, ofVec4f( v2));
mesh.setTexCoord(2, ofVec4f( v2));
mesh.setTexCoord(3, ofVec4f( v3));}



void testApp::draw(){

cam.begin();
video.getTextureReference().bind();
mesh.draw();
video.getTextureReference().unbind();

vector<ofVec3f> verts;
verts =  mesh.getVertices();
vector<ofIndexType> indices;
indices = mesh.getIndices();
for(int x = 0;x<verts.size();x++){
    ofDrawBitmapString(ofToString(indices[x]), verts[x]);
}
mesh.drawWireframe();
mesh.drawVertices();
    cam.end();
gui.draw();
}

testApp.h

#pragma once
#include "ofMain.h"
#include "ofxGui.h"
class testApp : public ofBaseApp{
public:

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

ofPlanePrimitive  videoProjection;
ofVideoPlayer video;
ofEasyCam cam;
ofMesh mesh;

ofxVec4Slider v0;
ofxVec4Slider v1;
ofxVec4Slider v2;
ofxVec4Slider v3;
ofxPanel gui;};

Hey strimbob, I’m currently wrestling with the same issue. Were you able to figure out a solution?

Best- L05

Hi L05

no sorry i never got to the bottom of it, it is still on my list and would still love to known how to do it.
if you find out please let me known, or if there is any one out there who can show us please let us known too -)

Best
Ben

i am trying something similar.
trying to drape a texture of a part of a 3d mesh.

using plane cuts i am able to select the mesh points inside the camera’s view and facing the camera.
out of those i can create a new mesh (the yellow dots on the bunny).

but know i am not sure how to drape my rectangular texture over it.
as simple bind() and unbind() doesn’t do it, because the mesh is not ordered correctly for it to work.

any thoughts?
thanks.

1 Like