Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: OpenGL ES Texturing question

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2013

    OpenGL ES Texturing question

    First off I know this isn't the place to post this, but the opengl es forum seems a bit dead. I'm trying to port some C code to run on an android device, and what I need is to draw a 2-D array of RGBA integers to the screen. These integers obviously correspond to pixels, and in C I'd do this via glDrawPixels. However in OpenGL es that doesn't seem to be a possibility, so I'm exploring other options. My current strategy is to draw a square and apply my int array as a texture map, and I can't seem to figure out why the code below doesn't work. I'm following a guide I found that I'd gladly post the link to if I could, and I'm using the ClearRenderer class as outlined in an android blog post (that I've tried and failed to link 3 times now.)

    I hate to just throw my code at you and expect results, but I'm pretty stumped. I'm open to any suggestions re: getting these integers on the screen, but this texturing route is all I can think of. In the code below the array is 200x200, and rather than use an int array I must use Java's ByteBuffer class. The image is completely red at the moment, though all I see on the screen is a black square.

    Code :
    class ClearRenderer implements GLSurfaceView.Renderer {
            private FloatBuffer coords;
            private FloatBuffer texCoords;
            private ByteBuffer PXA;
            private IntBuffer tex;
            public ClearRenderer(){
                    float[] coords = {
                                    0f, 1f, 0f,
                                    1f, 1f, 0f,
                                    0f, 0f, 0f,
                                    1f, 0f, 0f,
                    float[] texC = {
                    0f, 0f,                                
                    1f, 0f,
                    0f, 1f,
                    1f, 1f
                    this.coords = makeFloatBuffer(coords);
                    this.texCoords = makeFloatBuffer(texC);
                    //Allocate enough space for a 200x200 array of ints
                    this.PXA = ByteBuffer.allocateDirect(200*200*4);
                    //Just fill it with red to test
                    while (this.PXA.hasRemaining())
                    //Return to start of buffer
                    //We only need one int here
                    this.tex = IntBuffer.allocate(1);
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            GLU.gluOrtho2D(gl, -5f, 5f, -5f, 5f);
            gl.glGenTextures(1, this.tex);
        public void onDrawFrame(GL10 gl) {
            gl.glClearColor(0f, 0f, 0f, 1f);
            gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, this.tex.get(0));
            gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, 200, 200, 0, GL10.GL_RGBA,         GL10.GL_UNSIGNED_BYTE, PXA);
            gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.coords);
            gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, this.texCoords);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
            private FloatBuffer makeFloatBuffer(float[] arr){
                    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4);
                    FloatBuffer fb = bb.asFloatBuffer();
                    return fb;

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2013
    Hey all, if anyone cares I found the answer to my question here:

    Thanks to Lizzard for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts