gallium: change remaining util functions to use cso sampler views
[mesa/mesa-lb.git] / progs / trivial / vp-tri-tex.c
blobbd2b5e59f9d7aa91606aff1eb40ae2cccca6edb3
1 /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
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 <GL/glut.h>
11 static void Init( void )
13 GLint errno;
14 GLuint prognum;
16 static const char *prog1 =
17 "!!ARBvp1.0\n"
18 "MOV result.texcoord[0], vertex.texcoord[0];\n"
19 "MOV result.position, vertex.position;\n"
20 "END\n";
23 glGenProgramsARB(1, &prognum);
25 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
26 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
27 strlen(prog1), (const GLubyte *) prog1);
29 assert(glIsProgramARB(prognum));
30 errno = glGetError();
31 printf("glGetError = %d\n", errno);
32 if (errno != GL_NO_ERROR)
34 GLint errorpos;
36 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
37 printf("errorpos: %d\n", errorpos);
38 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
41 #define SIZE 32
43 GLubyte tex2d[SIZE][SIZE][3];
44 GLint s, t;
46 for (s = 0; s < SIZE; s++) {
47 for (t = 0; t < SIZE; t++) {
48 #if 0
49 tex2d[t][s][0] = (s < SIZE/2) ? 0 : 255;
50 tex2d[t][s][1] = (t < SIZE/2) ? 0 : 255;
51 tex2d[t][s][2] = 0;
52 #else
53 tex2d[t][s][0] = s*255/(SIZE-1);
54 tex2d[t][s][1] = t*255/(SIZE-1);
55 tex2d[t][s][2] = 0;
56 #endif
60 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
62 glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0,
63 GL_RGB, GL_UNSIGNED_BYTE, tex2d);
65 glEnable(GL_TEXTURE_2D);
66 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
67 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
68 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
69 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
71 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
76 static void Display( void )
78 glClearColor(0.3, 0.3, 0.3, 1);
79 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
81 glEnable(GL_VERTEX_PROGRAM_NV);
83 glBegin(GL_TRIANGLES);
84 glTexCoord2f(1,-1);
85 glVertex3f( 0.9, -0.9, -0.0);
86 glTexCoord2f(1,1);
87 glVertex3f( 0.9, 0.9, -0.0);
88 glTexCoord2f(-1,0);
89 glVertex3f(-0.9, 0.0, -0.0);
90 glEnd();
93 glFlush();
97 static void Reshape( int width, int height )
99 glViewport( 0, 0, width, height );
100 glMatrixMode( GL_PROJECTION );
101 glLoadIdentity();
102 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
103 glMatrixMode( GL_MODELVIEW );
104 glLoadIdentity();
105 /*glTranslatef( 0.0, 0.0, -15.0 );*/
109 static void Key( unsigned char key, int x, int y )
111 (void) x;
112 (void) y;
113 switch (key) {
114 case 27:
115 exit(0);
116 break;
118 glutPostRedisplay();
124 int main( int argc, char *argv[] )
126 glutInit( &argc, argv );
127 glutInitWindowPosition( 0, 0 );
128 glutInitWindowSize( 250, 250 );
129 glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
130 glutCreateWindow(argv[0]);
131 glewInit();
132 glutReshapeFunc( Reshape );
133 glutKeyboardFunc( Key );
134 glutDisplayFunc( Display );
135 Init();
136 glutMainLoop();
137 return 0;