2 * Test GLSL 1.20 gl_PointCoord fragment program attribute.
17 #include "shaderutil.h"
20 static GLint WinWidth
= 300, WinHeight
= 300;
21 static char *FragProgFile
= NULL
;
22 static char *VertProgFile
= NULL
;
23 static GLuint fragShader
;
24 static GLuint vertShader
;
25 static GLuint program
;
28 static GLenum Filter
= GL_NEAREST
;
34 glClear(GL_COLOR_BUFFER_BIT
);
36 /* draw one point/sprite */
40 glVertex2f(WinWidth
/ 2.0f
, WinHeight
/ 2.0f
);
49 Reshape(int width
, int height
)
51 glViewport(0, 0, width
, height
);
52 glMatrixMode(GL_PROJECTION
);
54 glOrtho(0, width
, 0, height
, -1, 1);
56 glMatrixMode(GL_MODELVIEW
);
67 glDeleteShader_func(fragShader
);
68 glDeleteShader_func(vertShader
);
69 glDeleteProgram_func(program
);
70 glutDestroyWindow(win
);
75 Key(unsigned char key
, int x
, int y
)
95 GLubyte image
[SZ
][SZ
][4];
98 for (i
= 0; i
< SZ
; i
++) {
99 for (j
= 0; j
< SZ
; j
++) {
104 image
[i
][j
][3] = 255;
107 image
[i
][j
][0] = j
* 255 / (SZ
-1);
108 image
[i
][j
][1] = i
* 255 / (SZ
-1);
110 image
[i
][j
][3] = 255;
115 glActiveTexture(GL_TEXTURE0
); /* unit 0 */
116 glBindTexture(GL_TEXTURE_2D
, 42);
117 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, SZ
, SZ
, 0,
118 GL_RGBA
, GL_UNSIGNED_BYTE
, image
);
119 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, Filter
);
120 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, Filter
);
121 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
122 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
130 static const char *fragShaderText
=
132 "uniform sampler2D tex0; \n"
134 " gl_FragColor = texture2D(tex0, gl_PointCoord.xy, 0.0); \n"
136 static const char *vertShaderText
=
138 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
141 if (!ShadersSupported())
146 vertShader
= CompileShaderText(GL_VERTEX_SHADER
, vertShaderText
);
147 fragShader
= CompileShaderText(GL_FRAGMENT_SHADER
, fragShaderText
);
148 program
= LinkShaders(vertShader
, fragShader
);
150 glUseProgram_func(program
);
152 tex0
= glGetUniformLocation_func(program
, "tex0");
153 printf("Uniforms: tex0: %d\n", tex0
);
155 glUniform1i_func(tex0
, 0); /* tex unit 0 */
157 /*assert(glGetError() == 0);*/
159 glClearColor(0.3f
, 0.3f
, 0.3f
, 0.0f
);
161 printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER
));
163 assert(glIsProgram_func(program
));
164 assert(glIsShader_func(fragShader
));
165 assert(glIsShader_func(vertShader
));
169 glEnable(GL_POINT_SPRITE
);
176 ParseOptions(int argc
, char *argv
[])
179 for (i
= 1; i
< argc
; i
++) {
180 if (strcmp(argv
[i
], "-fs") == 0) {
181 FragProgFile
= argv
[i
+1];
183 else if (strcmp(argv
[i
], "-vs") == 0) {
184 VertProgFile
= argv
[i
+1];
191 main(int argc
, char *argv
[])
193 glutInit(&argc
, argv
);
194 glutInitWindowPosition( 0, 0);
195 glutInitWindowSize(WinWidth
, WinHeight
);
196 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
197 win
= glutCreateWindow(argv
[0]);
198 glutReshapeFunc(Reshape
);
199 glutKeyboardFunc(Key
);
200 glutDisplayFunc(Redisplay
);
201 ParseOptions(argc
, argv
);