PDA

View Full Version : WebGL- Sending textures from JS to shader- problems



Skorpius
11-07-2013, 12:39 PM
I literally have no idea what I need to do to fix the code- I'm trying to send color information from javascript to webgl via shaders- I have a showing program- I basically want (at this point) to be able to print out my shader onto the screen, but all it does it show black :/

IN javascript:




var count=0;
var table = new Float32Array(128*4);

for (var y = 0; y<(128*4); y+=1) {

var sig = .35;


table[count++] = sig;
table[count++] = sig;
table[count++] = sig;
table[count++] = 1;




}

//alert(count);
//alert(table[101]);


gl.activeTexture(gl.TEXTURE2);


texturetab = gl.createTexture();

gl.bindTexture(gl.TEXTURE_2D, texturetab);

gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);

gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 128*4, 1, 0,

gl.RGBA, gl.FLOAT, table);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);


gl.useProgram(prog);

//irrelevant code taken out for conciseness

gl.uniform1i(gl.getUniformLocation(prog, "uTabSamp"), 2);




Fragment Shader:


uniform sampler2D uTabSamp;

const float d = 0.001953125; // 1./512. our delta (finite difference)

void main(void) {

sigmoid = texture2D(uTabSamp, vec2(2.5/128. ,.5)).r;

//irrelevant code taken out

gl_FragColor = vec4(texture2D(uTabSamp, vec2(3.0/128. ,.5)).r, 0,0,1. );


}


Basically, I want to see that I'm at least getting some output on the screen from the texture- all I get is a black screen, though...