Help with texture mapping please :)

Moderator
Posts: 370
Joined: 2006.08
Post: #1
Hello everyone Smile It's been a couple of weeks since I posted on this forum, but now I'm back again with another question Rasp
After finishing the basics of pong, I decided that I would add texture mapping. Unfortunately, this has proved to be much harder than I had anticipated; the last week or so of my time has been spent trying to make texture mapping work on both Windows and Mac platforms >.<
Anyway: I'm going to post a link to download a zipped copy of my code below, since it is fairly long. The main files of interest (or that have the problems, I believe) are texture.h and texture.m, texInclude.h and texInclude.m, and rectangles.h and rectangles.m, and a small portion of Lesson02View.h and Lesson02View.m
The main problem is this: I'm trying to load a texture into a texture object (of my own creation, not using libraries) with the LoadBMP function, and then I generate the texture with my Generate command. The texture ID is (supposed to be) stored in an array called "textures[]", which is declared in texInclude.h ; After a texture object is created, it is assigned to a "rectangle" object. When a rectangle object is drawn, it (should) receive the "textures[]" array, and bind the texture by taking out the texture's ID (which is also stored in the texture object). Unfortunately, when I run the program, I just get a blue rectangle when I'm supposed to get a rectangle with a texture applied to it O.o

Anyway, here's the link: http://www.ghettointeractions.com/pong.zip

Thanks everyone!
-wyrmmage
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #2
First of all, you seem to lack some glEnd()s somewhere. Further, in your LoadBMP: method, you redeclare texFormat, texSize and texBytes. That is most certainly not what you want, because this way, generate:TextureNum: works with incorrect data. You also use both glTexImage2D and gluBuild2DMipmaps. One is enough. It also seems that there is something wrong (though I don't know what) with your BMP loading code because the final texture is mostly red instead of black for me. Also, OneSadCookie tells everyone not to use NSBitmapImageRep for textures, and whatever he says is correct, so don't do that. Apple's ImageIO framework works well for loading textures.

Finally, you forgot to copy the texture in your program's bundle. Just putting the image in the ressources directory of your project should normally do this for you.
Quote this message in a reply
Moderator
Posts: 370
Joined: 2006.08
Post: #3
Ok, thanks for the help Smile I'll try what you said when I get a chance to. Could you please give me a sample of the the image IO you mentioned or tell me where I could find information on it?

Thanks,
-wyrmmage
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
Read the OpenGL Programming Guide for Mac OS X. Specifically, the "Creating Textures from Image Data" section.
Quote this message in a reply
Moderator
Posts: 370
Joined: 2006.08
Post: #5
I was not aware that this site had tutorials Annoyed Could you please provide a link to them?
-wyrmmage

*EDIT* Never mind, I found them, sry for the trouble XD
Quote this message in a reply
Post Reply