From: Rob Biedenharn Date: 2009-12-08T01:26:12+09:00 Subject: Re: Reading Images A jpeg is more complicated that that. (All image formats are actually.) Here's http://gist.github.com/89738 some code that can find the width and height of an image in PNG, GIF, or JPEG format. Notice how much more complicated the JPEG code is because you have to find the right JFIF segment and there can be embedded thumbnails and such so a simple regexp search for the first part that looks like the size won't work. You might want to look at ImageMagick (RMagick is the ruby interface) or some other image library that will find the pixel data for you. -Rob On Dec 7, 2009, at 11:05 AM, Alexandro Kez wrote: > > Ok, here's the code. I'm just trying to load it and put on a quad. 500 > and 500 are the original width and height of pic. > > name = GL.GenTextures(1); > > data = File.open("grass.jpg", "rb") {|io| io.read} > > GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1); > > GL.BindTexture(GL::TEXTURE_2D, name[0]); > > 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::NEAREST); > GL.TexParameteri(GL::TEXTURE_2D, > GL::TEXTURE_MIN_FILTER,GL::NEAREST); > GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, 500, > 500, 0, GL::RGBA, GL::UNSIGNED_BYTE, > data.unpack("C*")); > > > GL.BindTexture(GL::TEXTURE_2D,name[0]); > GL.Begin(GL::QUADS); > GL.TexCoord(0.0, 0.0); GL.Vertex(-20.0, 0.0, -20.0); > GL.TexCoord(0.0, 1.0); GL.Vertex(-20.0, 0.0, 20.0 ); > GL.TexCoord(1.0, 1.0); GL.Vertex(20.0, 0.0, 20.0 ); > GL.TexCoord(1.0, 0.0); GL.Vertex(20.0, 0.0, -20.0 ); > GL.End(); > > > > The error I get: > Length of specified data doesn't correspond to format and type > parameters passed. Calculated length: 1000000 (ArgumentError) > > As I think it may be due to the fact it contains more data, like width > and height in itself and the datatypes, just don't get it. By the way, > if I read it, it's still a string, why? Why do I have to pack/unpack? > thanks to every respond > -- > Posted via http://www.ruby-forum.com/. > Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com +1 513-295-4739 Skype: rob.biedenharn