LWJGL Forum

Programming => OpenGL => Topic started by: polskyman on October 28, 2006, 00:56:05

Title: impossible to make the texture working
Post by: polskyman on October 28, 2006, 00:56:05
Hi,

I do not want use the Devil loader for image.
I use pixelgrabber to store the image data in an integer pixel.

please help me how to load the int[] pixel data containing A,R,G,B info on 32 bits into the glTexImage2D

thanks




int[] texture=texture[100]   // 100 textures maximum

void loadtexture(int[] pixel)   // the pixel array generated by pixel grabber (contain an int for ARGB)
{


GL11.glPixelStorei (GL11.GL_UNPACK_ALIGNMENT, 1);
           GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[texcompt]);
//texcompt is counter for the texture number


           GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_MAG_FILTER,GL11.GL_LINEAR);
           GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_MIN_FILTER,GL11.GL_LINEAR);


IntBuffer data = IntBuffer.allocate(pixel.length);
           data.put(pixel);
           data.rewind();

GL11.glTexImage2D(GL11.GL_TEXTURE_2D,0,GL11.GL_RGBA,width,height,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,data);

}

Title: impossible to make the texture working
Post by: polskyman on October 29, 2006, 21:05:48
please help me.
I really need this to work
Title: impossible to make the texture working
Post by: biggeruniverse on October 29, 2006, 21:23:13
Try running the data through this first:

private static byte[] convertIntegersToBytes (int[] integers) {

       if (integers != null) {

           byte outputBytes[] = new byte[integers.length * 4];



           for(int i = 0, k = 0; i < integers.length; i++) {

               int integerTemp = integers[i];

               for(int j = 0; j < 4; j++, k++) {

                   outputBytes[k] = (byte)((integerTemp >> (8*j)) & 0xFF);

               }

           }

           return outputBytes;

       } else {

           return null;

       }

   }
Title: impossible to make the texture working
Post by: darkprophet on October 30, 2006, 01:09:31
Your half right there biggeruniverse; the only problem is that your the INT is ARGB, and OGL takes it as RGBA...

so that needs conversion too...but your on the right tracks

DP
Title: impossible to make the texture working
Post by: biggeruniverse on October 30, 2006, 11:59:48
I believe it has worked for me in the past, but I can't remember now. At any rate, it's going to show something closer to the original image than just sending int data in a buffer. Plus this function could be seriously optimized, so keep that in mind.

EDIT:

It occurs to me that you could unroll the inner loop, and then you have many options about component ordering- maybe pass in a specifier.
Title: impossible to make the texture working
Post by: darkprophet on October 30, 2006, 17:39:40
yup, your right...but shouldn't the inner loop's code be like ?


outputBytes[k*4 + j] = (byte)((integerTemp >> (8*j)) & 0xFF);


Notice the index used to reference the outputBytes array. But yes, you could unroll the loop and you would need to swich the ordering from ARGB to RGBA...

DP
Title: impossible to make the texture working
Post by: biggeruniverse on October 31, 2006, 05:27:38
No, the inner loop is correct.
Title: impossible to make the texture working
Post by: darkprophet on November 02, 2006, 17:02:39
It isn't correct because the index of the byte never changes inside the inner loop, your just going to be overwriting the same value 4 times....

your trying to split the Integer into 4 bytes....look at it carefully.

DP
Title: hmmmmmmm...
Post by: Fool Running on November 02, 2006, 19:42:33
The loop is correct. He is using a hard to read and follow inner and outer loop  :lol: . Notice that the inner loop (j) also increments k. k is separate from i (the outer loop).
It is correct, but hard to follow :D

EDIT: Maybe this rewrite will help:
int k = 0;
for(int i = 0; i < integers.length; i++){
   int integerTemp = integers[i];
   for(int j = 0; j < 4; j++){
       outputBytes[k] = (byte)((integerTemp >> (8*j)) & 0xFF);
       k++;
   }
}

Its the same loop, but readable :)
Title: impossible to make the texture working
Post by: darkprophet on November 02, 2006, 21:52:44
DOH! Big doh!

Apologies...

DP