< GLSL Animation >
GLSL에 에니메이션을 적용시켜보도록 하겠다.
그러기 위해서는 GLSL에 있는 변수에 변화를 주어야 하고, 그 변수를 실제 적용 시켜야한다.
fs는 그대로 두고, vs에만 변화를 주어보겠다.
//VertexShader.vs 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; }
// time라는 변수를 uniform float 으로 선언하여, OpenGL App. 에서 읽어들일 수 있게 하였다.
public void init(GLAutoDrawable drawable){
...
...
loc= gl.glGetUniformLocation(glsl.getProgID(), "time");
}
// 우선 loc는 integer형으로서, 멤버 변수로 선언되어 있어야 한다.
public void display(GLAutoDrawable drawable){
...
...
gl.glUniform1f(loc, t); //GLSL 변수에 접근.
t+=1;
}
// glUniform1f(loc, t) 함수로 OpenGL App.의 변수 t와 GLSL의 uniform 변수 time을 연결
'Computer > JOGL' 카테고리의 다른 글
10. GLSL -- Texture (0) | 2007.08.03 |
---|---|
9. GLSL -- 툰 셰이딩 (0) | 2007.08.03 |
7. GLSL -- vs & fs (0) | 2007.08.03 |
6. GLSL -- HelloWorld (0) | 2007.08.03 |
5. Text (0) | 2007.07.31 |