1、注释一定是我的,配置当然也是是我的。其他的是蓝宝书的。
/ Scissor.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#ifdef WIN32
#pragma comment(lib, "freeglut_static.lib")
#endif
#include <GLTools.h>
#define FREEGLUT_STATIC
#include <GL/glut.h>
//每次渲染执行剔除测试,减少绘制量
void renderScene(void)
{
//blue,透明
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
//红色区域启动剔除
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glScissor(100, 100, 600, 400);
glEnable(GL_SCISSOR_TEST);//启动剔除测试
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
glScissor(200, 200, 400, 200);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
glutSwapBuffers();
}
void changeSize(int w, int h)
{
//要预防计算时为0的除法溢出
if (h==0)
{
h = 1;
}
glViewport(0, 0, w, h);
}
int _tmain(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL Scissor");
glutReshapeFunc(changeSize);
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
}