NeHe and OpenGL Inconsistencies

Member
Posts: 64
Joined: 2005.06
Post: #1
In the Texture Mapping (06) NeHe tutorial, it states that the top left of a texture is glTexCoord2f(0.0, 1.0), but in practice, that's the top right corner, and in fact (0.0, 0.0) is the top left. It could just appear that way if the quads that form the textures box were being drawn counter-clockwise (drawing backwards I believe), but I checked, and all the quads are being drawn clockwise.

Anyone care to shed some light on the situation? I'm also wondering, since I am doing a box, wouldn't the front quad be drawn clockwise, and the back quad be drawn counter-clockwise, so the front of each quad if facing out?

Matter of fact, does anyone have some links to some good resources on matters like this? (Redbook?)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
There's a link to the red book online in the FAQ. If that's out of date, there's one on NeHe and can you please update the FAQ Smile

By convention, OpenGL's 2D coordinate systems have the origin in the lower left corner. Also by convention, front-facing is counterclockwise.

You can change any of these conventions to suit yourself in various different ways -- changing projection or texture matrices, submitting a flipped image to glTexImage2D, calling glFrontFace(GL_CW), &c.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #3
I'm still not getting it, because in the redbook, it says that as standard, OpenGL makes counter-clockwise front-facing as default, and the bottom-left of a texture is indeed (0.0, 0.0), but in it's examples, they draw everything clockwise, and in practice, drawing counter-clockwise makes the texture turn backwards, and I haven't changed the default for the front face in OpenGL. Also, the quad I'm texturing is facing me at all times, so it's not like I just have it backwards.

Here's the code for drawing the texture and quad if you want to see it.

Code:
// Front
    glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); // Top right
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top left
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom left
    glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); // Bottom right
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #4
This piece of code makes the texture show correctly; the quad is drawn counter-clockwise (although trying it both CCW and CW produced the exact same results with the texture).

If you'll notice, what I did to make the texture show correctly, was treat the origin (0.0, 0.0), as the top left, instead of the bottom left.

Code:
// Front
    glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 1.0f); // Top right
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top left
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom left
    glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); // Bottom right
Quote this message in a reply
Feanor
Unregistered
 
Post: #5
I have to add that I have a test app where I draw and sphere, and damned if I didn't have to invert the y-axis to make the triangles work correctly! I have not yet managed to figure out how the heck it got inverted. The x-axis and z-axis are still the same, so it's not an upside-down camera or anything. I'll admit that I'm dealing with a couple of angle calculations and might still be misunderstanding the algorithm, but I was very careful and did it on paper.

Here, have a look:
example

The interesting code is in the -createLists method of the CQPlanet.m file, where the angles alpha and theta are negated to make everything work right. The code makes it look like I am drawing from the bottom of the sphere up, but I am actually drawing from the top down. Huh

I don't know, I keep hoping to find out where I screwed up. OSC, maybe you can figure it out for us.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Errors With NeHe OpenGL Guide SamGray 1 2,630 Sep 6, 2009 02:36 PM
Last Post: AnotherJake
  NeHe revival? Duane 20 7,871 Jul 11, 2007 09:57 AM
Last Post: AnotherJake
  nehe tutorials - fullscreen Michael 5 4,060 Oct 28, 2004 08:08 AM
Last Post: Michael
  NeHe example djohnson 4 2,986 Jan 30, 2004 01:58 PM
Last Post: Sohta