#define GLFW_INCLUDE_ES2
#include <GLFW/glfw3.h>
void errorfunc(int error, const char* discription)
{
fputs(discription,stderr);
}
void keyfunc(GLFWwindow* window, int key, int scancode, int action, int mods) //按键回调函数
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{
glfwSetWindowShouldClose(window,GL_TRUE); //退出是销毁窗口
}
}
int main()
{
GLFWwindow* windows;
glfwSetErrorCallback(errorfunc);
if (!glfwInit())
{
exit(EXIT_FAILURE);
}
windows = glfwCreateWindow(600, 480, "test opengl windows", NULL, NULL); //创建窗口
if (!windows) {
glfwTerminate();
}
glfwMakeContextCurrent(windows);
glfwSetKeyCallback(windows,keyfunc);
while (!glfwWindowShouldClose(windows)) //渲染循环
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(....);
//do something about opengl
glfwSwapBuffers(windows);
glfwPollEvents();
}
glfwDestroyWindow(windows);
glfwTerminate();
return 0;
#include <GLFW/glfw3.h>
void errorfunc(int error, const char* discription)
{
fputs(discription,stderr);
}
void keyfunc(GLFWwindow* window, int key, int scancode, int action, int mods) //按键回调函数
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{
glfwSetWindowShouldClose(window,GL_TRUE); //退出是销毁窗口
}
}
int main()
{
GLFWwindow* windows;
glfwSetErrorCallback(errorfunc);
if (!glfwInit())
{
exit(EXIT_FAILURE);
}
windows = glfwCreateWindow(600, 480, "test opengl windows", NULL, NULL); //创建窗口
if (!windows) {
glfwTerminate();
}
glfwMakeContextCurrent(windows);
glfwSetKeyCallback(windows,keyfunc);
while (!glfwWindowShouldClose(windows)) //渲染循环
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(....);
//do something about opengl
glfwSwapBuffers(windows);
glfwPollEvents();
}
glfwDestroyWindow(windows);
glfwTerminate();
return 0;