JOGL-008 Animation on VertexShader
Post

JOGL-008 Animation on VertexShader

GLSL에 에니메이션을 적용시켜보도록 하겠다. 편의상 VertexShader만을 이용하여 에니메이션을 구현해 보겠다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void init(GLAutoDrawable drawable){
    ...
    ...
    
    // loc는 integer형으로서, 멤버 변수로 선언되어 있어야 한다.
    loc= gl.glGetUniformLocation(glsl.getProgID(), "time");
}

public void display(GLAutoDrawable drawable){
    ...
    ...
    // GLSL 변수에 접근.
    // glUniform1f(loc, t) 함수로 Java의 변수 t와 GLSL의 uniform 변수 time을 연결
    gl.glUniform1f(loc, t);
    t += 1;
}

1
2
3
4
5
6
7
8
9
10
11
// time라는 변수를 uniform float으로 선언하여 Java에서 읽어들일 수 있게 함.
uniform float time;

void main(){
    gl_FrontColor = gl_Color;
    
    vec4 v = vec4(gl_Vertex);
    v.y = cos( 5 * v.z + time*0.1);
    
    gl_Position=    gl_ModelViewProjectionMatrix * v;
}

img