OpenGL
[OpenGL] 1. 윈도우 창 생성 및 배경색 조절
Eu4ng
2022. 10. 7. 08:04
#include<iostream>
#include<glad/glad.h>
#include<GLFW/glfw3.h>
int main()
{
glfwInit();
// GLFW 버전 명시
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// OPENGL 프로필 설정 (Core 프로필)
// Core 프로필: 최신 함수들만 사용
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// 창 이름이 "OpenGL" 인 800 x 800 GLFWwindow 객체 생성
GLFWwindow* window = glfwCreateWindow(800, 800, "OpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
// Introduce the window into the current context
glfwMakeContextCurrent(window);
// Load GLAD so it configures OpenGL
gladLoadGL();
// Specify the viewport of OpenGL in the window
// In this case the viewport goes from x = 0, y = 0, to x = 800, y = 800
glViewport(0, 0, 800, 800);
// Specify the color of the background
glClearColor(0.07f, 0.13f, 0.17f, 1.0f);
// Clean the back buffer and assign the new color to it
glClear(GL_COLOR_BUFFER_BIT);
// Swap the back buffer with the front buffer
glfwSwapBuffers(window);
// 윈도우 창 x 버튼 누를 경우에만 프로그램이 꺼지도록 설정
// Main while loop
while (!glfwWindowShouldClose(window))
{
// Take care of all GLFW events
glfwPollEvents();
}
// Delete window before ending the program
glfwDestroyWindow(window);
// Terminate GLFW before ending the program
glfwTerminate();
return 0;
}