• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImage -> OpenGL textures?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage -> OpenGL textures?


  • Subject: Re: NSImage -> OpenGL textures?
  • From: email@hidden
  • Date: Sat, 2 Feb 2002 17:12:28 -0800

I've got it working... it was a lot of code... especially for textures larger than 1024... you have to cut your image up into tiles.

but assuming that you want to just load a small JPG image into GL... just grab the 24 bit representation, and get its bitmapData.

then what i did was expand this to 32 bit ARGB data in a simple loop... stored in a variable called pixels, with width and height being obvious

then i just told the texture target about the data.

GLuint texture_target = GL_TEXTURE_RECTANGLE_EXT;
// use glGenTextures() to create a texture_id...
glBindTexture(texture_target, texture_id);
glTexParameterf(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(texture_target, GL_TEXTURE_PRIORITY, 0.0);
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
glTexImage2D(texture_target, 0, GL_RGBA8, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
glTexParameterf(texture_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(texture_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(texture_target, 0);

then in my view i did this in initWithFrame:

NSOpenGLPixelFormat *fmt;
NSOpenGLPixelFormatAttribute attribs[] = {
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute) 24,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute) 8,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute) 0,
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute) 0,
NSOpenGLPFAAccumSize, (NSOpenGLPixelFormatAttribute) 0,
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFANoRecovery,
(NSOpenGLPixelFormatAttribute) 0
};

fmt = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs] autorelease];

if (self = [super initWithFrame:frameRect pixelFormat:fmt]) {
[[self openGLContext] makeCurrentContext];

}

then in drawRect, you set up your projection and modelview matrices to identity, set the viewport to the size of the image.
then do any scale/trans/rotate you want, then draw the image...

glEnable(texture_target);
glBindTexture(texture_target, texture_id);

glColor4f(1.0, 1.0, 1.0, 1.0);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0, 0);
glTexCoord2i(imageWidth, 0);
glVertex2i(imageWidth, 0);
glTexCoord2i(imageWidth, imageHeight);
glVertex2i(imageWidth, imageHeight);
glTexCoord2i(0, imageHeight);
glVertex2i(0, imageHeight);
glEnd();

glBindTexture(texture_target, 0);
glDisable(texture_target);


i cut and pasted this out of my OGLView, OGLImage and OGLTexture classes, so it works, but you'll need to glue it all together...


On Saturday, February 2, 2002, at 04:38 PM, Daniel Kaesmayr wrote:

Has anyone solved the problem of getting a NSImageRep that can be used for
OpenGL textures? I would appreciate any pointers or links to sample code :)

Thanx,

Daniel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >NSImage -> OpenGL textures? (From: Daniel Kaesmayr <email@hidden>)

  • Prev by Date: MultiProcessing & Cocoa...
  • Next by Date: Re: slightly OT (unblocking accept)
  • Previous by thread: NSImage -> OpenGL textures?
  • Next by thread: Disabling NSButton programmatically?
  • Index(es):
    • Date
    • Thread