Split: Loading textures

Post: #1
well. so far so good, this forum seems to be the best on the net, thanks guys!.. I'm glad it's back up..

now... i have a basic understanding of setting up vertex points in opengl...

however, looking at sample code from here and there, it seems that the preloading of image files into textures has to be done byte by byte, row by row, in a very confusing fashion, not nearly as simple as CGCreateImageWithPNGDataProvider (my sprites are all PNG RGBA...)

// Mad

Anyways, the bottom line is, I have no idea how to work with texture maps in OpenGL. I don't even know what mipmap means, or what the difference between bilinear and trilinear is. I have no idea what kind of pointer I should pass to openGL so it can reference the texture, or whether it takes an arbitrary resource ID (I seem to recall looking at some image loading methods that return INTEGERS!?!?!?)... and if I'm supposed to return an ID after loading is complete, how do I later make use of that ID to draw the image? there must be a list/vector that refers to a pointer or something.

okay and.... what the hell is a texel!? and what's with this "power of 2" stuff... I'm looking at apple's "OpenGL Image" sample code... and my alpha channel isn't working properly.

help, please!
Quote this message in a reply
Posts: 469
Joined: 2002.10
Post: #2
First, step through the redbook passages on texturing. Once you've done that Here's some code to get you started with texture upload in Cocoa:

Code to create a suitable bitmap from any NSImage. (See +bitmapWithImage;. note: this code is altivec opt')

Code to upload that bitmap to GL.

These classes will also allocate memory and names and various other things. Feel free to take or modify whatever.

15.4" MacBook Pro revA
Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #3
dave05 Wrote:I have no idea how to work with texture maps in OpenGL.

Most of your questions can be answered by reading the glTexImage2D man page.

General info is available on "the internet":
texture mapping
texture filtering
Quote this message in a reply
Post: #4
okay, the code you provided to convert an NSImage to a bitmap is, I suppose, where I get lost...

Should I attempt to understand what is going on within this method?

.. the thing is, I want to avoid downloading an entire library of code if possible. If it's possible to convert a CGImage to a GLVoid byte by byte, I'd rather do that than borrow a pile of someone else's work.

Maybe I'll print off the whole redbook..
Quote this message in a reply
Post: #5
by the way, if someone had just directed me to


I would have figured this out long ago. arrrrrrrrrrrrrg
Quote this message in a reply
Posts: 834
Joined: 2002.09
Post: #6
That's why Google is your friend. Wink
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 9,501 Dec 8, 2007 02:06 PM
Last Post: Malarkey
  loading textures - cocoa openGL mDmarco 20 16,331 Aug 28, 2007 08:48 PM
Last Post: OneSadCookie
  Best way to deal with loading textures? bronxbomber92 14 9,615 May 4, 2007 05:31 PM
Last Post: OneSadCookie
  libpng loading junk at bottom of my OpenGL textures...? BinarySpike 6 10,260 Apr 19, 2007 12:20 PM
Last Post: BinarySpike
  Loading textures from bitmaps tehqin 5 6,019 Feb 26, 2007 01:58 AM
Last Post: unknown