gallium: change remaining util functions to use cso sampler views
[mesa/mesa-lb.git] / progs / trivial / tex-quads.c
blob626e178b873114682c15062145327781a493806d
1 /**
2 * Draw a series of quads, each with a different texture.
3 */
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <GL/glew.h>
9 #include <GL/glut.h>
11 #define NUM_TEX 10
13 static GLint Win = 0;
14 static GLuint Tex[NUM_TEX];
17 static void Init(void)
19 int i;
21 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
22 fflush(stderr);
24 glGenTextures(NUM_TEX, Tex);
26 for (i = 0; i < NUM_TEX; i++) {
27 glBindTexture(GL_TEXTURE_2D, Tex[i]);
29 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
30 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
31 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
32 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
33 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
38 static void Reshape(int width, int height)
40 float ar = (float) width / height;
41 glViewport(0, 0, width, height);
42 glMatrixMode(GL_PROJECTION);
43 glLoadIdentity();
44 glOrtho(-ar, ar, -1.0, 1.0, -1.0, 1.0);
45 glMatrixMode(GL_MODELVIEW);
49 static void Key(unsigned char key, int x, int y)
51 if (key == 27) {
52 glDeleteTextures(NUM_TEX, Tex);
53 glutDestroyWindow(Win);
54 exit(1);
56 glutPostRedisplay();
60 static void Draw(void)
62 GLubyte tex[16][16][4];
63 int t, i, j;
65 for (t = 0; t < NUM_TEX; t++) {
67 for (i = 0; i < 16; i++) {
68 for (j = 0; j < 16; j++) {
69 if (i < t) {
70 /* red row */
71 tex[i][j][0] = 255;
72 tex[i][j][1] = 0;
73 tex[i][j][2] = 0;
74 tex[i][j][3] = 255;
76 else if ((i + j) & 1) {
77 tex[i][j][0] = 128;
78 tex[i][j][1] = 128;
79 tex[i][j][2] = 128;
80 tex[i][j][3] = 255;
82 else {
83 tex[i][j][0] = 255;
84 tex[i][j][1] = 255;
85 tex[i][j][2] = 255;
86 tex[i][j][3] = 255;
91 glBindTexture(GL_TEXTURE_2D, Tex[t]);
92 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
93 GL_RGBA, GL_UNSIGNED_BYTE, tex);
96 glEnable(GL_TEXTURE_2D);
98 glClear(GL_COLOR_BUFFER_BIT);
100 for (i = 0; i < NUM_TEX; i++) {
102 glBindTexture(GL_TEXTURE_2D, Tex[i]);
104 glPushMatrix();
105 glTranslatef(-4.0 + i, 0, 0);
106 glScalef(0.5, 0.5, 1.0);
108 glBegin(GL_QUADS);
109 glTexCoord2f(1,0);
110 glVertex3f( 0.9, -0.9, 0.0);
111 glTexCoord2f(1,1);
112 glVertex3f( 0.9, 0.9, 0.0);
113 glTexCoord2f(0,1);
114 glVertex3f(-0.9, 0.9, 0.0);
115 glTexCoord2f(0,0);
116 glVertex3f(-0.9, -0.9, 0.0);
117 glEnd();
119 glPopMatrix();
123 glutSwapBuffers();
127 int main(int argc, char **argv)
129 glutInit(&argc, argv);
130 glutInitWindowSize(900, 200);
131 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
132 Win = glutCreateWindow(*argv);
133 if (!Win) {
134 exit(1);
136 glewInit();
137 Init();
138 glutReshapeFunc(Reshape);
139 glutKeyboardFunc(Key);
140 glutDisplayFunc(Draw);
141 glutMainLoop();
142 return 0;