impossible to make the texture working

Started by polskyman, October 28, 2006, 00:56:05

Previous topic - Next topic

polskyman

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);

}

polskyman

please help me.
I really need this to work

biggeruniverse

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;

        }

    }

darkprophet

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

biggeruniverse

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.

darkprophet

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

biggeruniverse


darkprophet

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

Fool Running

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 :)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

darkprophet