shader uniform
This commit is contained in:
		
							parent
							
								
									66326bca06
								
							
						
					
					
						commit
						9922846acc
					
				
					 2 changed files with 13 additions and 6 deletions
				
			
		
							
								
								
									
										14
									
								
								index.ts
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								index.ts
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -27,8 +27,12 @@ class Renderer{
 | 
			
		|||
    gl : WebGL2RenderingContextStrict;
 | 
			
		||||
    constructor(gl: WebGL2RenderingContextStrict){
 | 
			
		||||
        this.gl = gl;
 | 
			
		||||
    }
 | 
			
		||||
    init(){
 | 
			
		||||
        const gl = this.gl;
 | 
			
		||||
        let program: WebGLProgram;
 | 
			
		||||
        try{
 | 
			
		||||
            const program = createProgramFromSource(gl,vert_src,frag_src);
 | 
			
		||||
            program = createProgramFromSource(gl,vert_src,frag_src);
 | 
			
		||||
            gl.useProgram(program);
 | 
			
		||||
        }
 | 
			
		||||
        catch(e){
 | 
			
		||||
| 
						 | 
				
			
			@ -40,9 +44,6 @@ class Renderer{
 | 
			
		|||
            }
 | 
			
		||||
            else throw e;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    init(){
 | 
			
		||||
        const gl = this.gl;
 | 
			
		||||
        const position = [
 | 
			
		||||
            -0.5,-0.5,
 | 
			
		||||
            0.5,-0.5,
 | 
			
		||||
| 
						 | 
				
			
			@ -60,7 +61,10 @@ class Renderer{
 | 
			
		|||
        const indexBuffer = gl.createBuffer();
 | 
			
		||||
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,indexBuffer);
 | 
			
		||||
        gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(index),gl.STATIC_DRAW);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        let location = gl.getUniformLocation(program, "u_color"); //u_color 변수 위치를 참조
 | 
			
		||||
        gl.uniform4f(location, 0.8, 0.3, 0.8, 1.0); //해당 위치에 0.2, 0.3, 0.8, 1.0 데이터를 전달
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    draw(){
 | 
			
		||||
        const gl = this.gl;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,10 @@
 | 
			
		|||
#version 300 es
 | 
			
		||||
precision highp float;
 | 
			
		||||
layout(location=0) out vec4 outColor;
 | 
			
		||||
//in vec4 gl_FragCoord;
 | 
			
		||||
//in vec2 gl_PointCoord;
 | 
			
		||||
uniform vec4 u_color;
 | 
			
		||||
 | 
			
		||||
void main() {
 | 
			
		||||
  outColor = vec4(0.0,0.0,1.0,1.0);
 | 
			
		||||
  outColor = u_color;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue