Problem loading textures

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?

The origin is in the lower left corner.

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.

you can fix this by

  1. changing the order of the quad’s vertices

or

  1. changing the order of the texcoord values

or

  1. using gluLookAt in an appropriate way

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!

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?

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.

I didn’t even used gluLookAt.
Inverting the calls (first Tex, then Vertex) worked. thank you all.

you can use gluLookAt to change the view direction, which could have solved the problem, too.

Sure, but that was to much :slight_smile:

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();