loading textures - cocoa openGL

Apprentice
Posts: 10
Joined: 2007.08
Post: #1
Hello everybody. This is my first post, so I apologize to you if I get something wrong. I also apologize to you because my english is not good, and so I'm surely going to say something wrong. Smile

I was looking for help in loading a texture in a cocoa application I was developing: I 've already looked some old threads, but none of these help me.

So: How can I do to load an image ( .bmp ) in cocoa and use it as an openGL texture?

I've alredy tried all these:

http://www.idevgames.com/forum/showthrea...ad+texture (I tried the code suggested from OSC and the one suggested from kelvin)

but the only result I have is a blue texture(with the OSC's code) or nothing (with kelvin's code).


Thanks to everybody for the help.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
If you're on an intel machine, you need to remove the _REV.

The usual way to do this is

Code:
#if defined(__BIG_ENDIAN__)
    GL_UNSIGNED_INT_8_8_8_8_REV,
#else
    GL_UNSIGNED_INT_8_8_8_8
#endif
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #3
thanks for the answer!
I tried what you suggested me, and worked, I saw my texture!
But when I compiled again my project everything stopped and in the Log window appared this error message:

ZeroLink: unknown symbol '_GetGraphicsImporterForFile'
the_paolometro has exited due to signal 6 (SIGABRT).


It seems that the system doesn't recognise QuickTime functions, in spite of I imported the QuickTime library in the haeder file
Have you any idea?
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #4
oh I forget that you're right, I'm on an intel machine, and so removing the _REV everything works. But now I've that error and I don't know how to proceed.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #5
Make sure QuickTime.framework is referenced from your project file. Also, turning off ZeroLink and/or doing a release build might give you a more informative error.
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #6
I'm still here. I was reading for the umpteenth time the OSC's code, when I thought that the problem could be the DisposeGWorld() that he suggests to call. So I tried to know something more about this function and the only thing I founded is that the function parameter whe have to pass it is a pointer to a offscreenGWorld variable...but I don't know what this one is and what this function should do!! I also founded out that this function is deprecated. Now the questions are:

1) Have I to call the DisposeGWorld() funtion? If so, when have I to call it and what is the parametr I have to pass it?
2) Why is this function deprecated? Is there a function that sobstitutes the DisposeGWorld()?
3) Is the call of this function the solution of my problem?
4) Why the first time I compile and build my project everything works, and the problem is came out later?

Or...what have I to do???

Thanks everybody
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #7
Ok, thanks a lot, I'll try!
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #8
Great!..Everything works, I was missing the framework!
Let me know if I also need the DisposeGWorld(), but now seems that everything works perfectly also without it.
Thanks to everybody!

Marco
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #9
Without DisposeGWorld, you're probably leaking memory. If you want to get around the deprecation warning, you can do this:

Code:
#define DisposeGWorld DeprecatedDisposeGWorld
#include <QuickTime/QuickTime.h>
#undef DisposeGWorld
extern void DisposeGWorld(GWorldPtr offscreenGWorld);

The function still works, and there isn't a non-deprecated replacement, so that's your best bet if you're using QuickTime to load stuff.
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #10
Ok, so I have to call the DisposeGWorld()! I suppose that the GWorldPtr parameter I have to pass to the function is the GWorldPtr variable that I use when I create the GWorld with the function QTNewGWorldFromPtr. Am I wrong?
But when have I to call the DisposeGWorld()? After or before the QTNewGWorldFromPtr?
And also: what does the DisposeGWorld do?

Thanks
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #11
I tried to use the DisposeGWorld() and it works only if I call it before the QTNewGWorldFromPtr. The deprecation warning is still here, but it's not a problem, surely I've not placed in the right position the code you suggested me. I think that the DisposeGWorld() is used to allocate the memory that is necessary to create the offscreen graphic ambient that we need to load the bitmap (and because of that we have to call it before the QTNewGWorldFromPtr). Let me know if I'm wrong! I'm here to learn!

thanks again
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
DisposeGWorld frees the GWorld. Use it when you're finished with the GWorld. Just after the free() of the buffer should be good.
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2007.08
Post: #13
eheh, the opposite of what I was thinking..
..done, after the free() everything works..thanks

Marco
Quote this message in a reply
Member
Posts: 81
Joined: 2007.05
Post: #14
I thought GWorlds are being depreciated? Before when I was building universal in my project I would get compiler warnings about it.

I saw on another thread a reference to FreeImage. I use FreeImage in my project now and it works well! So simple to use too and cross platform.

http://freeimage.sourceforge.net/
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #15
NewGWorld is deprecated. QTNewGWorld is not deprecated. But... DisposeGWorld is deprecated, but they didn't leave any way to get rid of a QTGWorld... Such is life.Rolleyes

QT is not in any remote danger of being deprecated so it's hard (impossible) to recommend against using it for image loading. Unfortunately that means having to put up with DisposeGWorld for now. I would imagine they'll get this straightened out by Leopard.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Opengl/Cocoa text rendering tesil 15 17,711 Mar 20, 2012 11:16 AM
Last Post: OneSadCookie
  [SOLVED]OpenGL edges of textures mk12 2 4,521 Sep 2, 2010 08:07 PM
Last Post: mk12
  OpenGL ES Loading images techy 4 3,945 Dec 24, 2009 02:01 PM
Last Post: techy
  OpenGL Image Textures mikey 52 25,571 Jun 30, 2009 10:42 AM
Last Post: AnotherJake
  Dealing with inverted textures in OpenGL johncmurphy 7 7,175 Jun 15, 2009 08:11 AM
Last Post: Skorche