Start of example program

This commit is contained in:
Ben Visness
2018-05-27 15:08:07 -05:00
parent f8b3a84cec
commit fdea881102
5 changed files with 79 additions and 0 deletions

2
.gitignore vendored
View File

@@ -31,4 +31,6 @@
*.exe *.exe
*.out *.out
*.app *.app
test/build test/build
example/build

3
.gitmodules vendored
View File

@@ -0,0 +1,3 @@
[submodule "example/external/glfw"]
path = example/external/glfw
url = git@github.com:glfw/glfw.git

20
example/Makefile Normal file
View File

@@ -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

1
example/external/glfw vendored Submodule

Submodule example/external/glfw added at 617a322bd8

53
example/main.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
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
);
}