OpenGL Texture not displaying - my first class.

Well, I just started messing around with OOP classes, and so far I've found them to be pretty cool. As my first, I figured I'd start with something relatively simple: A form of SDL_Surface, but for OpenGL. It uses DevIL and OpenGL. Unfortunatly, my texture does not appear.

I've actually posted a thread about this over at gameDev, but then I realized. Oh wait... what am I doing? It's the mac users that are the smart ones, I'll ask them.

I don't know DevIL, so your code might already do this depending on DevIL's setup of surfaces. But remember that OpenGL (afaik) can't load non-power-of-two textures. That might be your problem.

On another note, I am using SDL for loading of OpenGL textures, and loving it. Took some doing to set up, but there's a tutorial (GLtest) in the SDL source code that shows exactly how to do it. If you use SDL at some point instead of DevIL, try it out.

Now, after load:
Ignore the rotation, that's actually just a texpos mis-type. But why is it Pink? I'm guessing it's because of some sort of byte ordering error. It's a tif, with transparency, and DevIL should be passing the right format. This *might* be another pixen error, but I viewed it in photoshop and it seemed fine.

The dark blue windows becoming light yellow suggests that you are inverting the RGB channels, although the green/pink area maintains its shadows so this may not be quite right. It could be a little endian/big endian error with the RGB values. Also check you are reading the correct pixel format (not mixing up RGBA with ARGB or something), although I think you are OK on that one.

backslash Wrote:The dark blue windows becoming light yellow suggests that you are inverting the RGB channels, although the green/pink area maintains its shadows so this may not be quite right. It could be a little endian/big endian error with the RGB values. Also check you are reading the correct pixel format (not mixing up RGBA with ARGB or something), although I think you are OK on that one.

That's what I was thinking... might it be my "type" in glTexImage2D? It's set at GL_UNSIGNED_BYTE, perhaps GL_BITMAP or another choice could help...

I also can't get it to be oriented correctly, If I assume that the top-left corner is 0,0 of my texture it looks like the above picture. If I assume that bottom-left corner is 0,0... it's upside down. I'm gonna take a wild guess and try drawing the from the right corners.

Using DevIL, I tried forcing the image to be RGBA with:

Code:

ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

But it remained tinted pink and yellow.

EDIT: Trying to make it any other type results in a type 4 crash.

EDIT 2: I tried making GL use ONLY GL_RGBA isntead of what DevIL gave it, like this:

EDIT 3: Make another go, but with a gif... it just doesn't even draw the quad now! *smashes head against keyboard.* I mean come-on, the image only has like 4 little colors! No blending at all! Argh!

EDIT 4: Well, just noticed something... even if I rotated the image, or changed where it's drawn from, it'll still be backwards. This must be a byte ordering thing, with my tifs and DevIL. Pity, that's the only format I can export too that supports transparency. That and gif, which doesn't load.

Personally, I've always used PNGs. Libpng may not be the easiest library in the world, but the example code is quite good, and you only really have to write this stuff once. Don't feel constrained by only being able to export TIFFs - Preview can convert to many formats (including PNG), and there are plenty of free tools out there.
Anyway...
For your texture coordinates, you should have (0,0) in the top left and (1,0) in the top right. You appear to have the x and y coordinates mixed up between the texture coords and the the polygon coords in the code above. Also, remember that if (0,0) is the bottom left corner of the screen then you need to use y-height for the lower corners. I think this is why you are seeing it backwards - you are actually looking at the back of it.

I know I'm a little late (didn't see this thread before), but when using DevIL, instead of using GL_RGBA in glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); you probably should have used GL_BGRA. (for inverted blue and red channels)

For your libpng demo, is the texture a 2D texture or rectangular texture? You enable both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB, and I believe GL_TEXTURE_RECTANGLE_ARB takes precedence. If it's really a 2D texture, it won't display correctly.

BTW, you multiply by -1 to negate some numbers there: the unary - sign works. For example, this would be valid:
p_height & -p_height != 0
It won't make much of a difference, but it would take up a few less cycles. (well, assuming you have optimizations turned on, it actually likely be optimized out. )

akb825 Wrote:I know I'm a little late (didn't see this thread before), but when using DevIL, instead of using GL_RGBA in glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); you probably should have used GL_BGRA. (for inverted blue and red channels)

For your libpng demo, is the texture a 2D texture or rectangular texture? You enable both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB, and I believe GL_TEXTURE_RECTANGLE_ARB takes precedence. If it's really a 2D texture, it won't display correctly.

BTW, you multiply by -1 to negate some numbers there: the unary - sign works. For example, this would be valid:
p_height & -p_height != 0
It won't make much of a difference, but it would take up a few less cycles. (well, assuming you have optimizations turned on, it actually likely be optimized out. )

Would it really? I've always done it * -1 because it seemed to be more... correct. Dunno why.

I enable both ARB and 2D because the class can handle both, and needs to have both enabled. I'll try removing one...