/*
* GLSL noise demo.
- *\r
- * Michal Krol\r
+ *
+ * Michal Krol
* 20 February 2006
- *\r
+ *
* Based on the original demo by:
* Stefan Gustavson (stegu@itn.liu.se) 2004, 2005
- */\r
-\r
-#ifdef WIN32\r
-#include <windows.h>\r
+ */
+
+#ifdef WIN32
+#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
-#include <GL/gl.h>\r
-#include <GL/glut.h>\r
-#include <GL/glext.h>\r
-\r
-#ifdef WIN32\r
-#define GETPROCADDRESS wglGetProcAddress\r
-#else\r
-#define GETPROCADDRESS glutGetProcAddress\r
-#endif\r
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+
+#ifdef WIN32
+#define GETPROCADDRESS(F) wglGetProcAddress(F)
+#else
+#define GETPROCADDRESS(F) glutGetProcAddress(F)
+#endif
static GLhandleARB fragShader;
-static GLhandleARB vertShader;\r
-static GLhandleARB program;\r
-\r
-static GLint uTime;\r
-\r
-static GLfloat u_time = 0.0f;\r
-
-static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;\r
-static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;\r
-static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;\r
-static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;\r
-static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;\r
-static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;\r
-static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;\r
-static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;\r
+static GLhandleARB vertShader;
+static GLhandleARB program;
+
+static GLint uTime;
+
+static GLfloat u_time = 0.0f;
+
+static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
+static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
+static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
+static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
+static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
+static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
+static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL;
static void Redisplay (void)
{
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
-\r
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
glUniform1fARB (uTime, u_time);
glPushMatrix ();
- glutSolidSphere (2.0, 20, 10);\r
+ glutSolidSphere (2.0, 20, 10);
glPopMatrix ();
glutSwapBuffers();
}
static void Idle (void)
-{\r
+{
u_time += 0.1f;
glutPostRedisplay ();
}
static void Key (unsigned char key, int x, int y)
{
(void) x;
- (void) y;\r
+ (void) y;
- switch (key)\r
+ switch (key)
{
case 27:
exit(0);
static void Init (void)
{
- static const char *fragShaderText =\r
+ static const char *fragShaderText =
"uniform float time;\n"
- "void main () {\n"\r
- " gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (\n"\r
- " vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time)))), 1.0);\n"\r
+ "void main () {\n"
+ " gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (\n"
+ " vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time)))), 1.0);\n"
"}\n"
;
static const char *vertShaderText =
- "void main () {\n"\r
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"\r
- " gl_TexCoord[0] = gl_Vertex;\n"\r
- " gl_FrontColor = gl_Color;\n"\r
+ "void main () {\n"
+ " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ " gl_TexCoord[0] = gl_Vertex;\n"
+ " gl_FrontColor = gl_Color;\n"
"}\n"
;
-\r
- if (!glutExtensionSupported ("GL_ARB_fragment_shader"))\r
+
+ if (!glutExtensionSupported ("GL_ARB_fragment_shader"))
{
printf ("Sorry, this demo requires GL_ARB_fragment_shader\n");
exit(1);
- }\r
- if (!glutExtensionSupported ("GL_ARB_shader_objects"))\r
- {\r
- printf ("Sorry, this demo requires GL_ARB_shader_objects\n");\r
- exit(1);\r
- }\r
- if (!glutExtensionSupported ("GL_ARB_shading_language_100"))\r
- {\r
- printf ("Sorry, this demo requires GL_ARB_shading_language_100\n");\r
- exit(1);\r
- }\r
- if (!glutExtensionSupported ("GL_ARB_vertex_shader"))\r
- {\r
- printf ("Sorry, this demo requires GL_ARB_vertex_shader\n");\r
- exit(1);\r
}
+ if (!glutExtensionSupported ("GL_ARB_shader_objects"))
+ {
+ printf ("Sorry, this demo requires GL_ARB_shader_objects\n");
+ exit(1);
+ }
+ if (!glutExtensionSupported ("GL_ARB_shading_language_100"))
+ {
+ printf ("Sorry, this demo requires GL_ARB_shading_language_100\n");
+ exit(1);
+ }
+ if (!glutExtensionSupported ("GL_ARB_vertex_shader"))
+ {
+ printf ("Sorry, this demo requires GL_ARB_vertex_shader\n");
+ exit(1);
+ }
+
+ glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)
+ GETPROCADDRESS("glCreateShaderObjectARB");
+ glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)
+ GETPROCADDRESS("glShaderSourceARB");
+ glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)
+ GETPROCADDRESS("glCompileShaderARB");
+ glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)
+ GETPROCADDRESS("glCreateProgramObjectARB");
+ glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)
+ GETPROCADDRESS("glAttachObjectARB");
+ glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)
+ GETPROCADDRESS ("glLinkProgramARB");
+ glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)
+ GETPROCADDRESS("glUseProgramObjectARB");
- glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress ("glCreateShaderObjectARB");\r
- glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) wglGetProcAddress ("glShaderSourceARB");\r
- glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) wglGetProcAddress ("glCompileShaderARB");\r
- glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glCreateProgramObjectARB");\r
- glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress ("glAttachObjectARB");\r
- glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress ("glLinkProgramARB");\r
- glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glUseProgramObjectARB");\r
- glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GETPROCADDRESS ("glGetUniformLocationARB");\r
- glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GETPROCADDRESS ("glUniform1fARB");\r
-\r
- fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);\r
- glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);\r
+ glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)
+ GETPROCADDRESS("glGetUniformLocationARB");
+ glUniform1fARB = (PFNGLUNIFORM1FARBPROC)
+ GETPROCADDRESS("glUniform1fARB");
+
+ fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
+ glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);
glCompileShaderARB (fragShader);
-\r
- vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);\r
- glShaderSourceARB (vertShader, 1, &vertShaderText, NULL);\r
- glCompileShaderARB (vertShader);\r
-\r
- program = glCreateProgramObjectARB ();\r
- glAttachObjectARB (program, fragShader);\r
- glAttachObjectARB (program, vertShader);\r
- glLinkProgramARB (program);\r
- glUseProgramObjectARB (program);\r
-\r
- uTime = glGetUniformLocationARB (program, "time");\r
-
- glClearColor (0.0f, 0.1f, 0.3f, 1.0f);\r
+
+ vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);
+ glShaderSourceARB (vertShader, 1, &vertShaderText, NULL);
+ glCompileShaderARB (vertShader);
+
+ program = glCreateProgramObjectARB ();
+ glAttachObjectARB (program, fragShader);
+ glAttachObjectARB (program, vertShader);
+ glLinkProgramARB (program);
+ glUseProgramObjectARB (program);
+
+ uTime = glGetUniformLocationARB (program, "time");
+
+ glClearColor (0.0f, 0.1f, 0.3f, 1.0f);
glEnable (GL_CULL_FACE);
glEnable (GL_DEPTH_TEST);
glutMainLoop ();
return 0;
}
-\r
+