├── .gitignore
├── CMakeModules
└── app.plist.in
├── .gitmodules
├── main.cpp
├── README.md
└── CMakeLists.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | xcode/
3 |
--------------------------------------------------------------------------------
/CMakeModules/app.plist.in:
--------------------------------------------------------------------------------
1 |
2 | NSHighResolutionCapable
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "external/glfw"]
2 | path = external/glfw
3 | url = https://github.com/glfw/glfw.git
4 | [submodule "external/glm"]
5 | path = external/glm
6 | url = https://github.com/g-truc/glm.git
7 | [submodule "external/glew"]
8 | path = external/glew
9 | url = https://github.com/nigels-com/glew.git
10 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | using namespace glm;
10 |
11 | #define GLSL(src) #src
12 |
13 | static void error_callback(int error, const char *description) {
14 | fputs(description, stderr);
15 | }
16 |
17 | static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
18 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
19 | glfwSetWindowShouldClose(window, GL_TRUE);
20 | }
21 |
22 | static void render(GLFWwindow *window) {
23 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT);
24 | }
25 |
26 | int main(void) {
27 | GLFWwindow *window;
28 |
29 | glfwSetErrorCallback(error_callback);
30 |
31 | if (!glfwInit())
32 | exit(EXIT_FAILURE);
33 |
34 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
35 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
36 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
37 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
38 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
39 |
40 | window = glfwCreateWindow(640, 480, "OpenGL Boilerplate", NULL, NULL);
41 | if (!window) {
42 | glfwTerminate();
43 | exit(EXIT_FAILURE);
44 | }
45 |
46 | glewExperimental = GL_TRUE;
47 | glewInit();
48 |
49 | glfwMakeContextCurrent(window);
50 |
51 | glfwSetKeyCallback(window, key_callback);
52 |
53 | while (!glfwWindowShouldClose(window)) {
54 | render(window);
55 |
56 | glfwSwapBuffers(window);
57 | glfwPollEvents();
58 | //glfwWaitEvents();
59 | }
60 |
61 | glfwDestroyWindow(window);
62 |
63 | glfwTerminate();
64 | exit(EXIT_SUCCESS);
65 | }
66 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OpenGL C++ Boilerplate
2 |
3 | A cross-platform boilerplate project for OpenGL using GLFW and GLEW in C++. Compilation is done with `cmake`.
4 |
5 | I want to keep this project as simple as possible and is targetted to those who are learning modern OpenGL.
6 |
7 | ## Cloning
8 |
9 | The `external/` folder contains all the external dependencies used, and they are tracked using git submodules. In order to compile the program, you should first clone the repository and then download the dependencies with `git submodule init` and `git submodule update`
10 |
11 | Alternatively, you can achieve this with a one-liner as follows:
12 |
13 | git clone git@github.com:andersonfreitas/opengl-boilerplate.git --recursive
14 |
15 | ## Initializing GLEW
16 |
17 | Before compiling, you should first generate the `include/` folder for GLFW:
18 |
19 | cd external/glew
20 | make extensions
21 |
22 | ## Build
23 |
24 | mkdir build && cd build
25 | cmake ..
26 | make
27 |
28 | ### Building with XCode
29 |
30 | mkdir xcode && cd xcode
31 | cmake -G "Xcode" ..
32 |
33 | Then open the generated `Project.xcodeproj` project.
34 |
35 | If you don't have CMake installed on your Mac, the easist way is to install is with [Homebrew](http://brew.sh) using `brew install cmake`
36 |
37 | ### Building with Visual Studio
38 |
39 | CMake comes with a diverse options of [generators](http://www.cmake.org/cmake/help/v2.8.8/cmake.html#section_Generators). Use the CMake GUI on Windows to automatically create a project solution based on this project.
40 |
41 | ## Using a different dependency version
42 |
43 | If you want to use a different version of any dependency tracked as a submodule, you just need to checkout the desired version in the repository:
44 |
45 | cd external/my_dep
46 | git checkout XXX
47 | cd ..
48 | git add external/my_dep
49 | git commit -m "Using my_dep at branch/tag XXX"
50 |
51 | ## Dependencies
52 |
53 | * [GLFW](https://github.com/glfw/glfw)
54 | * [GLEW](http://github.com/nigels-com/glew.git)
55 | * [GLM](https://github.com/g-truc/glm)
56 | * [CMake](http://www.cmake.org/)
57 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8)
2 |
3 | set(GLFW_SOURCE_DIR "external/glfw")
4 | set(GLM_SOURCE_DIR "external/glm")
5 | set(GLEW_SOURCE_DIR "external/glew")
6 |
7 | # Building only the GLFW lib
8 | set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
9 | set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "")
10 | set(GLFW_BUILD_TESTS OFF CACHE BOOL "")
11 | set(GLFW_BUILD_DOCS OFF CACHE BOOL "")
12 | set(GLFW_INSTALL OFF CACHE BOOL "")
13 |
14 | add_subdirectory(${GLFW_SOURCE_DIR} ${GLEW_SOURCE_DIR})
15 |
16 | include_directories(${GLFW_SOURCE_DIR}/include
17 | ${GLFW_SOURCE_DIR}/deps
18 | ${GLM_SOURCE_DIR}
19 | ${GLEW_SOURCE_DIR}/include)
20 |
21 | add_library(glew STATIC
22 | ${GLEW_SOURCE_DIR}/src/glew.c
23 | ${GLEW_SOURCE_DIR}/include
24 | )
25 |
26 | target_link_libraries(glew ${GLFW_LIBRARIES})
27 |
28 | add_definitions(
29 | -DGLEW_STATIC
30 | )
31 |
32 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
33 |
34 |
35 | if (APPLE)
36 | set(APP_NAME "OpenGLBoilerplate")
37 |
38 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/icon.icns)
39 | add_executable(${APP_NAME} MACOSX_BUNDLE main.cpp icon.icns)
40 | set_source_files_properties("icon.icns" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
41 | set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/icon.icns)
42 | else ()
43 |
44 | add_executable(${APP_NAME} MACOSX_BUNDLE main.cpp)
45 | endif ()
46 |
47 | # set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/app.plist.in)
48 |
49 | set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME ${APP_NAME})
50 | set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0")
51 | set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_LONG_VERSION_STRING "1.0")
52 | set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_STRING "OpenGL boilerplate example app")
53 | else()
54 | set(APP_NAME "opengl-boilerplate")
55 | add_executable(${APP_NAME} main.cpp)
56 | endif()
57 |
58 | target_link_libraries(${APP_NAME} glfw ${GLFW_LIBRARIES} glew)
59 |
60 |
61 |
--------------------------------------------------------------------------------