PDA

View Full Version : Problem loading textures



Meloni Dario
07-18-2006, 01:45 AM
I'm having problem loading texture.

It seems that column and rows are swapped when displaying the texture.
And another question, the point (0,0) of the image must be the upper left pixel of the image or the lower left one?

Bob
07-18-2006, 02:06 AM
The origin is in the lower left corner.

Meloni Dario
07-18-2006, 02:21 AM
Then the origin is ok. with this code

glBegin(GL_QUADS);
glVertex3f(-1.0,-1.0,0.0); glTexCoord2f(0.0, 0.0);
glVertex3f( 1.0,-1.0,0.0); glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0, 1.0,0.0); glTexCoord2f(1.0, 1.0);
glVertex3f(-1.0, 1.0,0.0); glTexCoord2f(0.0, 1.0);
glEnd();

I get the image point (0,0) in the lower right corner. Like if the image is rotated 90° counterclockwise.

RigidBody
07-18-2006, 03:09 AM
you can fix this by

1. changing the order of the quad's vertices

or

2. changing the order of the texcoord values

or

3. using gluLookAt in an appropriate way

Meloni Dario
07-18-2006, 04:37 AM
I have found workarounds on my own but this is for a library and I need this to work like it should.

Why does (1.0,0.0) is the (0,0) of the image?
it seems to use rows as column and column as rows!

luisillo
07-18-2006, 06:00 AM
As RigidBody said, are you sure you use gluLookAt correctly?
I think your gluLookAt should be something like

gluLookAt(0,0,-z, 0,0,0, 0,1,0);

if you wanna see the quad center at the window.

Are you sure you see the quad as you hope?

errno
07-18-2006, 06:28 AM
you did write:

glBegin(GL_QUADS);
glVertex3f(-1.0,-1.0,0.0); glTexCoord2f(0.0, 0.0);
...
glEnd();

It should be:

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.0,-1.0,0.0);
...
glEnd();

You have to set the vertex attributes (in this case, the texture coordinates) before the call to glVertex.

Meloni Dario
07-18-2006, 06:41 AM
I didn't even used gluLookAt.
Inverting the calls (first Tex, then Vertex) worked. thank you all.

RigidBody
07-18-2006, 07:01 AM
you can use gluLookAt to change the view direction, which could have solved the problem, too.

Meloni Dario
07-18-2006, 07:03 AM
Sure, but that was to much :)

07-19-2006, 12:56 PM
You have exchanged vertex coords width text coords!!!

vertex coords must always be the last one

you should write so:

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.0,-1.0,0.0);
glTexCoord2f(1.0, 0.0); glVertex3f( 1.0,-1.0,0.0);
glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0,0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0,0.0);
glEnd();