shader uniform
This commit is contained in:
parent
66326bca06
commit
9922846acc
12
index.ts
12
index.ts
@ -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,
|
||||||
@ -61,6 +62,9 @@ class Renderer{
|
|||||||
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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user