Results 1 to 7 of 7

Thread: Creating textures from data

  1. #1

    Creating textures from data

    Heres the (concise) version of what Im doing

    Code :
    var b = new ArrayBuffer(32*32*4);
    var v1 = new Uint8Array(b);
    for ( var i=0; i<32*32*4; i++ )
       v1[i] = i%255;
     
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 32, 32, 0, gl.RGBA, gl.UNSIGNED_BYTE, v1);

    but nothings showing up when I draw the texture its just black, no errors

    Im not 100% sure if Im doing the arraybuffer thing correct,
    heres the spec
    http://www.khronos.org/registry/typedar ... cs/latest/

    Anyone have any ideas whats going wrong,
    cheers zed

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Creating textures from data

    I did this (based on your code - but Vulcan-mind-melded with some of mine):

    Code :
      var b = new ArrayBuffer(32*32*4);
      var v1 = new Uint8Array(b);
     
      for ( var i=0; i<32*32*4; i++ )
        v1[i] = i%255;
      var texture = gl.createTexture () ;
      gl.bindTexture  ( gl.TEXTURE_2D, texture ) ;
      gl.texParameteri ( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
                                                     gl.LINEAR_MIPMAP_LINEAR ) ;
      gl.texParameteri ( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR ) ;
      gl.texParameteri ( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT ) ;
      gl.texParameteri ( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT ) ;
      gl.texImage2D (gl.TEXTURE_2D, 0, gl.RGBA, 32, 32, 0, gl.RGBA,
                           gl.UNSIGNED_BYTE, v1);
      gl.generateMipmap ( gl.TEXTURE_2D ) ;

    ...and it worked OK inside my application. I'd start with that. If it doesn't work - then there is something wrong elsewhere in your application. If it does work and then pull out lines one at a time until it breaks - then you'll know what critical part you were missing!

    -- Steve

  3. #3

    Re: Creating textures from data

    cheers again steve, seems like we're the only ppl on this forum

    Im pretty sure thats pretty much what Ive got already, Ill check fully later though.
    Well at least I know thats the correct way to set up the ArrayBuffer

  4. #4

    Re: Creating textures from data

    hmm embarrassing, I was doing
    image.onload = function() { updateTexturePixels( data ); }

    of course the function wasnt getting called, since the image wasnt being loaded from somewhere

  5. #5
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Creating textures from data

    Yeah - I could easily see how that would happen!

  6. #6

    Re: Creating textures from data

    One of those imfamous copy/paste bugs. Still its not gonna stop me from copying + pasting code, cause I rarely make them.
    This would of been easy to find if there was a decent debugger for javascript that lets u step easily through code. Sure theres inbuilt debuggers in the browsers (chrome is a bit better than firebug IMHO) but compared to a C++ IDE theyre a pain, I find its actually easier to chuck a few log( "blah" ); through the code to debug.
    RANT - though if javascript had strong typed variables etc I would make 10x fewer mistakes, coding in javascript's driving me nuts.

  7. #7
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Creating textures from data

    Yeah...I agree. I hate JavaScript with a passion! It's horrible to not spot something as stupid as a typo in a variable name until the line of code is actually executed! Don't we have computers that can check that stuff for us?!

Similar Threads

  1. Creating buffers
    By jajce85 in forum OpenCL
    Replies: 8
    Last Post: 08-08-2012, 06:09 AM
  2. texturing from alpha data to RGBA data
    By neha.bhende in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 0
    Last Post: 05-14-2012, 05:50 AM
  3. eglCreatePBufferFromClientBuffer not creating
    By sammy in forum Cross API and window system integration
    Replies: 1
    Last Post: 11-24-2011, 06:42 AM

Posting Permissions

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