PDA

View Full Version : Texture Loading Headaches


napthali
2003.10.29, 03:01 PM
All right, I know this has been done to death on the boards, but I'm still having problems... I've tried the NeHe tutorials, and the QTValuePak, but to no avail. (They don't seem to work with Panther's XCode.)

I'm just trying to load a texture from file (format doesn't really matter to me at this stage, but I'm using Targa, since that seems to be the popular thing to do) and slap it on a quad. I'm writing in C++ and using GLUT.

Can anyone give me (or point me to) some sample code that ONLY loads a texture and displays it? Most samples I've seen do too many things at once, or are poorly commented. I still don't really have a handle on the OpenGL internal representation of a texture, and that's part of my problem at the moment.

I appreciate the help, and apologize for asking a newbie question.

kberg
2003.10.29, 03:19 PM
If you're sure that your texture loading code is copied pretty much verbatim, you might not have a GL context set up when you're loading your textures?

Make sure you've already set up your GLUT / AGL / NSGL /CGL window before you try and load any textures or display lists.

OneSadCookie
2003.10.29, 03:39 PM
Damn, QTValuePak doesn't work in Panther :( Guess I've got some work to do... been procrastinating updating QTValuePak for ages now, might be a good thing :)

The texture loading code should is fine though... Smiley Tag (source also available on iDevGames) uses a modified version of the QTValuePak code to load textures, and that works fine on Panther. It's probably also a more useful example, since you can just about cut-and-paste the function...

Josh
2003.10.29, 03:46 PM
Search our source code section. There are a few very small OpenGL samples that show things like that quite clearly.

napthali
2003.10.29, 04:36 PM
Wow, thanks for all the advice, guys. Glad to find a place on the web that's friendly to dumb questions and newbies like me. :)

I looked at the SmileyTag sample, but it's Obj-C and I only know C++ at the moment. I'm certainly not averse to learning Obj-C, but at this juncture I'd rather get the principle down in my native language so I can focus on just learning one thing at a time. :blink:

I really wish the source code library was searchable.... or is it and I'm just missing something obvious. Any other suggestions?

geezusfreeek
2003.10.29, 04:43 PM
The source code system is being revamped right now. A nice new set of features should be coming soon, I hope. Go, Griggs, Go!

OneSadCookie
2003.10.29, 04:57 PM
Originally posted by napthali
I looked at the SmileyTag sample, but it's Obj-C and I only know C++ at the moment.

STLuaGraphics.m only has a couple of lines of ObjC; the rest is straight C (and mostly straight from QTValuePak). If you need help removing those couple of lines, either come to the iDevGames chat or email me personally.

AnotherJake
2003.10.29, 09:59 PM
Originally posted by OneSadCookie
Damn, QTValuePak doesn't work in Panther :( Guess I've got some work to do...
I have a similar problem but I'm not using QTValuePak. It appears to be a problem with glTexImage2D although I haven't figured out what's up yet. SmileyTag uses gluBuild2DMipmaps instead and that works just fine in place of glTexImage2D in Panther for right now. Must figure this one out.

OneSadCookie
2003.10.29, 10:07 PM
glTexImage2D is significantly improved in Panther... maybe you're running afoul of that somehow http://onesadcookie.is-a-geek.net/~keith/Smilies/wink.png

The problem with QTValuePak is almost certainly to do with events or something. The QuickDraw image sample stopped working in Panther for event-handling reasons, I'm assuming something similar is going on here.

AnotherJake
2003.10.29, 10:46 PM
Originally posted by OneSadCookie
glTexImage2D is significantly improved in Panther... maybe you're running afoul of that somehow
Maybe. But this works:
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, imageBounds.right, imageBounds.bottom, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, buffer );
And this doesn't work in Panther whereas it worked just fine in Jaguar:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, imageBounds.right, imageBounds.bottom, 0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, buffer );
Events are definitely not the problem here. I'll just have to figure it out later.

OneSadCookie
2003.10.29, 10:58 PM
In what sense not work? White texture image? OpenGL error? Corrupt Texture Image?

