0
votes

My webgl program renders a white square, however whenever I try to pass a varying variable to the fragment shader it disappears, even if all the fragment shader does is: `gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);

this renders nothing

   <script id="shader-vs" type="x-shader/x-vertex">
        attribute vec3 vertexPos;
        attribute vec4 aColor;

        varying vec4 color;

        void main(void)
        {
            gl_Position = vec4(vertexPos, 1.0);
            color = aColor;
        }
    </script>
    <script id="shader-fs" type="x-shader/x-fragment">
        precision mediump float;

        varying vec4 color;

        void main(void) 
        {
            gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
        }
    </script>

this renders a white square

    <script id="shader-vs" type="x-shader/x-vertex">
        attribute vec3 vertexPos;
        attribute vec4 aColor;

        varying vec4 color;

        void main(void)
        {
            gl_Position = vec4(vertexPos, 1.0);
            //color = aColor;
        }
    </script>
    <script id="shader-fs" type="x-shader/x-fragment">
        precision mediump float;

        varying vec4 color;

        void main(void) 
        {
            gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
        }
    </script>
1
How are you setting up your attributes? If you hardcoded your attribute locations I'm guessing adding aColor changed the locations of the attributes and so you're not setting them up correctly.gman
@gman cbuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, cbo); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 1, 1, 1]), gl.STATIC_DRAW); .... vertex data stuff..... vertexColorAttribute = gl.getAttribLocation(glProgram, "aColor"); gl.enableVertexAttribArray(vertexColorAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, rect.cbuffer); gl.vertexAttribPointer(vertexColorAttribute, 4, gl.FLOAT, false, 0, 0); I hope it is slightly readableTopkek Mango
@gman resolved it by making my color array 4 * 5 instead of 4 * 1Topkek Mango
@TopkekMango: the usual StackOverflow method of marking question solved is to accept an answer. If you solved it yourself, write your solution into an answer and accept that.datenwolf
@datenwolf It says I can't accept my own answer for another 2dayTopkek Mango

1 Answers

1
votes

after reviewing my code I noticed that I only sent aColor to 1 out of the 5 vertices resolved it by making my color array 4 * 5 instead of 4 * 1