Only emit texcoords for enabled units. Enable/disable units with 0..7 keys.
Also, asst. clean-ups.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* GL_ARB_multitexture demo
|
* GL_ARB_multitexture demo
|
||||||
*
|
*
|
||||||
@@ -32,7 +31,6 @@ static GLint NumUnits = 1;
|
|||||||
static GLboolean TexEnabled[8];
|
static GLboolean TexEnabled[8];
|
||||||
|
|
||||||
static GLfloat Drift = 0.0;
|
static GLfloat Drift = 0.0;
|
||||||
static GLfloat drift_increment = 0.005;
|
|
||||||
static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0;
|
static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0;
|
||||||
|
|
||||||
|
|
||||||
@@ -41,9 +39,7 @@ static void Idle( void )
|
|||||||
if (Animate) {
|
if (Animate) {
|
||||||
GLint i;
|
GLint i;
|
||||||
|
|
||||||
Drift += drift_increment;
|
Drift = glutGet(GLUT_ELAPSED_TIME) * 0.001;
|
||||||
if (Drift >= 1.0)
|
|
||||||
Drift = 0.0;
|
|
||||||
|
|
||||||
for (i = 0; i < NumUnits; i++) {
|
for (i = 0; i < NumUnits; i++) {
|
||||||
glActiveTextureARB(GL_TEXTURE0_ARB + i);
|
glActiveTextureARB(GL_TEXTURE0_ARB + i);
|
||||||
@@ -57,10 +53,11 @@ static void Idle( void )
|
|||||||
glTranslatef(0.0, Drift, 0.0);
|
glTranslatef(0.0, Drift, 0.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glTranslatef(0.5, 0.5, 0.0);
|
float tx = 0.5, ty = 0.5;
|
||||||
|
glTranslatef(tx, ty, 0.0);
|
||||||
glRotatef(180.0 * Drift, 0, 0, 1);
|
glRotatef(180.0 * Drift, 0, 0, 1);
|
||||||
glScalef(1.0/i, 1.0/i, 1.0/i);
|
glScalef(1.0/i, 1.0/i, 1.0/i);
|
||||||
glTranslatef(-0.5, -0.5, 0.0);
|
glTranslatef(-tx, -ty + i * 0.1, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@@ -72,10 +69,9 @@ static void Idle( void )
|
|||||||
|
|
||||||
static void DrawObject(void)
|
static void DrawObject(void)
|
||||||
{
|
{
|
||||||
GLint i;
|
static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 };
|
||||||
GLint j;
|
static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 };
|
||||||
static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 };
|
GLint i, j;
|
||||||
static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 };
|
|
||||||
|
|
||||||
if (!TexEnabled[0] && !TexEnabled[1])
|
if (!TexEnabled[0] && !TexEnabled[1])
|
||||||
glColor3f(0.1, 0.1, 0.1); /* add onto this */
|
glColor3f(0.1, 0.1, 0.1); /* add onto this */
|
||||||
@@ -83,37 +79,20 @@ static void DrawObject(void)
|
|||||||
glColor3f(1, 1, 1); /* modulate this */
|
glColor3f(1, 1, 1); /* modulate this */
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
for (j = 0; j < 4; j++ ) {
|
||||||
/* Toggle between the vector and scalar entry points. This is done purely
|
for (i = 0; i < NumUnits; i++) {
|
||||||
* to hit multiple paths in the driver.
|
if (TexEnabled[i])
|
||||||
*/
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i,
|
||||||
if ( Drift > 0.49 ) {
|
tex_coords[j], tex_coords[j+1]);
|
||||||
for (j = 0; j < 4; j++ ) {
|
|
||||||
for (i = 0; i < NumUnits; i++)
|
|
||||||
glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i,
|
|
||||||
tex_coords[j], tex_coords[j+1]);
|
|
||||||
glVertex2f( vtx_coords[j], vtx_coords[j+1] );
|
|
||||||
}
|
}
|
||||||
|
glVertex2f( vtx_coords[j], vtx_coords[j+1] );
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
for (j = 0; j < 4; j++ ) {
|
|
||||||
for (i = 0; i < NumUnits; i++)
|
|
||||||
glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + i, & tex_coords[j]);
|
|
||||||
glVertex2fv( & vtx_coords[j] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void Display( void )
|
static void Display( void )
|
||||||
{
|
{
|
||||||
static GLint T0 = 0;
|
|
||||||
static GLint Frames = 0;
|
|
||||||
GLint t;
|
|
||||||
|
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT );
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
@@ -125,16 +104,6 @@ static void Display( void )
|
|||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|
||||||
Frames++;
|
|
||||||
|
|
||||||
t = glutGet(GLUT_ELAPSED_TIME);
|
|
||||||
if (t - T0 >= 250) {
|
|
||||||
GLfloat seconds = (t - T0) / 1000.0;
|
|
||||||
drift_increment = 2.2 * seconds / Frames;
|
|
||||||
T0 = t;
|
|
||||||
Frames = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,24 +120,34 @@ static void Reshape( int width, int height )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ToggleUnit(int unit)
|
||||||
|
{
|
||||||
|
TexEnabled[unit] = !TexEnabled[unit];
|
||||||
|
glActiveTextureARB(GL_TEXTURE0_ARB + unit);
|
||||||
|
if (TexEnabled[unit])
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
else
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
printf("Enabled: ");
|
||||||
|
for (unit = 0; unit < NumUnits; unit++)
|
||||||
|
printf("%d ", (int) TexEnabled[unit]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ModeMenu(int entry)
|
static void ModeMenu(int entry)
|
||||||
{
|
{
|
||||||
if (entry >= TEX0 && entry <= TEX7) {
|
if (entry >= TEX0 && entry <= TEX7) {
|
||||||
/* toggle */
|
/* toggle */
|
||||||
GLint i = entry - TEX0;
|
GLint i = entry - TEX0;
|
||||||
TexEnabled[i] = !TexEnabled[i];
|
ToggleUnit(i);
|
||||||
glActiveTextureARB(GL_TEXTURE0_ARB + i);
|
|
||||||
if (TexEnabled[i])
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
else
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
printf("Enabled: ");
|
|
||||||
for (i = 0; i < NumUnits; i++)
|
|
||||||
printf("%d ", (int) TexEnabled[i]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
else if (entry==ANIMATE) {
|
else if (entry==ANIMATE) {
|
||||||
Animate = !Animate;
|
Animate = !Animate;
|
||||||
|
if (Animate)
|
||||||
|
glutIdleFunc(Idle);
|
||||||
|
else
|
||||||
|
glutIdleFunc(NULL);
|
||||||
}
|
}
|
||||||
else if (entry==QUIT) {
|
else if (entry==QUIT) {
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -183,9 +162,36 @@ static void Key( unsigned char key, int x, int y )
|
|||||||
(void) x;
|
(void) x;
|
||||||
(void) y;
|
(void) y;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 27:
|
case 'a':
|
||||||
exit(0);
|
Animate = !Animate;
|
||||||
break;
|
break;
|
||||||
|
case '0':
|
||||||
|
ToggleUnit(0);
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
ToggleUnit(1);
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
ToggleUnit(2);
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
ToggleUnit(3);
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
ToggleUnit(4);
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
ToggleUnit(5);
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
ToggleUnit(6);
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
ToggleUnit(7);
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
@@ -327,7 +333,8 @@ int main( int argc, char *argv[] )
|
|||||||
glutKeyboardFunc( Key );
|
glutKeyboardFunc( Key );
|
||||||
glutSpecialFunc( SpecialKey );
|
glutSpecialFunc( SpecialKey );
|
||||||
glutDisplayFunc( Display );
|
glutDisplayFunc( Display );
|
||||||
glutIdleFunc( Idle );
|
if (Animate)
|
||||||
|
glutIdleFunc(Idle);
|
||||||
|
|
||||||
glutCreateMenu(ModeMenu);
|
glutCreateMenu(ModeMenu);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user