Convert libGL and DRI drivers to require libdrm.
[mesa-demos.git] / src / tests / arbfptrig.c
blob26b68c6b4128ac781c9cc7342858f6fb551e1526
1 /* GL_ARB_fragment_program texture test */
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>
11 #include "readtex.c"
14 #define TEXTURE_FILE "../images/girl.rgb"
16 static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
18 #define PI 3.141592
20 static void Display( void )
22 glClear( GL_COLOR_BUFFER_BIT );
24 glPushMatrix();
25 glRotatef(Xrot, 1.0, 0.0, 0.0);
26 glRotatef(Yrot, 0.0, 1.0, 0.0);
27 glRotatef(Zrot, 0.0, 0.0, 1.0);
29 glBegin(GL_POLYGON);
30 glTexCoord2f(-PI, 0); glVertex2f(-1, -1);
31 glTexCoord2f(PI, 0); glVertex2f( 1, -1);
32 glTexCoord2f(PI, 1); glVertex2f( 1, 1);
33 glTexCoord2f(-PI, 1); glVertex2f(-1, 1);
34 glEnd();
36 glPopMatrix();
38 glutSwapBuffers();
42 static void Reshape( int width, int height )
44 glViewport( 0, 0, width, height );
45 glMatrixMode( GL_PROJECTION );
46 glLoadIdentity();
47 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
48 glMatrixMode( GL_MODELVIEW );
49 glLoadIdentity();
50 glTranslatef( 0.0, 0.0, -8.0 );
54 static void SpecialKey( int key, int x, int y )
56 float step = 3.0;
57 (void) x;
58 (void) y;
60 switch (key) {
61 case GLUT_KEY_UP:
62 Xrot += step;
63 break;
64 case GLUT_KEY_DOWN:
65 Xrot -= step;
66 break;
67 case GLUT_KEY_LEFT:
68 Yrot += step;
69 break;
70 case GLUT_KEY_RIGHT:
71 Yrot -= step;
72 break;
74 glutPostRedisplay();
78 static void Key( unsigned char key, int x, int y )
80 (void) x;
81 (void) y;
82 switch (key) {
83 case 27:
84 exit(0);
85 break;
87 glutPostRedisplay();
91 static void Init( void )
93 static const char *modulate2D =
94 "!!ARBfp1.0\n"
95 "TEMP R0;\n"
96 "MOV R0, {0,0,0,1};\n"
97 "SCS R0, fragment.texcoord[0].x; \n"
98 "ADD R0, R0, {1.0}.x;\n"
99 "MUL R0, R0, {0.5}.x;\n"
100 "MOV result.color, R0; \n"
101 "END"
103 GLuint modulateProg;
104 GLuint Texture;
106 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
107 printf("Error: GL_ARB_fragment_program not supported!\n");
108 exit(1);
110 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
112 /* Setup the fragment program */
113 glGenProgramsARB(1, &modulateProg);
114 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
115 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
116 strlen(modulate2D), (const GLubyte *)modulate2D);
118 printf("glGetError = 0x%x\n", (int) glGetError());
119 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
120 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
121 assert(glIsProgramARB(modulateProg));
123 glEnable(GL_FRAGMENT_PROGRAM_ARB);
125 /* Load texture */
126 glGenTextures(1, &Texture);
127 glBindTexture(GL_TEXTURE_2D, Texture);
128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
130 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
131 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
132 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
133 exit(1);
135 /* XXX this enable shouldn't really be needed!!! */
136 glEnable(GL_TEXTURE_2D);
138 glClearColor(.3, .3, .3, 0);
142 int main( int argc, char *argv[] )
144 glutInit( &argc, argv );
145 glutInitWindowPosition( 0, 0 );
146 glutInitWindowSize( 250, 250 );
147 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
148 glutCreateWindow(argv[0]);
149 glutReshapeFunc( Reshape );
150 glutKeyboardFunc( Key );
151 glutSpecialFunc( SpecialKey );
152 glutDisplayFunc( Display );
153 Init();
154 glutMainLoop();
155 return 0;