Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to load imagefile for texture (Leopard)



Generally speaking, to load images from the disk you have 2 options: use ImageIO directly, or use NSImage which itself will use ImageIO.

In the case of NSImage, what you want to do is get a bitmap representation (an instance of NSBitmapImageRep, see the documentation for that class). NSImage has methods to get representations.

In turn, NSBitmapImageRep will get you access to the raw pixel data through its -bitmapData method.

Once you have the raw pixel data, you can simply use TexImage2D to create a new texture (on the GPU) or TexSubImage2D to update an existing texture with the pixel data. NSBitmapImageRep has other methods you can use to determine certain information about the image, such as the presence of an alpha channel and the row byte size.

Be aware that NSBitmapImageRep may not give you an optimal format for the pixels.

Concerning the image views and cells you have, every image cell displays an NSImage instance, and so you need only get the NSImage value of an NSImageCell and do as above.

I will leave using ImageIO directly as an exercise to you since it is a more advanced API. A good starting document is the ImageIO Programming Guide at http://developer.apple.com/documentation/GraphicsImaging/Conceptual/ImageIOGuide/imageio_intro/chapter_1_section_1.html .

As for CIImage, it is only useful within the scope of Core Image. If you are not going to be using Core Image, CIImage is of little use to you.

Finally, make sure to read the OpenGL Programming Guide for Mac OS X, specifically the section on textures at http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_1.html .

On 28-May-08, at 03:13, Mike mcFin wrote:
Hello,

I would like to load an imagefile to be used as a texture (.png or .jpg).

I have looked several examples (e.g. PBORenderToVertexArray load_texture() ) and I can't believe that I need 30+ lines of code for just to load an image while there are NSImage etc. classes which does same with one extra initParameter.

1) With Leopard what is the "correct" and easy way to load texture from file (inside appbundle) ?

2) I have also several small images on view as NSImageView or NSImageCell. How can I use those as a texture?

I am trying to learn the differences with NSImage, CIImage, ImageRef, etc.. (as apparently can be seen from my question).

Thanks.

-Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >How to load imagefile for texture (Leopard) (From: "Mike mcFin" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.