-
-
Save lennart/87592abd68bbe4062204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8) | |
set(app ocean) | |
set(sd ${CMAKE_CURRENT_LIST_DIR}/../src/) | |
include_directories( | |
${CMAKE_CURRENT_LIST_DIR}/../src | |
${CMAKE_CURRENT_LIST_DIR}/../extern/include | |
) | |
add_executable(${app} | |
${sd}/main.cpp | |
) | |
if(APPLE) | |
find_library(fr_corefoundation CoreFoundation) | |
find_library(fr_cocoa Cocoa) | |
find_library(fr_opengl OpenGL) | |
find_library(fr_iokit IOKit) | |
find_library(fr_corevideo CoreVideo) | |
target_link_libraries( | |
${app} | |
${CMAKE_CURRENT_LIST_DIR}/../extern/lib/libglfw3.a | |
${fr_corefoundation} | |
${fr_cocoa} | |
${fr_opengl} | |
${fr_iokit} | |
${fr_corevideo} | |
-lz | |
) | |
elseif(WIN32) | |
get_filename_component(ed ${EXTERN_DIR} ABSOLUTE) | |
target_link_libraries( | |
${app} | |
${ed}/lib/glfw3.lib | |
Opengl32.lib | |
ws2_32.lib # opengl / glfw | |
psapi.lib # opengl / glfw | |
iphlpapi.lib # opengl / glfw | |
) | |
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
BASIC GLFW + GLXW WINDOW AND OPENGL SETUP | |
------------------------------------------ | |
See https://gist.github.com/roxlu/6698180 for the latest version of the example. | |
We make use of the GLAD library for GL loading, see: https://github.com/Dav1dde/glad/ | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <glad/glad.h> | |
#include <GLFW/glfw3.h> | |
void button_callback(GLFWwindow* win, int bt, int action, int mods); | |
void cursor_callback(GLFWwindow* win, double x, double y); | |
void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods); | |
void char_callback(GLFWwindow* win, unsigned int key); | |
void error_callback(int err, const char* desc); | |
void resize_callback(GLFWwindow* window, int width, int height); | |
int main() { | |
glfwSetErrorCallback(error_callback); | |
if(!glfwInit()) { | |
printf("Error: cannot setup glfw.\n"); | |
exit(EXIT_FAILURE); | |
} | |
glfwWindowHint(GLFW_SAMPLES, 4); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); | |
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
GLFWwindow* win = NULL; | |
int w = 1280; | |
int h = 720; | |
win = glfwCreateWindow(w, h, "GLFW", NULL, NULL); | |
if(!win) { | |
glfwTerminate(); | |
exit(EXIT_FAILURE); | |
} | |
glfwSetFramebufferSizeCallback(win, resize_callback); | |
glfwSetKeyCallback(win, key_callback); | |
glfwSetCharCallback(win, char_callback); | |
glfwSetCursorPosCallback(win, cursor_callback); | |
glfwSetMouseButtonCallback(win, button_callback); | |
glfwMakeContextCurrent(win); | |
glfwSwapInterval(1); | |
if (!gladLoadGL()) { | |
printf("Cannot load GL.\n"); | |
exit(1); | |
} | |
// ---------------------------------------------------------------- | |
// THIS IS WHERE YOU START CALLING OPENGL FUNCTIONS, NOT EARLIER!! | |
// ---------------------------------------------------------------- | |
while(!glfwWindowShouldClose(win)) { | |
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glfwSwapBuffers(win); | |
glfwPollEvents(); | |
} | |
glfwTerminate(); | |
return EXIT_SUCCESS; | |
} | |
void char_callback(GLFWwindow* win, unsigned int key) { | |
} | |
void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods) { | |
if(action != GLFW_PRESS) { | |
return; | |
} | |
switch(key) { | |
case GLFW_KEY_ESCAPE: { | |
glfwSetWindowShouldClose(win, GL_TRUE); | |
break; | |
} | |
}; | |
} | |
void resize_callback(GLFWwindow* window, int width, int height) { | |
} | |
void cursor_callback(GLFWwindow* win, double x, double y) { | |
} | |
void button_callback(GLFWwindow* win, int bt, int action, int mods) { | |
/* | |
if(action == GLFW_PRESS) { | |
} | |
*/ | |
} | |
void error_callback(int err, const char* desc) { | |
printf("GLFW error: %s (%d)\n", desc, err); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ ! -d build ] ; then | |
mkdir build | |
fi | |
cd build | |
cmake ../ | |
cmake --build . | |
./ocean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment