Moving NV_fragment_program tests to ARB_fragment_program
[mesa.git] / progs / tests / arbfptexture.c
1 /* GL_ARB_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 "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 "!!ARBfp1.0\n"
94 "TEMP R0;\n"
95 "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
96 "MUL result.color, R0, fragment.color; \n"
97 "END"
98 ;
99 GLuint modulateProg;
100 GLuint Texture;
101
102 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
103 printf("Error: GL_ARB_fragment_program not supported!\n");
104 exit(1);
105 }
106 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
107
108 /* Setup the fragment program */
109 glGenProgramsARB(1, &modulateProg);
110 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
111 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
112 strlen(modulate2D), (const GLubyte *)modulate2D);
113
114 printf("glGetError = 0x%x\n", (int) glGetError());
115 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
116 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
117 assert(glIsProgramARB(modulateProg));
118
119 glEnable(GL_FRAGMENT_PROGRAM_ARB);
120
121 /* Load texture */
122 glGenTextures(1, &Texture);
123 glBindTexture(GL_TEXTURE_2D, Texture);
124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
126 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
127 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
128 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
129 exit(1);
130 }
131 /* XXX this enable shouldn't really be needed!!! */
132 glEnable(GL_TEXTURE_2D);
133
134 glClearColor(.3, .3, .3, 0);
135 }
136
137
138 int main( int argc, char *argv[] )
139 {
140 glutInit( &argc, argv );
141 glutInitWindowPosition( 0, 0 );
142 glutInitWindowSize( 250, 250 );
143 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
144 glutCreateWindow(argv[0]);
145 glutReshapeFunc( Reshape );
146 glutKeyboardFunc( Key );
147 glutSpecialFunc( SpecialKey );
148 glutDisplayFunc( Display );
149 Init();
150 glutMainLoop();
151 return 0;
152 }