2 * Test noise() functions.
12 #include "glut_wrap.h"
13 #include "shaderutil.h"
16 static const char *VertShaderText
=
18 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
19 " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
22 static const char *FragShaderText
=
23 "uniform vec4 Scale, Bias;\n"
24 "uniform float Slice;\n"
27 " vec4 scale = vec4(5.0);\n"
29 " p.xy = gl_TexCoord[0].xy;\n"
32 " vec4 n = noise4(p * scale);\n"
33 " gl_FragColor = n * Scale + Bias;\n"
37 static struct uniform_info Uniforms
[] = {
38 { "Scale", 1, GL_FLOAT_VEC4
, { 0.5, 0.4, 0.0, 0}, -1 },
39 { "Bias", 1, GL_FLOAT_VEC4
, { 0.5, 0.3, 0.0, 0}, -1 },
40 { "Slice", 1, GL_FLOAT
, { 0.5, 0, 0, 0}, -1 },
44 /* program/shader objects */
45 static GLuint fragShader
;
46 static GLuint vertShader
;
47 static GLuint program
;
50 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
, zRot
= 0.0f
;
51 static GLfloat Slice
= 0.0;
52 static GLboolean Anim
= GL_FALSE
;
66 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
68 glUniform1fv(Uniforms
[2].location
, 1, &Slice
);
71 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
72 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
73 glRotatef(zRot
, 0.0f
, 0.0f
, 1.0f
);
76 glTexCoord2f(0, 0); glVertex2f(-2, -2);
77 glTexCoord2f(1, 0); glVertex2f( 2, -2);
78 glTexCoord2f(1, 1); glVertex2f( 2, 2);
79 glTexCoord2f(0, 1); glVertex2f(-2, 2);
89 Reshape(int width
, int height
)
91 glViewport(0, 0, width
, height
);
92 glMatrixMode(GL_PROJECTION
);
94 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
95 glMatrixMode(GL_MODELVIEW
);
97 glTranslatef(0.0f
, 0.0f
, -15.0f
);
104 glDeleteShader(fragShader
);
105 glDeleteShader(vertShader
);
106 glDeleteProgram(program
);
107 glutDestroyWindow(win
);
112 Key(unsigned char key
, int x
, int y
)
114 const GLfloat step
= 0.01;
121 glutIdleFunc(Anim
? Idle
: NULL
);
145 SpecialKey(int key
, int x
, int y
)
147 const GLfloat step
= 3.0f
;
174 if (!ShadersSupported())
177 vertShader
= CompileShaderText(GL_VERTEX_SHADER
, VertShaderText
);
178 fragShader
= CompileShaderText(GL_FRAGMENT_SHADER
, FragShaderText
);
179 program
= LinkShaders(vertShader
, fragShader
);
181 glUseProgram(program
);
183 SetUniformValues(program
, Uniforms
);
184 PrintUniforms(Uniforms
);
186 assert(glGetError() == 0);
188 glClearColor(0.4f
, 0.4f
, 0.8f
, 0.0f
);
190 printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER
));
192 assert(glIsProgram(program
));
193 assert(glIsShader(fragShader
));
194 assert(glIsShader(vertShader
));
201 main(int argc
, char *argv
[])
203 glutInit(&argc
, argv
);
204 glutInitWindowSize(400, 400);
205 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
206 win
= glutCreateWindow(argv
[0]);
208 glutReshapeFunc(Reshape
);
209 glutKeyboardFunc(Key
);
210 glutSpecialFunc(SpecialKey
);
211 glutDisplayFunc(Redisplay
);