80 lines
2.0 KiB
C++
80 lines
2.0 KiB
C++
|
#include <glad/glad.h>
|
|||
|
#include <GLFW/glfw3.h>
|
|||
|
|
|||
|
#include <iostream>
|
|||
|
|
|||
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
|||
|
void processInput(GLFWwindow* window);
|
|||
|
|
|||
|
// settings
|
|||
|
const unsigned int SCR_WIDTH = 800;
|
|||
|
const unsigned int SCR_HEIGHT = 600;
|
|||
|
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
// <20><>ʼ<EFBFBD><CABC> GLFW
|
|||
|
glfwInit();
|
|||
|
// <20><><EFBFBD><EFBFBD> GLFW : <20>汾 3.3 ,ʹ<><CAB9> Core-profile ģʽ
|
|||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|||
|
|
|||
|
// MACOS ƽ̨<C6BD><CCA8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|||
|
#ifdef _APPLE_
|
|||
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|||
|
#endif // _APPLE_
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>
|
|||
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
|||
|
if (window == NULL)
|
|||
|
{
|
|||
|
std::cout << "Failed to create GLFW window" << std::endl;
|
|||
|
glfwTerminate();
|
|||
|
return -1;
|
|||
|
}
|
|||
|
glfwMakeContextCurrent(window);
|
|||
|
// ע<><D7A2>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD>仯ʱ<E4BBAF>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|||
|
|
|||
|
// <20><>ʼ<EFBFBD><CABC> GLAD : load all OpenGL function pointers
|
|||
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
|||
|
{
|
|||
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
// <20><>Ⱦѭ<C8BE><D1AD> (Render Loop)
|
|||
|
while (!glfwWindowShouldClose(window))
|
|||
|
{
|
|||
|
// input
|
|||
|
processInput(window);
|
|||
|
|
|||
|
// <20><>Ⱦָ<C8BE><D6B8>
|
|||
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); // ״̬<D7B4><CCAC><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
glClear(GL_COLOR_BUFFER_BIT); // ״̬ʹ<CCAC>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
|
|||
|
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
|||
|
glfwSwapBuffers(window);
|
|||
|
glfwPollEvents();
|
|||
|
}
|
|||
|
|
|||
|
// glfw: terminate, clearing all previously allocated GLFW resources
|
|||
|
glfwTerminate();
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>ڴ<EFBFBD>С<EFBFBD>ı<EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||
|
{
|
|||
|
// <20>ӿ<EFBFBD>
|
|||
|
glViewport(0, 0, width, height);
|
|||
|
}
|
|||
|
|
|||
|
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
|
|||
|
void processInput(GLFWwindow* window)
|
|||
|
{
|
|||
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
|||
|
glfwSetWindowShouldClose(window, true);
|
|||
|
}
|