-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complement OpenGL ES examples for different windowing toolkits
- Loading branch information
Showing
43 changed files
with
2,587 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
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
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
|
||
# | ||
# External dependencies | ||
# | ||
|
||
find_package(glfw3 QUIET) | ||
|
||
|
||
# | ||
# Executable name and options | ||
# | ||
|
||
# Target name | ||
set(target cubescape-glfw-gles) | ||
|
||
# Exit here if required dependencies are not met | ||
if (NOT glfw3_FOUND) | ||
message("Example ${target} skipped: glfw3 not found") | ||
return() | ||
else() | ||
message(STATUS "Example ${target}") | ||
endif() | ||
|
||
|
||
# | ||
# Sources | ||
# | ||
|
||
set(sources | ||
main.cpp | ||
) | ||
|
||
|
||
# | ||
# Create executable | ||
# | ||
|
||
# Build executable | ||
add_executable(${target} | ||
MACOSX_BUNDLE | ||
${sources} | ||
) | ||
|
||
# Create namespaced alias | ||
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) | ||
|
||
|
||
# | ||
# Project options | ||
# | ||
|
||
set_target_properties(${target} | ||
PROPERTIES | ||
${DEFAULT_PROJECT_OPTIONS} | ||
INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}" | ||
FOLDER "${IDE_FOLDER}" | ||
) | ||
|
||
|
||
# | ||
# Include directories | ||
# | ||
|
||
target_include_directories(${target} | ||
PRIVATE | ||
${DEFAULT_INCLUDE_DIRECTORIES} | ||
${PROJECT_BINARY_DIR}/source/include | ||
SYSTEM | ||
) | ||
|
||
|
||
# | ||
# Libraries | ||
# | ||
|
||
target_link_libraries(${target} | ||
PRIVATE | ||
${DEFAULT_LIBRARIES} | ||
glfw | ||
${META_PROJECT_NAME}::glbinding | ||
${META_PROJECT_NAME}::glbinding-aux | ||
${META_PROJECT_NAME}::cubescape-shared-gles | ||
) | ||
|
||
|
||
# | ||
# Compile definitions | ||
# | ||
|
||
target_compile_definitions(${target} | ||
PRIVATE | ||
${DEFAULT_COMPILE_DEFINITIONS} | ||
GLFW_INCLUDE_NONE | ||
) | ||
|
||
|
||
# | ||
# Compile options | ||
# | ||
|
||
target_compile_options(${target} | ||
PRIVATE | ||
${DEFAULT_COMPILE_OPTIONS_PRIVATE} | ||
PUBLIC | ||
${DEFAULT_COMPILE_OPTIONS_PUBLIC} | ||
) | ||
|
||
|
||
# | ||
# Linker options | ||
# | ||
|
||
target_link_libraries(${target} | ||
PRIVATE | ||
${DEFAULT_LINKER_OPTIONS} | ||
) | ||
|
||
|
||
# | ||
# Target Health | ||
# | ||
|
||
perform_health_checks( | ||
${target} | ||
${sources} | ||
) | ||
|
||
|
||
# | ||
# Deployment | ||
# | ||
|
||
# Executable | ||
install(TARGETS ${target} | ||
RUNTIME DESTINATION ${INSTALL_EXAMPLES} COMPONENT examples_glfw | ||
BUNDLE DESTINATION ${INSTALL_EXAMPLES} COMPONENT examples_glfw | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
|
||
#include <iostream> | ||
|
||
#include <GLFW/glfw3.h> | ||
|
||
#include <glbinding/glbinding.h> | ||
#include <glbinding/Version.h> | ||
#include <glbinding/FunctionCall.h> | ||
#include <glbinding/CallbackMask.h> | ||
|
||
#include <glbinding/gl/gl.h> | ||
#include <glbinding/getProcAddress.h> | ||
|
||
#include <glbinding-aux/ContextInfo.h> | ||
#include <glbinding-aux/Meta.h> | ||
#include <glbinding-aux/types_to_string.h> | ||
#include <glbinding-aux/ValidVersions.h> | ||
#include <glbinding-aux/debug.h> | ||
|
||
#include <CubeScape.h> | ||
|
||
|
||
using namespace gl; | ||
using namespace glbinding; | ||
|
||
|
||
namespace | ||
{ | ||
CubeScape * cubescape(nullptr); | ||
} | ||
|
||
|
||
void error(int errnum, const char * errmsg) | ||
{ | ||
std::cerr << errnum << ": " << errmsg << std::endl; | ||
} | ||
|
||
|
||
void framebuffer_size_callback(GLFWwindow * /*window*/, int width, int height) | ||
{ | ||
cubescape->resize(width, height); | ||
} | ||
|
||
void key_callback(GLFWwindow * window, int key, int /*scancode*/, int action, int /*mods*/) | ||
{ | ||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) | ||
glfwSetWindowShouldClose(window, 1); | ||
|
||
bool numCubesChanged = false; | ||
|
||
if (key == GLFW_KEY_I && (action == GLFW_PRESS || action == GLFW_REPEAT)) | ||
{ | ||
cubescape->setNumCubes(cubescape->numCubes() + 1); | ||
numCubesChanged = true; | ||
} | ||
|
||
if (key == GLFW_KEY_D && (action == GLFW_PRESS || action == GLFW_REPEAT)) | ||
{ | ||
cubescape->setNumCubes(cubescape->numCubes() - 1); | ||
numCubesChanged = true; | ||
} | ||
|
||
if (numCubesChanged) | ||
{ | ||
const int n = cubescape->numCubes(); | ||
std::cout << "#cubes = " << n << " * " << n << " = " << n * n << std::endl; | ||
} | ||
} | ||
|
||
|
||
int main(int, char *[]) | ||
{ | ||
glfwSetErrorCallback(error); | ||
|
||
if (!glfwInit()) | ||
return 1; | ||
|
||
glfwDefaultWindowHints(); | ||
|
||
// #ifdef SYSTEM_DARWIN | ||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); | ||
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); | ||
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | ||
// #endif | ||
|
||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); | ||
|
||
GLFWwindow * window = glfwCreateWindow(640, 480, "", nullptr, nullptr); | ||
if (!window) | ||
{ | ||
glfwTerminate(); | ||
return -1; | ||
} | ||
|
||
glfwSetKeyCallback(window, key_callback); | ||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); | ||
|
||
glfwMakeContextCurrent(window); | ||
|
||
glbinding::initialize(glfwGetProcAddress, false); // only resolve functions that are actually used (lazy) | ||
glbinding::aux::enableGetErrorCallback(); | ||
|
||
// print some gl infos (query) | ||
|
||
std::cout << std::endl | ||
<< "OpenGL ES Version: " << aux::ContextInfo::version() << std::endl | ||
<< "OpenGL ES Vendor: " << aux::ContextInfo::vendor() << std::endl | ||
<< "OpenGL ES Renderer: " << aux::ContextInfo::renderer() << std::endl; | ||
|
||
std::cout << std::endl | ||
<< "Press i or d to either increase or decrease number of cubes." << std::endl << std::endl; | ||
|
||
|
||
cubescape = new CubeScape(); | ||
|
||
int width, height; glfwGetFramebufferSize(window, &width, &height); | ||
cubescape->resize(width, height); | ||
|
||
while (!glfwWindowShouldClose(window)) | ||
{ | ||
glfwPollEvents(); | ||
cubescape->draw(); | ||
glfwSwapBuffers(window); | ||
} | ||
|
||
delete cubescape; | ||
cubescape = nullptr; | ||
|
||
glfwTerminate(); | ||
return 0; | ||
} |
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
File renamed without changes.
Oops, something went wrong.