2 * Test glTexSubImage mid-way through a frame.
4 * The same texture is used for both quads but it gets redefined
5 * with glTexSubImage (or glTexImage) after the first quad.
14 static GLuint Window
= 0;
15 static GLboolean Anim
= GL_FALSE
;
16 static GLfloat Angle
= 0.0f
;
23 static int width
=8, height
=8;
24 static GLubyte tex1
[] = {
25 0, 0, 0, 0, 0, 0, 0, 0,
26 0, 0, 0, 0, 1, 0, 0, 0,
27 0, 0, 0, 1, 1, 0, 0, 0,
28 0, 0, 0, 0, 1, 0, 0, 0,
29 0, 0, 0, 0, 1, 0, 0, 0,
30 0, 0, 0, 0, 1, 0, 0, 0,
31 0, 0, 0, 1, 1, 1, 0, 0,
32 0, 0, 0, 0, 0, 0, 0, 0 };
38 for (i
=0;i
<height
;i
++) {
39 for (j
=0;j
<width
;j
++) {
41 if (tex1
[(height
-i
-1)*width
+j
]) {
42 tex
[p
][0] = 255; tex
[p
][1] = 0; tex
[p
][2] = 0;
45 tex
[p
][0] = 255; tex
[p
][1] = 255; tex
[p
][2] = 255;
50 glTexImage2D( GL_TEXTURE_2D
, 0, 3, width
, height
, 0,
51 GL_RGB
, GL_UNSIGNED_BYTE
, tex
);
58 static int width
=8, height
=8;
60 static GLubyte tex2
[] = {
61 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 2, 2, 0, 0, 0,
63 0, 0, 2, 0, 0, 2, 0, 0,
64 0, 0, 0, 0, 0, 2, 0, 0,
65 0, 0, 0, 0, 2, 0, 0, 0,
66 0, 0, 0, 2, 0, 0, 0, 0,
67 0, 0, 2, 2, 2, 2, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0 };
74 for (i
=0;i
<height
;i
++) {
75 for (j
=0;j
<width
;j
++) {
77 if (tex2
[(height
-i
-1)*width
+j
]) {
78 tex
[p
][0] = 0; tex
[p
][1] = 255; tex
[p
][2] = 0;
81 tex
[p
][0] = 0; tex
[p
][1] = 0; tex
[p
][2] = 255;
86 glTexImage2D( GL_TEXTURE_2D
, 0, 3, width
, height
, 0,
87 GL_RGB
, GL_UNSIGNED_BYTE
, tex
);
89 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, width
, height
,
90 GL_RGB
, GL_UNSIGNED_BYTE
, tex
);
96 static void draw( void )
98 glClear( GL_COLOR_BUFFER_BIT
);
100 glColor3f( 1.0, 1.0, 1.0 );
102 /* draw first polygon */
104 glTranslatef( -1.0, 0.0, 0.0 );
105 glRotatef( Angle
, 0.0, 0.0, 1.0 );
109 glBegin( GL_POLYGON
);
110 glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
111 glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
112 glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
113 glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
117 /* draw second polygon */
119 glTranslatef( 1.0, 0.0, 0.0 );
120 glRotatef( Angle
-90.0, 0.0, 1.0, 0.0 );
124 glBegin( GL_POLYGON
);
125 glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
126 glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
127 glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
128 glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
137 static void idle( void )
139 static double t0
= -1.;
140 double dt
, t
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
151 /* change view Angle, exit upon ESC */
152 static void key(unsigned char k
, int x
, int y
)
160 glutIdleFunc( idle
);
162 glutIdleFunc( NULL
);
165 glutDestroyWindow(Window
);
172 /* new window size or exposure */
173 static void reshape( int width
, int height
)
175 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
176 glMatrixMode(GL_PROJECTION
);
178 /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/
179 glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 );
180 glMatrixMode(GL_MODELVIEW
);
182 glTranslatef( 0.0, 0.0, -8.0 );
186 static void init( void )
188 /* Setup texturing */
189 glEnable( GL_TEXTURE_2D
);
190 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
193 glBindTexture( GL_TEXTURE_2D
, 0 );
194 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
195 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
196 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
197 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
202 int main( int argc
, char *argv
[] )
204 glutInit(&argc
, argv
);
205 glutInitWindowPosition(0, 0);
206 glutInitWindowSize(300, 300);
207 glutInitDisplayMode( GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
209 Window
= glutCreateWindow("Texture Objects");
216 glutReshapeFunc( reshape
);
217 glutKeyboardFunc( key
);
219 glutIdleFunc( idle
);
220 glutDisplayFunc( draw
);