2 * Test floating point textures.
3 * No actual rendering, yet.
15 #ifndef GL_ARB_texture_float
16 #define GL_ARB_texture_float 1
17 #define GL_TEXTURE_RED_TYPE_ARB 0x9000
18 #define GL_TEXTURE_GREEN_TYPE_ARB 0x9001
19 #define GL_TEXTURE_BLUE_TYPE_ARB 0x9002
20 #define GL_TEXTURE_ALPHA_TYPE_ARB 0x9003
21 #define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x9004
22 #define GL_TEXTURE_INTENSITY_TYPE_ARB 0x9005
23 #define GL_TEXTURE_DEPTH_TYPE_ARB 0x9006
24 #define GL_UNSIGNED_NORMALIZED_ARB 0x9007
25 #define GL_RGBA32F_ARB 0x8814
26 #define GL_RGB32F_ARB 0x8815
27 #define GL_ALPHA32F_ARB 0x8816
28 #define GL_INTENSITY32F_ARB 0x8817
29 #define GL_LUMINANCE32F_ARB 0x8818
30 #define GL_LUMINANCE_ALPHA32F_ARB 0x8819
31 #define GL_RGBA16F_ARB 0x881A
32 #define GL_RGB16F_ARB 0x881B
33 #define GL_ALPHA16F_ARB 0x881C
34 #define GL_INTENSITY16F_ARB 0x881D
35 #define GL_LUMINANCE16F_ARB 0x881E
36 #define GL_LUMINANCE_ALPHA16F_ARB 0x881F
41 CheckError( int line
)
43 GLenum error
= glGetError();
45 char *err
= (char *) gluErrorString( error
);
46 fprintf( stderr
, "GL Error: %s at line %d\n", err
, line
);
56 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
69 Reshape(int width
, int height
)
71 glViewport(0, 0, width
, height
);
72 glMatrixMode(GL_PROJECTION
);
74 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
75 glMatrixMode(GL_MODELVIEW
);
77 glTranslatef(0.0, 0.0, -15.0);
82 Key(unsigned char key
, int x
, int y
)
99 GLfloat tex
[16][16][4];
100 GLfloat tex2
[16][16][4];
103 if (!glutExtensionSupported("GL_MESAX_texture_float")) {
104 printf("Sorry, this test requires GL_MESAX_texture_float\n");
108 for (i
= 0; i
< 16; i
++) {
109 for (j
= 0; j
< 16; j
++) {
110 GLfloat s
= i
/ 15.0;
112 tex
[i
][j
][1] = 2.0 * s
;
113 tex
[i
][j
][2] = -3.0 * s
;
114 tex
[i
][j
][3] = 4.0 * s
;
118 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA32F_ARB
, 16, 16, 0, GL_RGBA
,
120 CheckError(__LINE__
);
122 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0, GL_TEXTURE_RED_TYPE_ARB
, &t
);
123 assert(t
== GL_FLOAT
);
124 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0, GL_TEXTURE_GREEN_TYPE_ARB
, &t
);
125 assert(t
== GL_FLOAT
);
126 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0, GL_TEXTURE_BLUE_TYPE_ARB
, &t
);
127 assert(t
== GL_FLOAT
);
128 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0, GL_TEXTURE_ALPHA_TYPE_ARB
, &t
);
129 assert(t
== GL_FLOAT
);
131 CheckError(__LINE__
);
133 /* read back the texture and make sure values are correct */
134 glGetTexImage(GL_TEXTURE_2D
, 0, GL_RGBA
, GL_FLOAT
, tex2
);
135 CheckError(__LINE__
);
136 for (i
= 0; i
< 16; i
++) {
137 for (j
= 0; j
< 16; j
++) {
138 if (tex
[i
][j
][0] != tex2
[i
][j
][0] ||
139 tex
[i
][j
][1] != tex2
[i
][j
][1] ||
140 tex
[i
][j
][2] != tex2
[i
][j
][2] ||
141 tex
[i
][j
][3] != tex2
[i
][j
][3]) {
142 printf("tex[%d][%d] %g %g %g %g != tex2[%d][%d] %g %g %g %g\n",
144 tex
[i
][j
][0], tex
[i
][j
][1], tex
[i
][j
][2], tex
[i
][j
][3],
146 tex2
[i
][j
][0], tex2
[i
][j
][1], tex2
[i
][j
][2], tex2
[i
][j
][3]);
156 main(int argc
, char *argv
[])
158 glutInit(&argc
, argv
);
159 glutInitWindowPosition(0, 0);
160 glutInitWindowSize(400, 400);
161 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
162 glutCreateWindow(argv
[0]);
163 glutReshapeFunc(Reshape
);
164 glutKeyboardFunc(Key
);
165 glutDisplayFunc(Draw
);