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

Similar Threads

  1. texturing question
    By Savalia in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 09-22-2010, 04:23 PM
  2. texturing question
    By theophage in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 01-30-2006, 10:26 PM
  3. Dumb texturing question
    By Simon Hall in forum OpenGL: GLSL
    Replies: 2
    Last Post: 12-01-2004, 10:01 AM
  4. open gl texturing question
    By in forum OpenGL: Basic Coding
    Replies: 34
    Last Post: 02-16-2004, 10:37 AM
  5. Simple Texturing Question...
    By 2 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-08-2001, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean