diff options
author | Brian <[email protected]> | 2007-02-25 17:24:40 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-02-25 17:24:40 -0700 |
commit | f68067e101d596e59b39f94fafc39483f1c71233 (patch) | |
tree | 191e33194e292544a73e1cebb57da692e4741cb4 | |
parent | 9854a17f292193c9720cf25ab00818ecc210f911 (diff) |
add texture rotation
-rw-r--r-- | progs/glsl/CH11-toyball.vert.txt | 6 | ||||
-rw-r--r-- | progs/glsl/toyball.c | 25 |
2 files changed, 29 insertions, 2 deletions
diff --git a/progs/glsl/CH11-toyball.vert.txt b/progs/glsl/CH11-toyball.vert.txt index 1aa7e9cac23..b7da3ac839e 100644 --- a/progs/glsl/CH11-toyball.vert.txt +++ b/progs/glsl/CH11-toyball.vert.txt @@ -14,7 +14,11 @@ uniform vec4 BallCenter; // ball center in modelling coordinates void main() { - ECposition = gl_ModelViewMatrix * gl_Vertex; +//orig: ECposition = gl_ModelViewMatrix * gl_Vertex; + + ECposition = gl_TextureMatrix[0] * gl_Vertex; + ECposition = gl_ModelViewMatrix * ECposition; + ECballCenter = gl_ModelViewMatrix * BallCenter; gl_Position = ftransform(); } diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c index 2d3462fc61e..cef52c04a6c 100644 --- a/progs/glsl/toyball.c +++ b/progs/glsl/toyball.c @@ -51,11 +51,22 @@ static struct uniform_info Uniforms[] = { }; static GLint win = 0; - +static GLboolean Anim = GL_FALSE; +static GLfloat TexRot = 0.0; static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f; static void +Idle(void) +{ + TexRot += 2.0; + if (TexRot > 360.0) + TexRot -= 360.0; + glutPostRedisplay(); +} + + +static void Redisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -65,6 +76,11 @@ Redisplay(void) glRotatef(yRot, 0.0f, 1.0f, 0.0f); glRotatef(zRot, 0.0f, 0.0f, 1.0f); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glRotatef(TexRot, 0.0f, 1.0f, 0.0f); + glMatrixMode(GL_MODELVIEW); + glutSolidSphere(2.0, 20, 10); glPopMatrix(); @@ -106,6 +122,13 @@ Key(unsigned char key, int x, int y) (void) y; switch(key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; case 'z': zRot += step; break; |