PDA

View Full Version : Other than normalized texture coordinates.



Marc Butler
07-13-2009, 03:44 PM
Is it possible to specify texture coordinates in values other than normalized values? I would like to be able to specify coordinates in pixel (or texel I guess) values for the texture coordinates, as can be done with vertexes in orthographic project mode.

zeoverlord
07-13-2009, 07:11 PM
Yes, the same way in fact, only set the matrix mode to GL_TEXTURE

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glOrtho( 0, x , 0 , y, 0, 1 );

just remember to reset it after use

awhig
07-15-2009, 02:03 AM
You can also do this by mapping texture of size equal to dimension if underlying quad dimensions and setting texture type to GL_TEXTURE_RECTANGLE_ARB.

Marc Butler
07-15-2009, 04:14 PM
Thanks. I am still encountering a problem where it looks like I am getting only a tiny subsection of the texture.

For context: I am rendering to a texture using a Framebuffer. Here is a code fragment.


glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glOrtho(0, textureWidth, textureHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
...
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, texture);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
...
glMatrixMode(GL_TEXTURE);
glPopMatrix();

I am assuming that the transformation of the texture coordinates would occur when glTexCoordPointer() is called. I have checked that all coordinates are in range.

Marc Butler
07-15-2009, 04:18 PM
Thanks. I am not sure this applies as I am taking subregions of textures. Additionally, I have not been able to confirm, that the _ARB calls are available in OpenGL ES 1.x - 2.0.

SeanAustin
07-16-2009, 05:17 AM
Have you established any glTexParameteri() for your texture? I ran into a problem with my parameters on a 1D texture being used as a lookup table. Not sure what
tiny subsection of the texture. exactly means, but I was getting extra texture for my problem. Fixing the parameter solved this.

Just a thought.

Marc Butler
07-16-2009, 09:01 AM
Thanks Sean. The following parameters are set:


glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);


Could specify the particular parameter that was causing you problems?

As for a tiny subsection of the texture. I specify in the coordinates a quarter of the texture: x=0-255; y=0-255 where w=512; h=512.

However what I see looks like a sliver (possibly clamped) of the original texture. The vertexes used to render the texture in the final scene look correct (on screen).

awhig
07-16-2009, 11:28 AM
Check your glOrtho parameters..especially the bottom and top values (..interchange them)



I specify in the coordinates a quarter of the texture: x=0-255; y=0-255 where w=512; h=512.


Not clear. Does this mean that you are using only a quarter of your texture for mapping??What are x and y here?

scratt
07-16-2009, 12:14 PM
Thanks. I am not sure this applies as I am taking subregions of textures. Additionally, I have not been able to confirm, that the _ARB calls are available in OpenGL ES 1.x - 2.0.

So you're doing this on the iPhone / Simulator or something similar?
Your byte range for the texture coordinates also has me a little curious as you are using floats in the example above...

Just as an aside here, and it might make the maths easier for you..
For better performance (in terms of data upload) it's worth looking at using GL_BYTE, or GL_SHORT for your texture coordinates. Do note that they are signed values.

Here is quite a good thread discussing this..
http://www.idevgames.com/forum/showthread.php?t=16452

Marc Butler
07-17-2009, 12:01 PM
Thanks again. I have played with the glOrtho parameters. My math comprehension is old and feeble, but I don't believe there is a matrix to represent the translation and scaling needed to transform the parameters.

What I want is:


s' = s/width
t' = 1-t/height


This allows the texture coordinates to be expressed in terms of the texture height and width, with the origin in the top left corner.

I would like OpenGL to do as much of the math as possible so the simplest solution appears to be:



glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glScalef(1/(float)width, 1/(float)height, 0.f);
for (i = 0; i < texture coordinate count; i++) {
s coordinate = texture width - s coordinate
}
...

Marc Butler
07-17-2009, 12:04 PM
I appreciate the information. I am aware of the fixed point and integer APIs. I think a more accurate way to describe the work I am doing is that it must be portable to OpenGL ES. I wanted to be clear about that, to make it clear about the subset API calls I can work with.

Xmas
07-20-2009, 06:10 AM
Thanks again. I have played with the glOrtho parameters. My math comprehension is old and feeble, but I don't believe there is a matrix to represent the translation and scaling needed to transform the parameters.
Sure there is:

glMatrixMode(GL_TEXTURE);
glTranslatef(0, 1, 0);
glScalef(1/(float)width, -1/(float)height), 0);

Marc Butler
07-20-2009, 09:24 AM
Thanks. I ran the math by hand through Octave but was making a stupid numerical error.