gallium: change remaining util functions to use cso sampler views
[mesa/mesa-lb.git] / progs / tests / tex1d.c
blob7d67451c0da5153d6a337c175d9cc663869ab054
2 /* Exercise 1D textures
3 */
5 #include <assert.h>
6 #include <math.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "GL/glew.h"
11 #include "GL/glut.h"
13 static GLuint Window = 0;
14 static GLuint TexObj[2];
15 static GLfloat Angle = 0.0f;
18 static void draw( void )
20 glClear( GL_COLOR_BUFFER_BIT );
22 glColor3f( 1.0, 1.0, 1.0 );
24 /* draw first polygon */
25 glPushMatrix();
26 glTranslatef( -1.0, 0.0, 0.0 );
27 glRotatef( Angle, 0.0, 0.0, 1.0 );
28 glBindTexture( GL_TEXTURE_1D, TexObj[0] );
29 glBegin( GL_POLYGON );
30 glTexCoord1f( 0.0 ); glVertex2f( -1.0, -1.0 );
31 glTexCoord1f( 1.0 ); glVertex2f( 1.0, -1.0 );
32 glTexCoord1f( 1.0 ); glVertex2f( 1.0, 1.0 );
33 glTexCoord1f( 0.0 ); glVertex2f( -1.0, 1.0 );
34 glEnd();
35 glPopMatrix();
37 glutSwapBuffers();
43 static void idle( void )
45 Angle += 2.0;
46 glutPostRedisplay();
52 /* change view Angle, exit upon ESC */
53 static void key(unsigned char k, int x, int y)
55 (void) x;
56 (void) y;
57 switch (k) {
58 case 27:
59 exit(0);
65 /* new window size or exposure */
66 static void reshape( int width, int height )
68 glViewport(0, 0, (GLint)width, (GLint)height);
69 glMatrixMode(GL_PROJECTION);
70 glLoadIdentity();
71 /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/
72 glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 );
73 glMatrixMode(GL_MODELVIEW);
74 glLoadIdentity();
75 glTranslatef( 0.0, 0.0, -8.0 );
79 static void init( void )
81 GLubyte tex[256][3];
82 GLint i;
85 glDisable( GL_DITHER );
87 /* Setup texturing */
88 glEnable( GL_TEXTURE_1D );
89 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
92 /* generate texture object IDs */
93 glGenTextures( 2, TexObj );
95 /* setup first texture object */
96 glBindTexture( GL_TEXTURE_1D, TexObj[0] );
99 for (i = 0; i < 256; i++) {
100 GLfloat f;
102 /* map 0..255 to -PI .. PI */
103 f = ((i / 255.0) - .5) * (3.141592 * 2);
105 f = sin(f);
107 /* map -1..1 to 0..255 */
108 tex[i][0] = (f+1.0)/2.0 * 255.0;
109 tex[i][1] = 0;
110 tex[i][2] = 0;
113 glTexImage1D( GL_TEXTURE_1D, 0, 3, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, tex );
114 glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
115 glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
116 glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT );
117 glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT );
122 int main( int argc, char *argv[] )
124 glutInit(&argc, argv);
125 glutInitWindowPosition(0, 0);
126 glutInitWindowSize(300, 300);
127 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
129 Window = glutCreateWindow("Texture Objects");
130 glewInit();
131 if (!Window) {
132 exit(1);
135 init();
137 glutReshapeFunc( reshape );
138 glutKeyboardFunc( key );
139 /* glutIdleFunc( idle ); */
140 glutDisplayFunc( draw );
141 glutMainLoop();
142 return 0;