Merge branch 'gallium-0.1' into gallium-tex-surfaces
[mesa.git] / progs / tests / fptexture.c
1 /* GL_NV_fragment_program texture test */
2
3 #include <assert.h>
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #define GL_GLEXT_PROTOTYPES
9 #include <GL/glut.h>
10
11 #include "../util/readtex.c"
12
13
14 #define TEXTURE_FILE "../images/girl.rgb"
15
16 static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
17
18
19 static void Display( void )
20 {
21 glClear( GL_COLOR_BUFFER_BIT );
22
23 glPushMatrix();
24 glRotatef(Xrot, 1.0, 0.0, 0.0);
25 glRotatef(Yrot, 0.0, 1.0, 0.0);
26 glRotatef(Zrot, 0.0, 0.0, 1.0);
27
28 glBegin(GL_POLYGON);
29 glColor4f(1.0, 1.0, 1.0, 1); glTexCoord2f(0, 0); glVertex2f(-1, -1);
30 glColor4f(0.2, 0.2, 1.0, 1); glTexCoord2f(1, 0); glVertex2f( 1, -1);
31 glColor4f(0.2, 1.0, 0.2, 1); glTexCoord2f(1, 1); glVertex2f( 1, 1);
32 glColor4f(1.0, 0.2, 0.2, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1);
33 glEnd();
34
35 glPopMatrix();
36
37 glutSwapBuffers();
38 }
39
40
41 static void Reshape( int width, int height )
42 {
43 glViewport( 0, 0, width, height );
44 glMatrixMode( GL_PROJECTION );
45 glLoadIdentity();
46 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
47 glMatrixMode( GL_MODELVIEW );
48 glLoadIdentity();
49 glTranslatef( 0.0, 0.0, -8.0 );
50 }
51
52
53 static void SpecialKey( int key, int x, int y )
54 {
55 float step = 3.0;
56 (void) x;
57 (void) y;
58
59 switch (key) {
60 case GLUT_KEY_UP:
61 Xrot += step;
62 break;
63 case GLUT_KEY_DOWN:
64 Xrot -= step;
65 break;
66 case GLUT_KEY_LEFT:
67 Yrot += step;
68 break;
69 case GLUT_KEY_RIGHT:
70 Yrot -= step;
71 break;
72 }
73 glutPostRedisplay();
74 }
75
76
77 static void Key( unsigned char key, int x, int y )
78 {
79 (void) x;
80 (void) y;
81 switch (key) {
82 case 27:
83 exit(0);
84 break;
85 }
86 glutPostRedisplay();
87 }
88
89
90 static void Init( void )
91 {
92 static const char *modulate2D =
93 "!!FP1.0\n"
94 "TEX R0, f[TEX0], TEX0, 2D; \n"
95 "MUL o[COLR], R0, f[COL0]; \n"
96 "END"
97 ;
98 GLuint modulateProg;
99 GLuint Texture;
100
101 if (!glutExtensionSupported("GL_NV_fragment_program")) {
102 printf("Error: GL_NV_fragment_program not supported!\n");
103 exit(1);
104 }
105 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
106
107 /* Setup the fragment program */
108 glGenProgramsNV(1, &modulateProg);
109 glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, modulateProg,
110 strlen(modulate2D),
111 (const GLubyte *) modulate2D);
112 printf("glGetError = 0x%x\n", (int) glGetError());
113 printf("glError(GL_PROGRAM_ERROR_STRING_NV) = %s\n",
114 (char *) glGetString(GL_PROGRAM_ERROR_STRING_NV));
115 assert(glIsProgramNV(modulateProg));
116
117 glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, modulateProg);
118 glEnable(GL_FRAGMENT_PROGRAM_NV);
119
120 /* Load texture */
121 glGenTextures(1, &Texture);
122 glBindTexture(GL_TEXTURE_2D, Texture);
123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
125 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
126 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
127 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
128 exit(1);
129 }
130 /* XXX this enable shouldn't really be needed!!! */
131 glEnable(GL_TEXTURE_2D);
132
133 glClearColor(.3, .3, .3, 0);
134 }
135
136
137 int main( int argc, char *argv[] )
138 {
139 glutInit( &argc, argv );
140 glutInitWindowPosition( 0, 0 );
141 glutInitWindowSize( 250, 250 );
142 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
143 glutCreateWindow(argv[0]);
144 glutReshapeFunc( Reshape );
145 glutKeyboardFunc( Key );
146 glutSpecialFunc( SpecialKey );
147 glutDisplayFunc( Display );
148 Init();
149 glutMainLoop();
150 return 0;
151 }