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!
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 :/
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]);
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
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).