I have a byte Buffer array
static IntBuffer byteBuffer = BufferUtils.createIntBuffer(8300000);
I put a lot of pixels on it like following :
byteBuffer.put(256) // ALPHA
byteBuffer.put(150) // RED
byteBuffer.put(152) // GREEN
byteBuffer.put(23) // BLUE
byteBuffer.put(152) // ALPHA
... etc etc
In my Render class that implements GLSurfaceView.Renderer
, I have this 3 methods overrided :
public void onDrawFrame(GL10 gl) {
gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, 1920, 1080, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, SocketActivity.byteBuffer);
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
init(width, height);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
I want to rendera big texture on 1920x1080 resolution that's why I allocated 8300000 (1920*1080*4).
But it does not display anything.
Resolved ! Here is the order for anyone who wanna do it.
In init
function :
glViewport(GL_ZERO, GL_ZERO, width, height);
glGenTextures(1, &idTexture);
glBindTexture(GL_TEXTURE_2D, idTexture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, idTexture);
glUseProgram(gProgram);
In draw
function :
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, GL_ZERO, GL_RGB, width, height, GL_ZERO, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat), vertices);
glVertexAttribPointer(inputTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat), vVertices);
glEnableVertexAttribArray(gvPositionHandle);
glEnableVertexAttribArray(inputTextureCoordinate);
glUniform1i(baseMapLoc, GL_ZERO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
You see the idea. Thank you very much to all those who enlightened me.