1

I'm trying to port my Java OpenGL code on Android to the Native SDK and I need an IntBuffer implementation.

Basically what I do in Java to load up an arbitrary integer RGBA pixel color array into a texture is:

    // pixel array
    pixelIntArray = new int[width * height];

    bb = ByteBuffer.allocateDirect(pixelIntArray.length * 4);
    bb.order(ByteOrder.nativeOrder());

    // native buffer
    pixelBuffer = bb.asIntBuffer();

    // push integer array of pixels into buffer
    pixelBuffer.put(pixelIntArray);
    pixelBuffer.position(0);

    // bind buffer to texture
    gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, width, height, 0,
                GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);

in C so that I can push a texture to a quad using a buffer.

Currently I'm just binding it to my pixelIntArray in C and the texture comes out distorted.

Basically I need to be able to bind a series of colors in an integer pixel array to a texture through a buffer similar to Java's NIO class.

2
  • Why did you delete this question that you posted a while ago? Commented Jan 21, 2013 at 2:45
  • Had to change the title. Commented Jan 21, 2013 at 3:02

1 Answer 1

0

I think this may be how to solve it:


Initialize


    int length = width * height;

    int* pixels = (int*) malloc(sizeof(int) * length);
    unsigned char * buffer = (unsigned char*) malloc(sizeof(char) * length * 4);

Copy to buffer


    int i, j;

    for (i = 0; i < length; i++) {

        j = 4 * i;

        buffer[j] = (char) (pixels[i] & 0xFF);
        buffer[j + 1] = (char) (pixels[i] >> 8 & 0xFF);
        buffer[j + 2] = (char) (pixels[i] >> 16 & 0xFF);
        buffer[j + 3] = (char) (pixels[i] >> 24 & 0xFF);

    }

Source


From: http://www.c-sharpcorner.com/Forums/Thread/32972/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.