diff --git a/.gitignore b/.gitignore index e4bc7b6..603c4a8 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,6 @@ *.exe *.out *.app + test/build +example/build diff --git a/.gitmodules b/.gitmodules index e69de29..fc6f8ae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "example/external/glfw"] + path = example/external/glfw + url = git@github.com:glfw/glfw.git diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..f499f4d --- /dev/null +++ b/example/Makefile @@ -0,0 +1,20 @@ +BUILD_DIR=build + +clean: + rm -rf $(BUILD_DIR) + +glfw: + mkdir -p $(BUILD_DIR)/glfw + cd $(BUILD_DIR)/glfw \ + && cmake -DGLFW_BUILD_TESTS=off -DGLFW_BUILD_DOCS=off -DGLFW_BUILD_EXAMPLES=off ../../external/glfw \ + && make + +example: + mkdir -p $(BUILD_DIR)/example + cd $(BUILD_DIR)/example \ + && $(CXX) $(CPPFLAGS) $(CXXFLAGS) -ohmmexample \ + -I../../external/glfw/include \ + -L../glfw/src \ + -lglew -lglfw3 \ + -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo \ + ../../main.cpp diff --git a/example/external/glfw b/example/external/glfw new file mode 160000 index 0000000..617a322 --- /dev/null +++ b/example/external/glfw @@ -0,0 +1 @@ +Subproject commit 617a322bd88c1b27f1fd7d05dc3723b6c5461a68 diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..18debc7 --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,53 @@ +#include + +#include +#include + +int main() +{ + // Initialise GLFW + glewExperimental = true; // Needed for core profile + if (!glfwInit()) { + fprintf( stderr, "Failed to initialize GLFW\n" ); + return -1; + } + + glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3 + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL + + // Open a window and create its OpenGL context + GLFWwindow* window; // (In the accompanying source code, this variable is global for simplicity) + window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL); + if (window == NULL) { + fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" ); + glfwTerminate(); + return -1; + } + glfwMakeContextCurrent(window); // Initialize GLEW + glewExperimental=true; // Needed in core profile + if (glewInit() != GLEW_OK) { + fprintf(stderr, "Failed to initialize GLEW\n"); + return -1; + } + + // Ensure we can capture the escape key being pressed below + glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); + + do { + // Clear the screen. It's not mentioned before Tutorial 02, but it can cause flickering, so it's there nonetheless. + glClear(GL_COLOR_BUFFER_BIT); + + // Draw nothing, see you in tutorial 2 ! + + // Swap buffers + glfwSwapBuffers(window); + glfwPollEvents(); + } while ( + // Check if the ESC key was pressed or the window was closed + glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS + && glfwWindowShouldClose(window) == 0 + ); +}