• 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: OpenGL Texturing Example
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OpenGL Texturing Example


  • Subject: Re: OpenGL Texturing Example
  • From: Dylan Neild <email@hidden>
  • Date: Wed, 25 Sep 2002 12:18:41 -0400

Whoops.

That should be...

glBegin(GL_QUADS);
glTexture2f(<positioning parameters>); glVertex3f(1.0f, 1.0f, -1.0f);
glTexture2f(<positioning parameters>); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexture2f(<positioning parameters>); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexture2f(<positioning parameters>); glVertex3f(1.0f, -1.0f, -1.0f);
glEnd();

Sorry.

Dylan


On Wednesday, September 25, 2002, at 09:46 AM, Dylan Neild wrote:


Hey John,

OpenGL is pretty flexible, at least under OS X, as far as what images it can accept as textures.

This code is written from memory, so it might not compile straight away. In particular, I might be missing an argument or something on the glTexImage2D function.. so use with caution and be sure to double check what I'm doing first. :)

Assuming you're working in cocoa:

// to load texture
GLuint myTexturePointer[1];
GLint imageType, imageWidth, imageHeight;
NSData *myImageData = [NSData dataWithContentsOfFile:@"/images/myimage.jpg"];
NSBitmapImageRep *myImageRep = [NSBitmapImageRep imageRepWithData:myImageData];

imageWidth = [myImageRep pixelsWide];
imageHeight = [myImageRep pixelsHigh];

if ([myImageRep.bytesPerPixel] == 3) imageType=GL_RGB;
else if ([myImageRep.bytesPerPixel == 4) imageType=GL_RGBA;

glEnable(GL_TEXTURE_2D);
glGenTextures(1, myTexturePointer);
glBindTexture(GL_TEXTURE_2D, myTexturePointer[0]);

gTexImage2D(GL_TEXTURE_2D, 0, imageType, pixelsWide, pixelsHigh, imageType, 0, GL_UNSIGNED_BYTE, [myImageRep bitmapData]);

// to use texture

glBindTexture(GL_TEXTURE_2D, myTexturePointer[0]);

glBegin(GL_QUADS);
glVertex2f(<positioning parameters>); glVertex3f(1.0f, 1.0f, -1.0f);
glVertex2f(<positioning parameters>); glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex2f(<positioning parameters>); glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex2f(<positioning parameters>); glVertex3f(1.0f, -1.0f, -1.0f);
glEnd();

glFlush(); (-or- preferably, [glContext flushBuffer] if you're using a double buffered context, which I recommend you do). :)

Hope this helps a bit,

Dylan
_______________________________________________
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: 
 >Re: OpenGL Texturing Example (From: Dylan Neild <email@hidden>)

  • Prev by Date: Force Finder to redisplay changed custom icon
  • Next by Date: Re: How to use SystemStarter in 10.2?
  • Previous by thread: Re: OpenGL Texturing Example
  • Next by thread: building & distributing frameworks
  • Index(es):
    • Date
    • Thread