Creating a grid like mesh and texturing it

Hello. Still learning openframeworks and getting used to how it works. I want to build a simple 2d mesh, pretty much a grid, and then texture it. It seems like the resources out there to do this are a bit limited. I followed as many forum posts as I could, but I am still unsure how to exactly go about it.

Comments are other things I tried and tested around with.

Any help is appreciated, thank you.

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofBackground(0);
    ofDisableArbTex();
    
    int W = 100; //Grid size
    int H = 100;
    int meshSize = 6;
    
    texture.load("ichi.jpg");
    //texture.getTexture().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
    //texture.getTexture().setTextureWrap(GL_REPEAT, GL_REPEAT);

    
    for (int y=0; y<H; y++) {
        for (int x=0; x<W; x++) {
            mesh.addVertex(ofPoint(x * meshSize, y * meshSize, 0 ));
            mesh.addTexCoord(ofVec2f(x * meshSize, y * meshSize));
        }
    }
    
    /*
     for (int y=0; y<H; y++) {
     for (int x=0; x<W; x++) {
     mesh.addVertex(ofPoint((x - W/2) * meshSize, (y - H/2) * meshSize, 0 ));
     mesh.addTexCoord(ofVec2f(x * (550 / W), y * (768 / H)));
     }
     }
    */

}

//--------------------------------------------------------------
void ofApp::draw(){
    //ofSetColor(0);
    //mesh.drawWireframe();
    
    ofSetColor(255);
    texture.bind();
    mesh.draw();
    texture.unbind();
}

You can generate the shape with an ofFbo, then use this fbo as a texture on any mesh.

void generateFboTexture() {
        
        
        ofDisableArbTex();
        fbo.clear();
        
        float fboDiv = 1.f;
        fbo.allocate(1000/fboDiv, 1000/fboDiv, GL_RGBA,4);
        
        
        cols = fbo.getWidth() / res;
        rows = fbo.getHeight() / res;
        
        plane.set(fbo.getWidth(), fbo.getHeight(), rows+1, cols+1);
        
        fbo.begin();
        ofClear(0, 0, 0, 0);
        
        if(bFillMesh) {
            ofSetColor(mColor);
            ofDrawRectangle(0, 0, fbo.getWidth(), fbo.getHeight());
        }
        
        
        
        int numIterations = cols;
        
        for (int i = 0; i < numIterations; i++) {
            int tx = i*res + res;
            int ty = i*res + res;
            ofSetColor(255, 255, 255, 255);
            ofSetLineWidth(mThickness);
            ofDrawLine(tx, 0, tx, fbo.getHeight());
            ofDrawLine(0, ty, fbo.getWidth(), ty);
        }
        
        fbo.end();
        
        fbo.getTexture().setTextureWrap(GL_REPEAT, GL_REPEAT);
    
        mesh = plane.getMesh();
        ofQuaternion rquat;
        rquat.makeRotate( 90, 1, 0, 0);
        ofSeedRandom();
        float rseed = ofRandom(0, 10000);

        vector< glm::vec3 >& verts = plane.getMesh().getVertices();
        for( int i = 0; i < verts.size(); i++ ) {
            verts[i] = rquat * verts[i];
        }
        
        vector< glm::vec3 >& tcoords = plane.getMesh().getVertices();
        for( int i = 0; i < tcoords.size(); i++ ) {
            //tcoords[i].x *= 1.f;
            //tcoords[i].y *= 1.f;
        }
        
    }

Just take a look on the example, you can download the codes from -> 7_generate3DPlaneFboTexture

Hi @RealHuman,
actually it is quite straight forwards, were @alp gives you a good example to start with.
OF provides functions for creating a grid like mesh with texture coordinates and from a single line of code. Use the ofPlanePrimitive class for achieving such. Take a look at the examples in examples/shaders/ as most of these make use of it.