shader uniform

This commit is contained in:
monoid 2021-09-28 15:27:00 +09:00
parent 66326bca06
commit 9922846acc
2 changed files with 13 additions and 6 deletions

View File

@ -27,8 +27,12 @@ class Renderer{
gl : WebGL2RenderingContextStrict; gl : WebGL2RenderingContextStrict;
constructor(gl: WebGL2RenderingContextStrict){ constructor(gl: WebGL2RenderingContextStrict){
this.gl = gl; this.gl = gl;
}
init(){
const gl = this.gl;
let program: WebGLProgram;
try{ try{
const program = createProgramFromSource(gl,vert_src,frag_src); program = createProgramFromSource(gl,vert_src,frag_src);
gl.useProgram(program); gl.useProgram(program);
} }
catch(e){ catch(e){
@ -40,9 +44,6 @@ class Renderer{
} }
else throw e; else throw e;
} }
}
init(){
const gl = this.gl;
const position = [ const position = [
-0.5,-0.5, -0.5,-0.5,
0.5,-0.5, 0.5,-0.5,
@ -60,7 +61,10 @@ class Renderer{
const indexBuffer = gl.createBuffer(); const indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,indexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(index),gl.STATIC_DRAW); 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(){ draw(){
const gl = this.gl; const gl = this.gl;

View File

@ -1,7 +1,10 @@
#version 300 es #version 300 es
precision highp float; precision highp float;
layout(location=0) out vec4 outColor; layout(location=0) out vec4 outColor;
//in vec4 gl_FragCoord;
//in vec2 gl_PointCoord;
uniform vec4 u_color;
void main() { void main() {
outColor = vec4(0.0,0.0,1.0,1.0); outColor = u_color;
} }