"but now I'm having another problem (sigh), i'm loading an image with
alpha, and its almost correct, but its appearing a bit seethrough and
the colors a bit off. I'm guessing it might have to do with the byte
order set in glPixelStore or glTextImage2D etc.... but I couldn't find
a solution. I'm also a bit wary of whether or not it it will behave
differently on intel vs powerpc - i.e. I'd like it to be failsafe and
generic (checking the system etc.) instead of just trial and error
working on my machine.... I've included the core of the code below
(minus other stuff for position, scale etc.), it's for a class which
(is supposed to) just take care of loading a file and rendering it"
I actually just found a solution to this problem - changing
kCGImageAlphaPremultipliedFirst to kCGImageAlphaPremultipliedLast in
the CGBitmapContextCreate works for me - but I'm not sure if this is
hackish solution for this file or my machine, or whether thats how it
should be fullstop regardless of file format and/or architexture.. I"m
reading through the Quartz Programming Guide, but it is 224 pages and
if anyone knows the answer would be much appreciated :P ...
cheers,
Memo (Mehmet S. Akten)
www.memo.tv
[EMAIL PROTECTED]
On 8 Jun 2008, at 00:03, Memo Akten wrote:
Thanks for the tips Christopher, learning a lot...
P.S. my opengl texture appears upside down even though i'm sure
my mapping
coordinates are correct :S I guess I can just flip the
coordinates, but is
it a setting somewhere or is it normal? (difference in coordinate
system
perhaps?)
GL stuff always winds up flipping. How are you creating the
image? I've not worked with image generation using the official-
API, but we've had success generating QCImages from file data by
using Core Image as an intermediate ([CIImage
imageFromData:imageFileData]) -- maybe post some simple image-
creation code?
I'm using CGImageSourceCreateWithURL and I've included the source
code below. The vertical flip was me being stupid - I forgot the
coordinate system in openGL was upwards +ve, so it was my texture
coordinates which were wrong :o
but now I'm having another problem (sigh), i'm loading an image with
alpha, and its almost correct, but its appearing a bit seethrough
and the colors a bit off. I'm guessing it might have to do with the
byte order set in glPixelStore or glTextImage2D etc.... but I
couldn't find a solution. I'm also a bit wary of whether or not it
it will behave differently on intel vs powerpc - i.e. I'd like it to
be failsafe and generic (checking the system etc.) instead of just
trial and error working on my machine.... I've included the core of
the code below (minus other stuff for position, scale etc.), it's
for a class which (is supposed to) just take care of loading a file
and rendering it
any suggestions welcome! I might post this in the opengl list if I
can't get anywhere...
Cheers,
Memo.
@interface MSA_GLTexture : NSObject {
GLuint width, height;
GLuint myTextureName;
CGLContextObj cgl_ctx;
}
- (id)initWithImage:(NSString *)imageName andContext:
(CGLContextObj)_cgl_ctx;
- (void)render;
@end
@implementation MSA_GLTexture
- (id)initWithImage:(NSString *)imageName andContext:
(CGLContextObj)_cgl_ctx {
if(self = [super init]) {
cgl_ctx = _cgl_ctx;
NSBundle *thisBundle=[NSBundle bundleForClass:[self class]];
NSString *imagePath=[thisBundle pathForResource:imageName
ofType:nil];
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)
imagePath, kCFURLPOSIXPathStyle, 0);
CGImageSourceRef myImageSourceRef =
CGImageSourceCreateWithURL(url, nil);
CGImageRef myImageRef = CGImageSourceCreateImageAtIndex
(myImageSourceRef, 0, nil);
width = CGImageGetWidth(myImageRef);
height = CGImageGetHeight(myImageRef);
CGRect rect = {{0, 0}, {width, height}};
void * myData = calloc(width * 4, height);
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef myBitmapContext = CGBitmapContextCreate (myData,
width, height, 8, width*4, space, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(myBitmapContext, rect, myImageRef);
CGContextRelease(myBitmapContext);
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &myTextureName);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, width, height,
0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, myData);
free(myData);
}
return self;
}
-(void)render {
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, height); glVertex3f(-0.5f,
-0.5f, 0.0f);
glTexCoord2f(width, height); glVertex3f(0.5f, -0.5f,
0.0f);
glTexCoord2f(width, 0.0f); glVertex3f(0.5f, 0.5f,
0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, 0.5f,
0.0f);
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected]
)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/memo%40memo.tv
This email sent to [EMAIL PROTECTED]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]