Skip to content

Commit

Permalink
Complement OpenGL ES examples for different windowing toolkits
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibel committed Feb 26, 2024
1 parent 9e764ff commit a4ada9a
Show file tree
Hide file tree
Showing 43 changed files with 2,587 additions and 65 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ auto shader = glCreateShader(GL_COMPUTE_SHADER);

*glbinding* is compatible with OpenGL-compatible windowing toolkits and we provide example integrations for the following ones within the examples:

* [GLFW](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-glfw)
* [GTK 3](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk3)
* [GTK 4](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk4)
* [Qt 5](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-qt)
* [SDL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-sdl)
* [GLFW OpenGL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-glfw-gl)
* [GTK 3 OpenGL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk3-gl) and [GTK 3 OpenGL ES](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk3-gles) (may require `GDK_GL=gles` environment variable)
* [GTK 4 OpenGL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk4-gl) and [GTK 4 OpenGL ES](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk3-gles)
* [Qt 5 OpenGL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-qt-gl) and [Qt 5 OpenGL ES](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-qt-gles)
* [SDL OpenGL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-sdl-gl) and [SDL OpenGL ES](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-sdl-gles)

# Resources

Expand Down
25 changes: 15 additions & 10 deletions source/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# Examples
#

# General Features
add_subdirectory("callbacks")
add_subdirectory("comparison")
add_subdirectory("multi-context")

#
# Cubescape
#
Expand All @@ -21,10 +16,20 @@ add_subdirectory("cubescape-gl")
add_subdirectory("cubescape-gles")

# Integrations
add_subdirectory("cubescape-glfw")
add_subdirectory("cubescape-glfw-gl")
add_subdirectory("cubescape-glfw-gles")
add_subdirectory("cubescape-qt-gl")
add_subdirectory("cubescape-qt-gles")
add_subdirectory("cubescape-sdl-gl")
add_subdirectory("cubescape-sdl-gles")
add_subdirectory("cubescape-gtk3-gl")
add_subdirectory("cubescape-gtk3-gles")
add_subdirectory("cubescape-gtk4-gl")
add_subdirectory("cubescape-gtk4-gles")
add_subdirectory("cubescape-wgl")
add_subdirectory("cubescape-qt")
add_subdirectory("cubescape-sdl")
add_subdirectory("cubescape-gtk3")
add_subdirectory("cubescape-gtk4")

# General Features
add_subdirectory("callbacks")
add_subdirectory("comparison")
add_subdirectory("multi-context")
add_subdirectory("cubescape-log")
2 changes: 2 additions & 0 deletions source/examples/cubescape-gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(target cubescape-gl)
if (NOT glfw3_FOUND)
message("Example ${target} skipped: glfw3 not found")
return()
else()
message(STATUS "Example ${target}")
endif()


Expand Down
2 changes: 2 additions & 0 deletions source/examples/cubescape-gles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(target cubescape-gles)
if (NOT glfw3_FOUND)
message("Example ${target} skipped: glfw3 not found")
return()
else()
message(STATUS "Example ${target}")
endif()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ find_package(glfw3 QUIET)
#

# Target name
set(target cubescape-glfw)
set(target cubescape-glfw-gl)

# 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()


Expand Down
File renamed without changes.
137 changes: 137 additions & 0 deletions source/examples/cubescape-glfw-gles/CMakeLists.txt
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
)
134 changes: 134 additions & 0 deletions source/examples/cubescape-glfw-gles/main.cpp
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ find_package(GTK3 QUIET)
#

# Target name
set(target cubescape-gtk3)
set(target cubescape-gtk3-gl)

# Exit here if required dependencies are not met
if (NOT TARGET GTK3::GTK3)
message("Example ${target} skipped: GTK 3 not found")
return()
else()
message(STATUS "Example ${target}")
endif()


Expand Down
File renamed without changes.
Loading

0 comments on commit a4ada9a

Please sign in to comment.