我怎样才能绑定的整数颜色的像素阵列来使用Android NDK纹理? [英] How can I bind a pixel array of integer colors to a texture using the Android NDK?
问题描述
我试图端口Android上我的Java的OpenGL code到本地SDK,我需要一个IntBuffer实现。
I'm trying to port my Java OpenGL code on Android to the Native SDK and I need an IntBuffer implementation.
基本上我用Java做的任意整数RGBA像素的彩色阵列加载到纹理是:
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);
用C,这样我可以用一个缓冲推纹理四。
in C so that I can push a texture to a quad using a buffer.
目前我只是将它绑定到我用C pixelIntArray和质感散发出来扭曲。
Currently I'm just binding it to my pixelIntArray in C and the texture comes out distorted.
基本上,我需要能够通过类似于Java的NIO类的缓冲区以整数像素阵列结合一系列的颜色到纹理。
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.
推荐答案
我想这可能是如何解决这个问题:
I think this may be how to solve it:
int length = width * height;
int* pixels = (int*) malloc(sizeof(int) * length);
unsigned char * buffer = (unsigned char*) malloc(sizeof(char) * length * 4);
复制到缓冲区
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);
}
来源
来源: http://www.c-sharpcorner.com/论坛/主题/ 32972 /
Source
From: http://www.c-sharpcorner.com/Forums/Thread/32972/
这篇关于我怎样才能绑定的整数颜色的像素阵列来使用Android NDK纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!