2 * Test noise() functions.
15 #include "shaderutil.h"
18 static const char *VertShaderText
=
20 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
21 " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
24 static const char *FragShaderText
=
25 "uniform vec4 Scale, Bias;\n"
26 "uniform float Slice;\n"
29 " vec4 scale = vec4(5.0);\n"
31 " p.xy = gl_TexCoord[0].xy;\n"
33 " vec4 n = noise4(p * scale);\n"
34 " gl_FragColor = n * Scale + Bias;\n"
38 static struct uniform_info Uniforms
[] = {
39 { "Scale", 4, GL_FLOAT
, { 0.5, 0.4, 0.0, 0}, -1 },
40 { "Bias", 4, GL_FLOAT
, { 0.5, 0.3, 0.0, 0}, -1 },
41 { "Slice", 1, GL_FLOAT
, { 0.5, 0, 0, 0}, -1 },
45 /* program/shader objects */
46 static GLuint fragShader
;
47 static GLuint vertShader
;
48 static GLuint program
;
51 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
, zRot
= 0.0f
;
52 static GLfloat Slice
= 0.0;
53 static GLboolean Anim
= GL_FALSE
;
67 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
69 glUniform1fv_func(Uniforms
[2].location
, 1, &Slice
);
72 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
73 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
74 glRotatef(zRot
, 0.0f
, 0.0f
, 1.0f
);
77 glTexCoord2f(0, 0); glVertex2f(-2, -2);
78 glTexCoord2f(1, 0); glVertex2f( 2, -2);
79 glTexCoord2f(1, 1); glVertex2f( 2, 2);
80 glTexCoord2f(0, 1); glVertex2f(-2, 2);
90 Reshape(int width
, int height
)
92 glViewport(0, 0, width
, height
);
93 glMatrixMode(GL_PROJECTION
);
95 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
96 glMatrixMode(GL_MODELVIEW
);
98 glTranslatef(0.0f
, 0.0f
, -15.0f
);
105 glDeleteShader_func(fragShader
);
106 glDeleteShader_func(vertShader
);
107 glDeleteProgram_func(program
);
108 glutDestroyWindow(win
);
113 Key(unsigned char key
, int x
, int y
)
115 const GLfloat step
= 0.01;
122 glutIdleFunc(Anim
? Idle
: NULL
);
145 SpecialKey(int key
, int x
, int y
)
147 const GLfloat step
= 3.0f
;
174 if (!ShadersSupported())
179 vertShader
= CompileShaderText(GL_VERTEX_SHADER
, VertShaderText
);
180 fragShader
= CompileShaderText(GL_FRAGMENT_SHADER
, FragShaderText
);
181 program
= LinkShaders(vertShader
, fragShader
);
183 glUseProgram_func(program
);
185 InitUniforms(program
, Uniforms
);
187 assert(glGetError() == 0);
189 glClearColor(0.4f
, 0.4f
, 0.8f
, 0.0f
);
191 printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER
));
193 assert(glIsProgram_func(program
));
194 assert(glIsShader_func(fragShader
));
195 assert(glIsShader_func(vertShader
));
202 main(int argc
, char *argv
[])
204 glutInit(&argc
, argv
);
205 glutInitWindowPosition( 0, 0);
206 glutInitWindowSize(400, 400);
207 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
208 win
= glutCreateWindow(argv
[0]);
209 glutReshapeFunc(Reshape
);
210 glutKeyboardFunc(Key
);
211 glutSpecialFunc(SpecialKey
);
212 glutDisplayFunc(Redisplay
);