'WebGL draw constant texture is black

I want to test constant texture, but when I give [0, 1, 0] as the param, the result is still black. Is any one know how to create a constant texture and how to modify my code.

createConstantTexture(buffer) {
        const gl = this.gl;
        this.texture = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, this.texture);

        // Because images have to be download over the internet
        // they might take a moment until they are ready.
        // Until then put a single pixel in the texture so we can
        // use it immediately. When the image has finished downloading
        // we'll update the texture with the contents of the image.
        const level = 0;
        const internalFormat = gl.RGB;
        const width = 1;
        const height = 1;
        const border = 0;
        const srcFormat = gl.RGB;
        const srcType = gl.UNSIGNED_BYTE;
        const pixel = new Uint8Array([buffer[0] * 255, buffer[1] * 255, buffer[2] * 255, 255]); // opaque blue
        gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);


        gl.bindTexture(gl.TEXTURE_2D, null);

        //this.ceateMipmap(gl, width, height);
    }


Solution 1:[1]

Sorry, I give the wrong shader, and it works now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 薛潇宇