From: Robert Klemme Date: 2009-12-08T01:23:53+09:00 Subject: Re: Reading Images 2009/12/7 Alexandro Kez : > > 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 Do you have to unpack? I don't know the GL API but I doubt it would require to unpack the String. Did you test what happens when you unpack? You get an Array full of ints. That does not look like a type that a low level graphics rendering library would use. Methinks GL would rather use a String (as the Ruby type for binary data). What do the docs say? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/