Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL ES 1.1 on Android: Q texture coordinate not having any effect
    text
    copied!<p>I'm developing an OpenGL ES 1.1 app for Android (with the OpenGL calls being made from C code called via NDK). </p> <p>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. </p> <p>(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 <a href="http://www.xyzw.us/~cass/qcoord/" rel="nofollow noreferrer">http://www.xyzw.us/~cass/qcoord/</a>). </p> <p>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.</p> <p>I can't really post full code, but here's the fundamentals:</p> <p>My vertex struct is defined as follows:</p> <pre><code>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; </code></pre> <p>Creating each vertex buffer object (VBO):</p> <pre><code>// 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 </code></pre> <p>And here's how I give my vertex and text coord pointers:</p> <pre><code>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)); </code></pre> <p>It's all working beautifully, except as I say, my Q coord makes no difference. If change my <code>glTextCoordPointer</code> call to only provide 2 or 3 coordinates, there is no change in the program behaviour:</p> <pre><code>glTexCoordPointer(2, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4)); // OR: glTexCoordPointer(3, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4)); </code></pre> <p><strong>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)?</strong></p> <p>I am testing my code on an actual Android device: the HTC Wildfire S. </p> <p>I am loading my textures using the <a href="http://www.lonesock.net/soil.html" rel="nofollow noreferrer">SOIL library</a> for convenience.</p> <p><strong>Update</strong></p> <p>I've downloaded the <a href="http://insanitydesign.com/wp/projects/nehe-android-ports/" rel="nofollow noreferrer">NeHe Android port for Lesson 6</a>. This uses the Java OpenGL ES interface (no NDK). I added random R and Q texture coordinates to that, and again, no visible effect.</p> <p><strong>Update 2</strong></p> <p>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.</p> <p>Related links:</p> <p><a href="http://www.xyzw.us/~cass/qcoord/" rel="nofollow noreferrer">http://www.xyzw.us/~cass/qcoord/</a></p> <p><a href="http://www.gamedev.net/topic/419296-skewedsheared-texture-mapping-in-opengl" rel="nofollow noreferrer">http://www.gamedev.net/topic/419296-skewedsheared-texture-mapping-in-opengl</a></p> <p><a href="http://hacksoflife.blogspot.com/2009/11/perspective-correct-texturing-q.html" rel="nofollow noreferrer">http://hacksoflife.blogspot.com/2009/11/perspective-correct-texturing-q.html</a></p> <p><a href="https://stackoverflow.com/questions/5424078/perspective-correction-of-texture-coordinates-in-3d">perspective correction of texture coordinates in 3d</a></p> <p><a href="http://sfml-dev.org/forum/viewtopic.php?t=2893" rel="nofollow noreferrer">http://sfml-dev.org/forum/viewtopic.php?t=2893</a></p> <p><a href="http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html" rel="nofollow noreferrer">http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload