Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Creating a grid like mesh and texturing it

$
0
0

@RealHuman wrote:

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();
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles