From: Xavier Date: 2006-05-29T16:12:04+09:00 Subject: PNG to OpenGL Texture (libpng) Hi, I'm trying to load a PNG file into an OpenGL texture using ruby-libpng-0.3.3 I can't quite figure out how to convert libpng data to the correct format. I've dumped png.read_image to screen and it looks like my picture (with numbers instead of colors). At the moment I'm trying to use this index as my Red index (just to get something displaying) but am getting a white square instead. I'm already using textures for fonts, so I know that bit works. Any Ideas? As an aside, if anyone has a better x-platform way of doing this I'm all ears... - Xavier # Load a test png rpng = Reader.new('res/img/test.png'); width, height, bit_depth, color_type, interlace_type, compression_type, filter_type = rpng.get_IHDR puts width # 20#for i in (0..height) # buffer += data[i].pack("C*") #end puts height # 20 puts bit_depth # 8 puts color_type # 6 .. not sure what this means yet #for i in (0..height) # buffer += data[i].pack("C*") #end # Create and bind to OGL texture @testogl = GL::GenTextures(1)[0]; GL.BindTexture(GL::TEXTURE_2D, @testogl); GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::CLAMP); GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::CLAMP); GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER,GL::LINEAR); GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER,GL::LINEAR); # Abomination follows data = rpng.read_image data2 = data.flatten data3 = "" for i in (0..data2.length-1) data3 += " " data3[i] = data2[i] end GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RED, width, height, 0, GL::RED, GL::UNSIGNED_BYTE, data); -- Posted via http://www.ruby-forum.com/.