Drawing bitmaps in OpenGL

Luminary
Posts: 5,143
Joined: 2002.04
Post: #16
The bottom line is, unless you create the NSBitmapImageRep yourself with the longwinded constructor passing your own pixel array, you should not attempt to pass -bitmapData to OpenGL.

Even if your app happens to work for the images you've tried on the OS you've tried, there are no guarantees for other images, and other OSes.
Quote this message in a reply
Member
Posts: 21
Joined: 2007.09
Post: #17
Some one seems to have maliciously destroyed the content at GameWiki and in particular I would have liked to see the code for the ImageIO texture loader. Does anyone have a (more or less) clean version of that code they could share along with caveats or criticisms?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #18
http://gamewiki.evolpenguin.com/index.ph...oldid=3461 is the last good version of the page.

It needs

Code:
#if defined(__BIG_ENDIAN__)
GL_UNSIGNED_INT_8_8_8_8_REV,
#else
GL_UNSIGNED_INT_8_8_8_8,
#endif

to work on Intel, and of course it requires 10.4.
Quote this message in a reply
Member
Posts: 21
Joined: 2007.09
Post: #19
Thanks OSC!
Quote this message in a reply
Member
Posts: 21
Joined: 2007.09
Post: #20
I've been working through this and I am stuck again.

To get my image object within the IOImage Texture loader I chopped in some code from the Apple Dev site:

Code:
NSString* path=[ NSString stringWithFormat:@"%@/%s",
        [ [ NSBundle mainBundle ] resourcePath ],
        "RedSquare.bmp" ];
    

        NSData* raw;
        raw=nil;    
        raw = [NSData dataWithContentsOfFile:path];
            
    
        CGImageRef        image = NULL;
        CGImageSourceRef  sourceRef;
        
        sourceRef = CGImageSourceCreateWithData((CFDataRef)raw, NULL);
        
        if(sourceRef) {
            image = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);
            CFRelease(sourceRef);
            NSLog(@"SourceRef exists");
        }

Everything loads but the build gets hung up in the debugger because at the end of this code fragement there is basically no data in the object (in the debugger the value is 0x1) so:

Code:
unsigned width = CGImageGetWidth(image);

fails.

I've checked in the debugger and "raw" does have an address and 196 Kbytes of data in the summary (Furthermore, RedSquare.bmp is an image file that opens fine in Preview).

So the problem seems to be with the line

Code:
image = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);

Which isn't doesn't appear to be moving the data.


Any thoughts?


By the way I had to make some changes to the Assert and AssertNonNull statements using assert (lower case) and assert (____ !-= NULL) to the same effect (I hope). I am working without the Carbon framework.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #21
Those macros aren't from Carbon, you're intended to define 'em however you want Wink

[[NSBundle mainBundle] pathForResource:@"RedSquare" ofType:@"bmp"] would be a more normal way to get the path, but what you have should *work*...
Quote this message in a reply
Member
Posts: 21
Joined: 2007.09
Post: #22
I started over and coverted the method back to a function and it seems to run smoothly. Except that there is no texture on the cube. I imagine I am binding the texture incorectly in the drawRect method. But I'll work at it.

Thanks.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  opengl text/font drawing from CGContext fretmunky 11 12,872 Dec 7, 2008 11:29 AM
Last Post: fretmunky
  OpenGL ES - Drawing a simple cube help. MattCairns 7 12,435 Oct 10, 2008 05:26 PM
Last Post: Frogblast
  Loading textures from bitmaps tehqin 5 3,930 Feb 26, 2007 01:58 AM
Last Post: unknown
  OpenGL, SDL, and Transparent Bitmaps RyanA 4 4,005 Jun 26, 2006 04:26 PM
Last Post: RyanA
  Loading Bitmaps Jones 3 2,542 May 3, 2006 07:57 PM
Last Post: OneSadCookie