LearnOpenGL1.0创建窗口
来源:互联网 发布:php酒店管理系统 编辑:程序博客网 时间:2024/05/18 07:33
source : 1 2
一、准备
可使用GLFW库、SDL库或者freeGLUT库。 其中可用glew库或glad库setup the OpenGL Function pointers
二、初始化并配置GLFW
glfwInit()glfwWindowHint()
三、创建窗口对象
glfwWindow *windowglfwCreatWindow()glfwTerminate()glfwMakeContextCurrent(window)
四、设置glew管理方式并初始化
glewExperimental = GL_TRUE;glewInit()
五、定义视窗(Viewport)尺寸
glfwGetFramebufferSize()glViewport()
六、Game loop
// 程序循环while(!glfwWindowShouldClose(window)){ // 检查事件 glfwPollEvents(); // 渲染指令 ... // 交换缓冲 glfwSwapBuffers(window);}
七、设置窗口回调
glfwSetKeyCallback()void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
八、源代码
#include <iostream>#include "GL\glew.h"#include "GLFW\glfw3.h"// Function prototypesvoid key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);// Window dimensionsconst GLuint WIDTH = 800, HEIGHT = 600;// The MAIN function, from here we start the application and run the game loopint main(){ std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl; // Init GLFW glfwInit(); // Set all the required options for GLFW glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //核心模式 glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); //不可调整大小 // Create a GLFWwindow object that we can use for GLFW's functions GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr); if (window == nullptr) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Set the required callback functions glfwSetKeyCallback(window, key_callback); // Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions glewExperimental = GL_TRUE; // Initialize GLEW to setup the OpenGL Function pointers if (glewInit() != GLEW_OK) { std::cout << "Failed to initialize GLEW" << std::endl; return -1; } // Define the viewport dimensions int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); // Game loop while (!glfwWindowShouldClose(window)) { // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions glfwPollEvents(); // Render // Clear the colorbuffer glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // Swap the screen buffers glfwSwapBuffers(window); } // Terminate GLFW, clearing any resources allocated by GLFW. glfwTerminate(); return 0;}// Is called whenever a key is pressed/released via GLFWvoid key_callback(GLFWwindow* window, int key, int scancode, int action, int mode){ std::cout << key << std::endl; if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE);}
阅读全文
0 0
- LearnOpenGL1.0创建窗口
- V C6.0++ 创建窗口
- SDL2.0窗口创建历程
- 创建窗口
- 创建窗口
- 创建窗口
- 创建窗口
- 创建窗口
- 创建窗口
- 创建窗口
- 创建窗口
- API创建创建子窗口
- 创建不规则窗口
- 动态创建数据窗口
- 创建透明窗口
- 总结创建窗口全过程
- 创建一不规则窗口
- 如何创建不规则窗口
- Java:一维数组
- 同花顺&京颐测试工程师面试问题总结
- 斐波拉切数列(python实现)
- 做了几天杭电ACM感想
- 跑步去了
- LearnOpenGL1.0创建窗口
- 声明式事务
- PAT乙级1024
- 线程间通信之信号量(多文件编程,全局变量的问题)
- 2017.9.27 青蛙的约会 失败总结
- OOP基础
- HDOJ2034
- 利用python制作点读翻译软件(基于google api)
- struts2的传参和struts2的第二种开发方式(继承ActionSupport)