模板缓冲
主要用于绘制轮廓
模板缓冲函数
模板更新
初始值
glClearStencil(0);//模板初始
glClearDepth(1);//深度初始
使能禁用背面
glEnable(GL_CULL_FACE);//使能禁用背面
glCullFace(GL_BACK);//禁用背部渲染
glFrontFace(GL_CW);//顺时针为正面
绘制立方体缓冲设置
//使能纹理
glEnable(GL_TEXTURE_CUBE_MAP);
//使能模板
glEnable(GL_STENCIL_TEST);
//使能深度测试
glEnable(GL_DEPTH_TEST);
//模板函数
glStencilFunc(GL_ALWAYS, 0, 1);
//模板更新
glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT);
//深度函数
glDepthFunc(GL_LESS);
绘制轮廓缓冲设置
//禁止纹理
glDisable(GL_TEXTURE_CUBE_MAP);
//模板函数
glStencilFunc(GL_EQUAL, 0, 1);
//深度函数
glDepthFunc(GL_LESS);
//颜色设置
glColor3f(1.0f, 1.0f, 0.0f);
示例
#define GLEW_STATIC
#include <GLEW/glew.h>
#include <GLFW/glfw3.h>
#include <assert.h>
#include <iostream>
#include <SOIL\SOIL.h>
#include <string.h>
#include <camera.h>
#include <model.h>
#include "glsl_my.h"
using namespace std;
#define my_pi 3.14159265358979323846 /* pi */
bool UPDATE = true;
//常量
const unsigned int ORIGIN_WIDTH = 1280;
const unsigned int ORIGIN_HEIGHT = 1024;
GLFWwindow* window;
GLuint textureid_3d;
// camera
Camera camera(glm::vec3(0.0f, 0.0f, 0.0f));
float lastX = ORIGIN_WIDTH / 2.0f;
float lastY = ORIGIN_HEIGHT / 2.0f;
bool firstMouse = true;
float deltaTime = 0.0f; // 当前帧与上一帧的时间差
float lastFrame = 0.0f; // 上一帧的时间
int gl_width = 1280, gl_height = 1024;//视窗宽度、高度
float radius_inner, radius_outer;
void setupdate() {
if (UPDATE == false)
{
UPDATE = true;
}
}
static void error_callback(int error, const char* description)
{
return;
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (action != GLFW_PRESS)
return;
switch (key)
{
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, GL_TRUE);
break;
case GLFW_KEY_W:
camera.ProcessKeyboard(FORWARD, deltaTime);
setupdate();
printf("GLFW_KEY_W\n");
break;
case GLFW_KEY_S:
camera.ProcessKeyboard(BACKWARD, deltaTime);
setupdate();
printf("GLFW_KEY_S\n");
break;
case GLFW_KEY_A