Another core graphics question -- textures

So, I was using gworlds before in Carbon to import textures to opengl. Unfortunately, when I build a universal application the compiler says the calls I’m using are going to be deprecated. So, I saw the mac pdf reference from another post on the mac opengl board and it had an example of reading in a file with quartz. Anyhow, the example code works fine with one little issue – the textures are all upside down! I had the same problem with my previous code which led to a transform solution:

//this works in the old code…
MatrixRecord matrix;
SetIdentityMatrix (&matrix);
TranslateMatrix ( &matrix, -X2Fix(0.5f * imageWidth), -X2Fix(0.5f * imageHeight));
ScaleMatrix (&matrix, X2Fix(1.0), X2Fix(-1.0), X2Fix (0.0), X2Fix (0.0));
TranslateMatrix ( &matrix, X2Fix(0.5f * imageWidth), X2Fix(0.5f * imageHeight));
err = GraphicsImportSetMatrix(giComp, &matrix);

Quartz has a similiar mechanism but I cant get it to work. I suspect its related to these calls…

CGContextRef myBitmapContext = CGBitmapContextCreate (myData,
width, height, 8,
width4, space,
kCGImageAlphaPremultipliedFirst);
/

CGContextTranslateCTM(myBitmapContext, -width *0.5, -height *0.5 );
CGContextScaleCTM(myBitmapContext, 0, -1);
CGContextRotateCTM(myBitmapContext,M_PI);
CGContextTranslateCTM(myBitmapContext, width 0.5, height0.5 );
*/
CGContextRotateCTM(myBitmapContext,M_PI);
CGContextDrawImage(myBitmapContext, rect, myImageRef);
CGContextRelease(myBitmapContext);

return myImageRef;

Some apple examples just have the 180 degree rotation…does not seem to work for me. Most of the examples are textures and I’m not sure if they realize they are upside down.(?)

Anyhow, the quartz stuff just produces a black texture… :frowning: Any ideas??

As an aside, an upside down normal map import is going to create some really ugly results. ;p

Figured it out. ( more like googled it out )

CGContextTranslateCTM(myBitmapContext, 0, height);
CGContextScaleCTM(myBitmapContext, 1.0, -1.0);

Shoot, seem to be running into another problem.

If I use kCGImageAlphaPremultipliedFirst in

CGContextRef myBitmapContext = CGBitmapContextCreate (myData,
width, height, _bits,
width*4, space,
kCGImageAlphaPremultipliedFirst);

call then I get a nice texutre. Looks great with everything ( particularly leaves ) except for a few cases. For instance, if I have an explosion image. There is alot of aplha and its not constant. The explosion looks like a gray blob. The reds and oranges get premultipled to a gray like color.

OK, one would think just dont premultiply the alpha and use kCGImageAlphaFirst. But this always returns nothing in everycase. No more texture.

Shoot…

Darn, looks like you have to have premultiplied alpha.

http://developer.apple.com/qa/qa2001/qa1037.html

well, sorry, i can’t help you- i just came here because i like monologue threads :smiley: if you decide to register here, i recommend your nickname should be ‘hamlet’

premultiplied alpha in this blog may help

http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.