// 范例P96.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <gl/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT); //清除所有像素
glColor3f(1.0,1.0,1.0); //设置画笔白色
/*在缓存中绘制4对顶点坐标的矩形*/
GLdouble eqn[4]={0.0,1.0,0.0,0.0};
GLdouble eqn2[4]={1.0,0.0,0.0,0.0};
GLdouble eqn3[4]={0.0,0.0,1.0,0};
glPushMatrix();
glTranslatef(0.0,0.0,-5.0); //模型变换
/*裁掉下半部分(y坐标小于0的部分)*/
glClipPlane(GL_CLIP_PLANE0,eqn);
glEnable(GL_CLIP_PLANE0);
/*裁掉左半部分(x坐标小于0的部分)*/
glClipPlane(GL_CLIP_PLANE1,eqn2);
glEnable(GL_CLIP_PLANE1);
glRotatef(90.0,1.0,0.0,0.0);
glutWireSphere(1.0,20,16);
glPopMatrix();
glFlush(); //立即显示出来
}
void init()
{
glClearColor(0.0,0.0,0.0,0.0); //用黑色清除背景
glShadeModel(GL_FLAT);
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30,(GLfloat)w/(GLfloat)h,0.1,20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500); //初始化窗口大小
glutInitWindowPosition(100,100); //初始化窗口位置
glutCreateWindow("hello"); //创建标题为“hello”的窗口
init(); //调用初始化函数
glutDisplayFunc(display); //注册回调函数
glutReshapeFunc(reshape);
glutMainLoop(); //进入主循环处理事件
return 0;
}
评论