2 /* Exercise 1D textures
12 static GLuint Window
= 0;
13 static GLuint TexObj
[2];
14 static GLfloat Angle
= 0.0f
;
17 static void draw( void )
19 glClear( GL_COLOR_BUFFER_BIT
);
21 glColor3f( 1.0, 1.0, 1.0 );
23 /* draw first polygon */
25 glTranslatef( -1.0, 0.0, 0.0 );
26 glRotatef( Angle
, 0.0, 0.0, 1.0 );
27 glBindTexture( GL_TEXTURE_1D
, TexObj
[0] );
28 glBegin( GL_POLYGON
);
29 glTexCoord1f( 0.0 ); glVertex2f( -1.0, -1.0 );
30 glTexCoord1f( 1.0 ); glVertex2f( 1.0, -1.0 );
31 glTexCoord1f( 1.0 ); glVertex2f( 1.0, 1.0 );
32 glTexCoord1f( 0.0 ); glVertex2f( -1.0, 1.0 );
41 static void idle( void )
49 /* change view Angle, exit upon ESC */
50 static void key(unsigned char k
, int x
, int y
)
62 /* new window size or exposure */
63 static void reshape( int width
, int height
)
65 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
66 glMatrixMode(GL_PROJECTION
);
68 /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/
69 glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 );
70 glMatrixMode(GL_MODELVIEW
);
72 glTranslatef( 0.0, 0.0, -8.0 );
76 static void init( void )
82 glDisable( GL_DITHER
);
85 glEnable( GL_TEXTURE_1D
);
86 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
89 /* generate texture object IDs */
90 glGenTextures( 2, TexObj
);
92 /* setup first texture object */
93 glBindTexture( GL_TEXTURE_1D
, TexObj
[0] );
96 for (i
= 0; i
< 256; i
++) {
99 /* map 0..255 to -PI .. PI */
100 f
= ((i
/ 255.0) - .5) * (3.141592 * 2);
104 /* map -1..1 to 0..255 */
105 tex
[i
][0] = (f
+1.0)/2.0 * 255.0;
110 glTexImage1D( GL_TEXTURE_1D
, 0, 3, 256, 0, GL_RGB
, GL_UNSIGNED_BYTE
, tex
);
111 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
112 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
113 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
114 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
119 int main( int argc
, char *argv
[] )
121 glutInit(&argc
, argv
);
122 glutInitWindowPosition(0, 0);
123 glutInitWindowSize(300, 300);
124 glutInitDisplayMode( GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
126 Window
= glutCreateWindow("Texture Objects");
133 glutReshapeFunc( reshape
);
134 glutKeyboardFunc( key
);
135 /* glutIdleFunc( idle ); */
136 glutDisplayFunc( draw
);