blend

#include <gl/glew.h>
#include <gl/glut.h>
float g_rorate = 0.0;
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0,10,100,0,0,0,0,1,0);
	
	glDisable(GL_BLEND);

	glPushMatrix();
	glRotatef(10,1.0,0.1,0);
	glColor4f(0.1,0.2,0.5,0.5);
	glTranslatef(-10,10,10);
	glutSolidCube(20);
	glPopMatrix();

	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE,GL_ONE);
	glDisable(GL_DEPTH_TEST);
	glPushMatrix();	
	glRotatef(g_rorate,1.0,1.0,0);
	glColor4f(0.2,0.3,0.2,0.5);
	glutSolidCube(10);
	glPopMatrix();
#if 1
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);
	glPushMatrix();	
	glRotatef(g_rorate,1.0,1.0,0);
	glColor4f(0.2,0.3,0.2,0.5);
	glutSolidCube(10);
	glPopMatrix();
#endif
	glutSwapBuffers();
	glutPostRedisplay();
	g_rorate +=1;
}

void reshape(int w, int h)
{
	glViewport(0,0,w,h);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45,1.3333,1.0,10000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void key(unsigned char c, int x ,int y)
{
	switch(c)
	{
	case 'P':
	case 'p':
		glPolygonMode(GL_FRONT,GL_LINE);
		glEnable(GL_CULL_FACE);
		break;
	case 's':
	case 'S':
		glPolygonMode(GL_FRONT,GL_FILL);
		glDisable(GL_CULL_FACE);

		break;
	case 27:
		exit(0);
	}
}

void init()
{
	glClearColor(0.6,0.6,0.6,1.0);

	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH);
	glEnable(GL_DEPTH_TEST);
}

int main(int argc, char* argv[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowPosition(200,100);
	glutInitWindowSize(800,600);
	glutCreateWindow("blend");
	glewInit();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(key);

	init();
	glutMainLoop();
}

你可能感兴趣的:(blend)