Texture coords in VBO

I know that this is something simple that I’ve done before but I’m just drawing a blank with how to fix it in OF. I have an ofImage that I’m using as the texture on a VBO. I’m using non-normalized coords but not ARB (for my shaders), but my textures are coming out looking like the first image, when it should be doing something like the second image.

I’m assigning the texcoords in a pretty simple way:

  
  
    ofDisableArbTex(); // so I can play nice with my shaders.  
      
    image.loadImage("checkerboard.png");  
      
    ofIndexType indices[WIDTH*LENGTH*4];  
      
    for( int x = 0; x < WIDTH; ++x ) {  
		for( int z = 0; z < LENGTH; ++z ) {  
            int ind = x * LENGTH + z;  
            verts[ind].set(x*4, 1, z);  
            texcoords[ind].set( (float) x, (float) z);  
  
            // some other stuff snipped out.  
        }  
    }  
  
    mesh.setTexCoordData(&texcoords[0], WIDTH*LENGTH, GL_STATIC_DRAW);  
  

If someone could jog my memory as to what might be wrong I’d appreciate it greatly. Thx!

![](http://forum.openframeworks.cc/uploads/default/2365/Screen Shot 2012-05-22 at 8.22.15 PM.png)

mmh, but if you disable arb then the tex coords are normalized, have you tried with x/image.getWidth(), y/image.getHeight()?

Thanks Arturo! Ah, ok, I had been using enable/disableNormalizedTexCoords separately but that makes total sense. So, that works pretty well except that my texture doesn’t seem bound now. My shader is just expecting this:

  
uniform sampler2D texture;  
  
void main {  
    // this is just to debug  
    gl_FragColor = texture2D(texture, frag_texcoord);  
}  
  

but binding the texture, it seems to be unallocated somehow (note the image)

  
  
    shader.begin();  
    // tried binding the texture to 1 w/raw oGL calls and no luck either  
    shader.setUniformTexture("texture", image, 0);  
    //image.bind(); // tried w/ && w/o this :/  
  

Any thoughts?

![](http://forum.openframeworks.cc/uploads/default/2367/Screen Shot 2012-05-23 at 8.15.39 AM.png)

mmh, ok i guess enable/disableNormalizedTexCoords must have an error with 2d textures. also that code seems ok, what’s frag_texcoord?

It’s something I’m passing via shader attributes:

  
  
    GLint texCoordLoc = shader.getAttributeLocation("texcoord");  
    glEnableVertexAttribArray(texCoordLoc);  
    // I just copy the props of each ofVec2f into a float*  
    glVertexAttribPointer(texCoordLoc, 2, GL_FLOAT, GL_TRUE, 0, (void*) &tp[0]);  
  

vert

  
  
varying vec2 frag_texcoord;  
  
void main() {  
    frag_texcoord = texcoord;  
}  
  

Any thoughts?

have you tried to just draw the mesh binding the texture? it seems to me that the problem is in how you are using glVertexAttribPointer but not sure what’s wrong

Yeah, that looks off too. I’m doing something wrong in initializing the VBO, I guess.

![](http://forum.openframeworks.cc/uploads/default/2368/Screen Shot 2012-05-23 at 3.53.48 PM.png)

Hi Josh,

I tend to use raw opengl when I’m sure I’m not developing for cross platforms… it’s a bit less read-friendly though. Nice thing about this is that you can easily add new vertex attributes by just adding new members to the Vertex struct (see paste).

Shader-without-texture,-but-with-vao,-vbo
Shader-with-texture,-vao,-vbo

roxlu