#include <windows.h>
#include <stdio.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include <gl\glaux.h>
GLuint texture[10];
float xrot;
float yrot;
int LoadTextures(char *filename,int numtexture)
{
AUX_RGBImageRec *texture1;
texture1=auxDIBImageLoad(filename);
glGenTextures(1, &texture[numtexture]);
glBindTexture(GL_TEXTURE_2D, texture[numtexture]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
void init(void)
{
glEnable ( GL_TEXTURE_2D );
LoadTextures("1.bmp",0);
LoadTextures("2.bmp",1);
}
void reshape( int w, int h )
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 1000.0 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );
}
void display( void )
{
init();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity ( );
glPushMatrix();
glTranslatef ( 0.0, 0.0, -5.0 );
glRotatef ( xrot, 1.0, 0.0, 0.0 );
glRotatef ( yrot, 0.0, 1.0, 0.0 );
glRotatef ( 0, 0.0, 0.0, 1.0 );
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glEnd();
glPopMatrix();
xrot+=0.3f;
glutSwapBuffers();
}
void keyboard ( unsigned char key, int x, int y )
{
if (key == 27) exit(0);
}
void mouse(int button, int state,int x, int y)
{
if (button == GLUT_LEFT_BUTTON) {
yrot+=0.3f;
}
}
int main ( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE );
glutInitWindowSize (500, 500 );
glutCreateWindow ( "" );
glutFullScreen();
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutKeyboardFunc( keyboard );
glutMouseFunc(mouse);
glutIdleFunc( display );
glutMainLoop();
}
|