2 * Draw a series of quads, each with a different texture.
14 static GLuint Tex
[NUM_TEX
];
17 static void Init(void)
21 fprintf(stderr
, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
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
);
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
)
52 glDeleteTextures(NUM_TEX
, Tex
);
53 glutDestroyWindow(Win
);
60 static void Draw(void)
62 GLubyte tex
[16][16][4];
65 for (t
= 0; t
< NUM_TEX
; t
++) {
67 for (i
= 0; i
< 16; i
++) {
68 for (j
= 0; j
< 16; j
++) {
76 else if ((i
+ j
) & 1) {
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
]);
105 glTranslatef(-4.0 + i
, 0, 0);
106 glScalef(0.5, 0.5, 1.0);
110 glVertex3f( 0.9, -0.9, 0.0);
112 glVertex3f( 0.9, 0.9, 0.0);
114 glVertex3f(-0.9, 0.9, 0.0);
116 glVertex3f(-0.9, -0.9, 0.0);
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
);
138 glutReshapeFunc(Reshape
);
139 glutKeyboardFunc(Key
);
140 glutDisplayFunc(Draw
);