2 /* Exercise 1D textures
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 */
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 );
43 static void idle( void )
52 /* change view Angle, exit upon ESC */
53 static void key(unsigned char k
, int x
, int y
)
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
);
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
);
75 glTranslatef( 0.0, 0.0, -8.0 );
79 static void init( void )
85 glDisable( GL_DITHER
);
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
++) {
102 /* map 0..255 to -PI .. PI */
103 f
= ((i
/ 255.0) - .5) * (3.141592 * 2);
107 /* map -1..1 to 0..255 */
108 tex
[i
][0] = (f
+1.0)/2.0 * 255.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");
137 glutReshapeFunc( reshape
);
138 glutKeyboardFunc( key
);
139 /* glutIdleFunc( idle ); */
140 glutDisplayFunc( draw
);