Josh
2003.10.29, 11:02 PM
Originally posted by napthali
I really wish the source code library was searchable.... or is it and I'm just missing something obvious. Any other suggestions? If you click the download file finder, you can search it. Unfortunately, the example I was thinking of is Cocoa, so it won't help you much...

FCCovett
2003.10.29, 11:23 PM
http://www.idevgames.com/forum/showthread.php?postid=51277#post51277

AnotherJake
2003.10.29, 11:35 PM
Originally posted by OneSadCookie
In what sense not work? White texture image? OpenGL error? Corrupt Texture Image?
Yeah, white texture image. Sorry about the lack of description. This is actually starting to tick me off a little now. My same exact texture loading library works perfectly in another app that I have so I suspect that the problem is not with glTexImage2D after all. It's gonna be a long night tracking this one down... Were there any significant changes to texturing/blending/??? in Panther that you can think of off the top of your head?

arekkusu
2003.10.30, 02:21 AM
Several of Apple's own GL demos have broken white textures in Panther, so you're not alone.

Maybe flooding Apple with bugs saying "don't break stuff, dumbasses" will fix it?

AnotherJake
2003.10.30, 03:37 AM
Originally posted by arekkusu
Maybe flooding Apple with bugs saying "don't break stuff, dumbasses" will fix it?
That's funny.:D I was just thinking that if that's the case, I'm sure they'll be right on it. I hope something materializes soon cause I'm just about out of ideas on this one. Luckily I have a good workaround with gluBuild2DMipmaps for now.

OneSadCookie
2003.10.30, 04:54 AM
All that changed is that glTexImage2D is now much better able to tell whether a texture upload will actually succeed or not... but maybe they went overboard a little http://onesadcookie.is-a-geek.net/~keith/Smilies/wink.png

Those of you just calling glTexImage2D, are you doing a proper proxy test to check the texture will fit before you do the upload? If not, don't be surprised if glTexImage2D fails unexpectedly, though you should get a GL error.

I've just installed Panther on my G5 at work, so I'll test Weatherscape XT tomorrow -- I'm pretty sure that does the "right thing" when it comes to texture uploads.

AnotherJake
2003.10.30, 12:04 PM
Originally posted by OneSadCookie
Those of you just calling glTexImage2D, are you doing a proper proxy test to check the texture will fit before you do the upload? If not, don't be surprised if glTexImage2D fails unexpectedly, though you should get a GL error.
What the heck is a "proper proxy test"? I'm checking for NPT but I've never heard of a proxy test before. I'm not getting a GL error.

EDIT: Okay, I found the proxy test thing you were talking about. I'd seen it before but disregarded it. It seems a little silly for a standard 128x128 pixel bmp though.

AnotherJake
2003.10.30, 01:31 PM
Got it! Must specify glTexParameteri for the GL_TEXTURE_MIN_FILTER for glTexImage2D to work. I wasn't doing that in the loading routine for flexibility and forgot to do so later. I thought that it would work with default parameters. Apparently it DID, but not anymore.

FCCovett
2003.10.30, 01:59 PM
"The Force with him strong is, but ready he is not." :)

Thank you for sorting that out. I was getting concerned too.

OneSadCookie
2003.10.30, 05:45 PM
Ah, I forgot about that http://onesadcookie.is-a-geek.net/~keith/Smilies/blush.png

According to the GL spec, the default texture minification filter is GL_NEAREST_MIPMAP_LINEAR (go figure), and you get a white texture image if you don't have mipmaps. 8.x, 9.x, 10.0.x, 10.1.x and 10.2.x treat NEAREST_MIPMAP_LINEAR as LINEAR (I believe) if there are no mipmaps. This was wrong, and has been "fixed" for Panther.

I'm still not sure if that's a good thing or not http://onesadcookie.is-a-geek.net/~keith/Smilies/roll_eyes.png

AnotherJake
2003.10.30, 06:08 PM
Seems to me that it should be/should have been according to spec. Sucks that Apple didn't send out a technote on it though. Can we sue them for potential hair-loss?

soccerboyO7
2004.11.16, 05:34 PM
I'm also having the same problem as the original poster. I want to load in a texture file, but I am using C++. All I need is the C++ code to load in the file. I can get it to texture with patterns that I created, but I don't know how to load in a file using C++. Any help, would be greatly appreciated.