I'm developing an OpenGL ES 1.1 app for Android (with the OpenGL calls being made from C code called via NDK).
My problem is that I'm trying to use the Q texture coordinate as well as the usual (S, T) texture coordinates. However, nothing I put into Q has any noticable effect.
(Aside: the reason for wanting to play with the Q coordinate is that I want to map a rectangular texture to a trapezoid quad in space with correct perspective effect (i.e. not affine) -- as described at http://www.xyzw.us/~cass/qcoord/).
My method for trying to set the Q coordinate (to something other than the default 1.0f) is the usual: I'm providing 4 texture coordinates instead of the usual 2. I've tried putting all sorts of values in the Q coord (and even into the typically unused R coord, in case of mixup between the two) with zero apparent effect on my textures. I would expect to see effects on my textures from having Q != 1.0 -- for example, Q = 0.5 for every texture coordinate should just double every derived (S, T) value -- in effect, halving the apparent texture sizes. But no change.
I can't really post full code, but here's the fundamentals:
My vertex struct is defined as follows:
typedef struct
{
GLfloat x, y, z; // 3 x spacial coord - 12 bytes
GLfloat tx, ty, tr, tq; // 4 x texture coord - 16 bytes
GLfloat padding[1]; // make it up to 32 bytes (or 8 floats, in effect)
} VertexData;
Creating each vertex buffer object (VBO):
// alloc space for my vertex buffer
int vertexBufferSize = numVertices * sizeof(VertexData);
VertexData* vertexData = (VertexData *)malloc(vertexBufferSize);
..//for each vertex I'm creating:
vertex.x = (... appropriate coord)
vertex.y = (... appropriate coord)
vertex.z = (... appropriate coord)
vertex.tx = (... appropriate coord) // AKA the 's' texture coord
vertex.ty = (... appropriate coord) // AKA the 't' texture coord
vertex.tr = 0.5f; // 'R' texture coord. Usually ignored, but I set in case of mixup between Q and R
vertex.tq = 0.5f; // 'Q' texture coord
And here's how I give my vertex and text coord pointers:
glVertexPointer(3, GL_FLOAT, stride, (GLvoid*)((char*)NULL));
// note the 4 below - we want to give 4 tex coordinates, not 2.
// 3*4 corresponds to the offset of texture coords in the VertexData struct
glTexCoordPointer(4, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4));
It's all working beautifully, except as I say, my Q coord makes no difference. If change my glTextCoordPointer
call to only provide 2 or 3 coordinates, there is no change in the program behaviour:
glTexCoordPointer(2, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4));
// OR:
glTexCoordPointer(3, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4));
My question is: why are my Q texture coordinates not having any effect? If it's device or Android API level specific, can I find out on what device or API levels would it work? If I can't rely on Q coordinate doing anything useful, how else could I achieve the same effect (realistic, non-affine texture mapping to a trapezoid)?
I am testing my code on an actual Android device: the HTC Wildfire S.
I am loading my textures using the SOIL library for convenience.
Update
I've downloaded the NeHe Android port for Lesson 6. This uses the Java OpenGL ES interface (no NDK). I added random R and Q texture coordinates to that, and again, no visible effect.
Update 2
I gave up on attempting to get the Q texture coordinate to have any effect; I presume it's just not supported on all devices. Still interested in authoritative info to this effect.
Related links:
http://www.xyzw.us/~cass/qcoord/
http://www.gamedev.net/topic/419296-skewedsheared-texture-mapping-in-opengl
http://hacksoflife.blogspot.com/2009/11/perspective-correct-texturing-q.html
perspective correction of texture coordinates in 3d