本文整理汇总了C++中SkyBox::getTextId方法的典型用法代码示例。如果您正苦于以下问题:C++ SkyBox::getTextId方法的具体用法?C++ SkyBox::getTextId怎么用?C++ SkyBox::getTextId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkyBox
的用法示例。
在下文中一共展示了SkyBox::getTextId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
// 鼠标捕获 停留在程序内
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// 初始化GLEW 获取OpenGL函数
glewExperimental = GL_TRUE; // 让glew获取所有拓展函数
GLenum status = glewInit();
if (status != GLEW_OK)
{
std::cout << "Error::GLEW glew version:" << glewGetString(GLEW_VERSION)
<< " error string:" << glewGetErrorString(status) << std::endl;
glfwTerminate();
std::system("pause");
return -1;
}
// 设置视口参数
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
//Section1 加载模型数据
Model objModel;
if (!objModel.loadModel("../../resources/models/sphere/sphere.obj"))
{
glfwTerminate();
std::system("pause");
return -1;
}
// Section2 创建Skybox
std::vector<const char*> faces;
faces.push_back("../../resources/skyboxes/sky/sky_rt.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_lf.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_up.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_dn.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_bk.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_ft.jpg");
SkyBox skybox;
skybox.init(faces);
// Section3 准备着色器程序
Shader shader("scene.vertex", "scene.frag");
Shader skyBoxShader("skybox.vertex", "skybox.frag");
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
// 开始游戏主循环
while (!glfwWindowShouldClose(window))
{
GLfloat currentFrame = (GLfloat)glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents(); // 处理例如鼠标 键盘等事件
do_movement(); // 根据用户操作情况 更新相机属性
// 设置colorBuffer颜色
glClearColor(0.18f, 0.04f, 0.14f, 1.0f);
// 清除colorBuffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 先绘制场景
shader.use();
glm::mat4 projection = glm::perspective(camera.mouse_zoom,
(GLfloat)(WINDOW_WIDTH) / WINDOW_HEIGHT, 0.1f, 100.0f); // 投影矩阵
glUniformMatrix4fv(glGetUniformLocation(shader.programId, "projection"),
1, GL_FALSE, glm::value_ptr(projection));
glm::mat4 view = camera.getViewMatrix(); // 视变换矩阵
glUniformMatrix4fv(glGetUniformLocation(shader.programId, "view"),
1, GL_FALSE, glm::value_ptr(view));
glm::mat4 model;
// model = glm::translate(model, glm::vec3(0.0f, -1.55f, 0.0f)); // 适当下调位置
// model = glm::scale(model, glm::vec3(0.2f, 0.2f, 0.2f)); // 适当缩小模型
glUniformMatrix4fv(glGetUniformLocation(shader.programId, "model"),
1, GL_FALSE, glm::value_ptr(model));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.getTextId());
glUniform1i(glGetUniformLocation(shader.programId, "envText"), 0);
glUniform3f(glGetUniformLocation(shader.programId, "cameraPos"),
camera.position.x, camera.position.y, camera.position.z); // 注意设置观察者位置
objModel.draw(shader); // 绘制球体
// 然后绘制包围盒
skyBoxShader.use();
view = glm::mat4(glm::mat3(camera.getViewMatrix())); // 视变换矩阵 移除translate部分
glUniformMatrix4fv(glGetUniformLocation(skyBoxShader.programId, "projection"),
1, GL_FALSE, glm::value_ptr(projection));
glUniformMatrix4fv(glGetUniformLocation(skyBoxShader.programId, "view"),
1, GL_FALSE, glm::value_ptr(view));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.getTextId());
glUniform1i(glGetUniformLocation(skyBoxShader.programId, "skybox"), 0);
skybox.draw(skyBoxShader);
glBindVertexArray(0);
glUseProgram(0);
glfwSwapBuffers(window); // 交换缓存
}
// 释放资源
glfwTerminate();
return 0;
}