demos: add missing binaries to .gitignore
[mesa-demos.git] / src / tests / arbfptexture.c
blob8f68551f6225722e65ffe4b6278d7dcc3a6c4abd
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 #include <GL/glew.h>
9 #include "glut_wrap.h"
11 #include "readtex.c"
14 #define TEXTURE_FILE DEMOS_DATA_DIR "girl.rgb"
16 static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
19 static void Display( void )
21 glClear( GL_COLOR_BUFFER_BIT );
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);
28 glBegin(GL_POLYGON);
29 #define Q 2
30 glColor4f(1.0, 1.0, 1.0, 1); glTexCoord4f(0, 0, 0, Q); glVertex2f(-1, -1);
31 glColor4f(0.2, 0.2, 1.0, 1); glTexCoord4f(1, 0, 0, Q); glVertex2f( 1, -1);
32 glColor4f(0.2, 1.0, 0.2, 1); glTexCoord4f(1, 1, 0, Q); glVertex2f( 1, 1);
33 glColor4f(1.0, 0.2, 0.2, 1); glTexCoord4f(0, 1, 0, Q); 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 "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
97 "MUL result.color, R0, fragment.color; \n"
98 "END"
100 GLuint modulateProg;
101 GLuint Texture;
103 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
104 printf("Error: GL_ARB_fragment_program not supported!\n");
105 exit(1);
107 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
109 /* Setup the fragment program */
110 glGenProgramsARB(1, &modulateProg);
111 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
112 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
113 strlen(modulate2D), (const GLubyte *)modulate2D);
115 printf("glGetError = 0x%x\n", (int) glGetError());
116 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
117 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
118 assert(glIsProgramARB(modulateProg));
120 glEnable(GL_FRAGMENT_PROGRAM_ARB);
122 /* Load texture */
123 glGenTextures(1, &Texture);
124 glBindTexture(GL_TEXTURE_2D, Texture);
125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
127 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
128 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
129 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
130 exit(1);
132 /* XXX this enable shouldn't really be needed!!! */
133 glEnable(GL_TEXTURE_2D);
135 glClearColor(.3, .3, .3, 0);
139 int main( int argc, char *argv[] )
141 glutInit( &argc, argv );
142 glutInitWindowPosition( 0, 0 );
143 glutInitWindowSize( 250, 250 );
144 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
145 glutCreateWindow(argv[0]);
146 glewInit();
147 glutReshapeFunc( Reshape );
148 glutKeyboardFunc( Key );
149 glutSpecialFunc( SpecialKey );
150 glutDisplayFunc( Display );
151 Init();
152 glutMainLoop();
153 return 0;