7 * Based on the original demo by:
8 * Stefan Gustavson (stegu@itn.liu.se) 2004, 2005
13 #include <glad/glad.h>
14 #include "glut_wrap.h"
17 static GLhandleARB fragShader
;
18 static GLhandleARB vertShader
;
19 static GLhandleARB program
;
24 static GLint frames
= 0;
26 static GLfloat u_time
= 0.0f
;
33 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
35 glUniform1fARB(uTime
, 0.5f
* u_time
);
38 glutSolidSphere(2.0, 20, 10);
44 t
= glutGet(GLUT_ELAPSED_TIME
);
46 GLfloat seconds
= (GLfloat
) (t
- t0
) / 1000.0f
;
47 GLfloat fps
= frames
/ seconds
;
48 printf("%d frames in %6.3f seconds = %6.3f FPS\n", frames
, seconds
,
64 Reshape(int width
, int height
)
66 glViewport(0, 0, width
, height
);
67 glMatrixMode(GL_PROJECTION
);
69 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
70 glMatrixMode(GL_MODELVIEW
);
72 glTranslatef(0.0f
, 0.0f
, -15.0f
);
76 Key(unsigned char key
, int x
, int y
)
92 static const char *fragShaderText
=
93 "uniform float time;\n"
94 "varying vec3 position;\n"
96 " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n"
98 static const char *vertShaderText
=
99 "varying vec3 position;\n"
101 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
102 " position = 4.0 * gl_Vertex.xyz;\n" "}\n";
104 if (!glutExtensionSupported("GL_ARB_fragment_shader")) {
105 printf("Sorry, this demo requires GL_ARB_fragment_shader\n");
108 if (!glutExtensionSupported("GL_ARB_shader_objects")) {
109 printf("Sorry, this demo requires GL_ARB_shader_objects\n");
112 if (!glutExtensionSupported("GL_ARB_shading_language_100")) {
113 printf("Sorry, this demo requires GL_ARB_shading_language_100\n");
116 if (!glutExtensionSupported("GL_ARB_vertex_shader")) {
117 printf("Sorry, this demo requires GL_ARB_vertex_shader\n");
121 fragShader
= glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB
);
122 glShaderSourceARB(fragShader
, 1, &fragShaderText
, NULL
);
123 glCompileShaderARB(fragShader
);
125 vertShader
= glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB
);
126 glShaderSourceARB(vertShader
, 1, &vertShaderText
, NULL
);
127 glCompileShaderARB(vertShader
);
129 program
= glCreateProgramObjectARB();
130 glAttachObjectARB(program
, fragShader
);
131 glAttachObjectARB(program
, vertShader
);
132 glLinkProgramARB(program
);
133 glUseProgramObjectARB(program
);
135 uTime
= glGetUniformLocationARB(program
, "time");
137 glClearColor(0.0f
, 0.1f
, 0.3f
, 1.0f
);
138 glEnable(GL_CULL_FACE
);
139 glEnable(GL_DEPTH_TEST
);
141 printf("GL_RENDERER = %s\n", (const char *) glGetString(GL_RENDERER
));
145 main(int argc
, char *argv
[])
147 glutInit(&argc
, argv
);
148 glutInitWindowSize(200, 200);
149 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
150 glutCreateWindow(argv
[0]);
151 glutReshapeFunc(Reshape
);
152 glutKeyboardFunc(Key
);
153 glutDisplayFunc(Redisplay
);