Search code examples
opengltextures

position opengl camera over a specific texel


I'm trying to pan over a specific part of a texture (applied to a Quad defined by 2D-Vertices). I'm using the fixed rendering pipeline.

The start, and end positions are given as pixel-positions in the texture: (e.g. start: 30,12; end: 340,220 ) Is there a way to position the camera over a specified texel? Or am I approaching this from a wrong angle?


Solution

  • You need to compute the position yourself, OpenGL can't really do that for you. You need to transform the position from the image space of the texture (pixels) to the texture coordinates (texels), then to the world space. To be a bit nit-picky, you don't want to position the camera over a texel, but over the position the texel is rendered at, since texels are in a different coordinate system than the camera.

    Just as an idea, instead of moving the camera in GL_MODELVIEW mode, you could also move the texture in GL_TEXTURE mode.