How To Setup Opengl Project: (Opengl) Installation of Opengl With Visual Studio 2017 (GLFW, Glew, Glut)
How To Setup Opengl Project: (Opengl) Installation of Opengl With Visual Studio 2017 (GLFW, Glew, Glut)
Date: 2019.03.26
[OpenGL] Installation of OpenGL with Visual Studio 2017 (GLFW, GLEW, GLUT)
Reference: http://webnautes.tistory.com/1102
* Students, download Visual Studio Community 2017 version (with your portal id)
* If you do not want to use with Visual Studio, you can use Eclipse, Intellij, Netbeans ... etc.
* Please note that when you download, select language service package (English, Korean...)
* Please use the pre-compiled binaries. (If you are the Windows OS users)
* Please download source package and compile them.
Source Package Download Link: https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zip
Guide for compiling GLFW: http://www.glfw.org/docs/latest/compile.html
3-1 Unzip the downloaded compiled file, and copy include folder to your project location.
* ex. Copy include file to the C:\Users\heave\source\repos\CGOpenGLExample\CGOpenGLExample
4-1 Unzip the downloaded compiled file, and copy include folder to your project location. (it will be
overwritten)
* Please make sure, in include file (in the Project Location), you have GL and GLFW folder.
5. Download FreeGLUT
Download Link: https://www.transmissionzero.co.uk/software/freeglut-devel/
Before you run the code, please copy the freeglut.dll, glew32.dll, glfw3.dll to the
C:\Windows\SysWOW64 (if your system is 64bit computer, if not copy to
C:\Windows\System32).
6. Run Example Code
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
glfwSetErrorCallback(show_glfw_error);
if (!glfwInit()) {
std::cerr << "GLFW 초기화 실패" << '\n';
exit(-1);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwMakeContextCurrent(window);
glfwSetWindowSizeCallback(window, window_resized);
glfwSetKeyCallback(window, key_pressed);
glfwSwapInterval(1);
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (err != GLEW_OK) {
std::cerr << "GLEW 초기화 실패 " << glewGetErrorString(err) << '\n';
glfwTerminate();
exit(-1);
}
int nr_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &nr_extensions);
glClearColor(0, 0, 1, 1);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
glClearColor(0, 0, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
void key_pressed(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == 'Q' && action == GLFW_PRESS) {
glfwTerminate();
exit(0);
}
}