#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h>
#include <GL/glut.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#pragma comment(lib,"glaux.lib")
void CreatWindow (void)
{
auxInitDisplayMode (AUX_RGB);
auxInitPosition (0,0,400,400);
auxInitWindow ("半透明");
}
void myinit(void)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_FLAT);
glClearColor(1.0, 1.0, 1.0, 0.0);
}
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor4f(1.0, 0.0, 0.0, 0.3);
glTranslatef(-0.4,-0.4,0.0);
glRectf(0.0, 0.0,1.0, 1.0);
glColor4f(0.0, 1.0, 0.0, 0);
glTranslatef(0.4,0.4,0.0);
glRectf(0.0, 0.0, 1.0, 1.0);
glColor4f(0.0, 0.0, 1.0, 0.3);
glTranslatef(0.30,0.30,0.0);
glRectf(0.0, 0.0, 1.0, 1.0);
glFlush();
}
void CALLBACK myReshape(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-4,4,4,-4,8,-8);
else
glOrtho (4,-4,-4,4,-8,8);
}
void main()
{
CreatWindow();
myinit();
auxReshapeFunc(myReshape);
auxMainLoop(display);
}