Date: Thu, 19 Aug 2004 12:09:33 +0200 (CEST) Message-Id: <20040819.120933.41629782.oandrieu at nerim.net> To: seguso.forever at tin.it Cc: lablgtk at kaba.or.jp Subject: Re: Loading a texture from file and applying it? From: Olivier Andrieu In-Reply-To: <200408181845.37672.seguso.forever at tin.it> References: <200408181845.37672.seguso.forever at tin.it> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Maurizio Colucci [Wed, 18 Aug 2004]: > Hello again, > > In lablgl + lablgtk, I need to load a texture from file and apply it to a > triangle. > > More precisely: GlTex.image2d wants a byte array as a GlPix. I need > to know how to create a GlPix from a png file (or similar). You can use GdkPixbuf: it will load the png file and convert it into a "pixel buffer" structure. You then need to convert this into a Raw array. The easiest way is to do this: ,---- | let raw_of_pixbuf pb kind = | Raw.of_string (Gpointer.string_of_region (GdkPixbuf.get_pixels pb)) ~kind `---- But that will copy the pixel data twice: once from the pixbuf into a caml string then from the caml string into the raw array, so it's not as efficient as it could be. It's possible to share the pixel data between the pixbuf and the raw array but it's a bit messy (breaks encapsulation). If you're interested, I can send you the code to do this. > The GlPix should have rgba format, and the png file may not have > alpha information. Use GdkPixbuf.get_has_alpha and GdkPixbuf.add_alpha . -- Olivier