학습한 내용을 정리해둔 글입니다. 잘못된 내용이나 오타가 있다면 댓글로 남겨주세요.
Visual Studio로 Empty Project를 만든 뒤 Dependencies, src, res 폴더를 만들어준다.
Dependencies 폴더 - 라이브러리 파일 보관용
src 폴더 - 프로젝트에서 개발할 소스 파일 보관용
res 폴더 - 모델, 쉐이더, 텍스쳐 파일 보관용
GLFW를 다운받고 Dependencies 폴더에 GLFW 하위 폴더를 만들고 라이브러리 파일을 옮겨준다.
32비트, 64비트, 디버그, 릴리즈에 맞는 라이브러리를 각각 넣어준다.
GLFW-include-GLFW 와 같은 폴더 구조로 되어있는 이유는 최상위 GLFW 폴더는 다른 라이브러리와 구분하기 위함이고 최하위 GLFW는 개발 중에 #include <GLFW/...> 를 통해 쉽게 접근하고 다른 헤더들과 직관적으로 구분하기 위함이다.
Configuration - All Configurations
Platform - All Platforms
output 경로를 bin 폴더에 config 별로 directory를 지정한다.
General - Output Directory
$(SolutionDir)bin\$(Platform)\$(Configuration)\
General - Intermediate Directory
$(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\
프로젝트 include 경로를 추가한다.
$(SolutionDir)Dependencies\GLFW\include;$(SolutionDir)Dependencies
프로젝트에 포함할 라이브러리를 추가한다.
glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;Shell32.lib
라이브러리 경로를 추가한다. Configuration, Platform을 각각의 *.lib에 맞게 변경한다.
ex) Configuration - Debug, Platform - Win32 => x86\Debug\glfw3.lib
$(SolutionDir)Dependencies\GLFW\lib\x64\Debug
$(SolutionDir)Dependencies\GLFW\lib\x64\Release
$(SolutionDir)Dependencies\GLFW\lib\x86\Debug
$(SolutionDir)Dependencies\GLFW\lib\x86\Release
GLFW에서 제공하는 기본 코드이다.
#include <GLFW/glfw3.h>
int main(void) {
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) {
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
output
...
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f( 0.0f, 0.5f);
glVertex2f( 0.5f, -0.5f);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
...
output