GLBLEND.C
上传用户:tengyuc
上传日期:2007-08-14
资源大小:722k
文件大小:3k
- #include <GL/glut.h>
- #include <stdlib.h>
- #include <stdio.h>
- #pragma warning( disable : 4305 )
-
- GLdouble rot_angle;
- void init(void)
- {
- rot_angle = 0.0;
- glClearColor(1.0, 1.0, 1.0, 1.0);
- glShadeModel(GL_FLAT);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- glRotated(rot_angle, 1.0, 0.0, 0.0);
- glRotated(rot_angle, 0.0, 1.0, 0.0);
- glBegin(GL_TRIANGLE_STRIP);
- glColor4f(1.0, 0.0, 0.0, 0.3);
- glVertex3f(-1.0, -1.0, 1.0);
- glVertex3f(1.0, -1.0, 1.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glVertex3f(1.0, 1.0, 1.0);
- glColor4f(0.0, 1.0, 0.0, 0.3);
- glVertex3f(-1.0, 1.0, -1.0);
- glVertex3f(1.0, 1.0, -1.0);
- glColor4f(0.0, 0.0, 1.0, 0.3);
- glVertex3f(-1.0, -1.0, -1.0);
- glVertex3f(1.0, -1.0, -1.0);
- glEnd();
- glBegin(GL_TRIANGLE_STRIP);
- glColor4f(1.0, 1.0, 0.0, 0.3);
- glVertex3f(-1.0, 1.0, -1.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glVertex3f(-1.0, -1.0, -1.0);
- glVertex3f(-1.0, -1.0, 1.0);
- glColor4f(0.0, 1.0, 1.0, 0.3);
- glVertex3f(1.0, -1.0, -1.0);
- glVertex3f(1.0, -1.0, 1.0);
- glColor4f(1.0, 0.0, 1.0, 0.3);
- glVertex3f(1.0, 1.0, -1.0);
- glVertex3f(1.0, 1.0, 1.0);
- glEnd();
- glPopMatrix();
- glutSwapBuffers();
- }
- void reshape (int w, int h)
- {
- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, (GLfloat)w / (GLfloat)h, 1.0, 10.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- }
- void keyboard (unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27:
- case 'Q':
- case 'q':
- exit(0);
- break;
- }
- }
- void idle(void)
- {
- rot_angle += 0.25;
- if( rot_angle > 360.0 )
- rot_angle -= 360.0;
- glutPostRedisplay();
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowSize(250, 250);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Transparent Cube");
- init();
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutIdleFunc(idle);
- glutMainLoop();
- return 0;
- }