Skip to content

Commit a4ada9a

Browse files
committed
Complement OpenGL ES examples for different windowing toolkits
1 parent 9e764ff commit a4ada9a

File tree

43 files changed

+2587
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2587
-65
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ auto shader = glCreateShader(GL_COMPUTE_SHADER);
3636

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

39-
* [GLFW](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-glfw)
40-
* [GTK 3](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk3)
41-
* [GTK 4](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-gtk4)
42-
* [Qt 5](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-qt)
43-
* [SDL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-sdl)
39+
* [GLFW OpenGL](https://github.com/cginternals/glbinding/tree/master/source/examples/cubescape-glfw-gl)
40+
* [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)
41+
* [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)
42+
* [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)
43+
* [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)
4444

4545
# Resources
4646

source/examples/CMakeLists.txt

+15-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
# Examples
44
#
55

6-
# General Features
7-
add_subdirectory("callbacks")
8-
add_subdirectory("comparison")
9-
add_subdirectory("multi-context")
10-
116
#
127
# Cubescape
138
#
@@ -21,10 +16,20 @@ add_subdirectory("cubescape-gl")
2116
add_subdirectory("cubescape-gles")
2217

2318
# Integrations
24-
add_subdirectory("cubescape-glfw")
19+
add_subdirectory("cubescape-glfw-gl")
20+
add_subdirectory("cubescape-glfw-gles")
21+
add_subdirectory("cubescape-qt-gl")
22+
add_subdirectory("cubescape-qt-gles")
23+
add_subdirectory("cubescape-sdl-gl")
24+
add_subdirectory("cubescape-sdl-gles")
25+
add_subdirectory("cubescape-gtk3-gl")
26+
add_subdirectory("cubescape-gtk3-gles")
27+
add_subdirectory("cubescape-gtk4-gl")
28+
add_subdirectory("cubescape-gtk4-gles")
2529
add_subdirectory("cubescape-wgl")
26-
add_subdirectory("cubescape-qt")
27-
add_subdirectory("cubescape-sdl")
28-
add_subdirectory("cubescape-gtk3")
29-
add_subdirectory("cubescape-gtk4")
30+
31+
# General Features
32+
add_subdirectory("callbacks")
33+
add_subdirectory("comparison")
34+
add_subdirectory("multi-context")
3035
add_subdirectory("cubescape-log")

source/examples/cubescape-gl/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(target cubescape-gl)
1717
if (NOT glfw3_FOUND)
1818
message("Example ${target} skipped: glfw3 not found")
1919
return()
20+
else()
21+
message(STATUS "Example ${target}")
2022
endif()
2123

2224

source/examples/cubescape-gles/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(target cubescape-gles)
1717
if (NOT glfw3_FOUND)
1818
message("Example ${target} skipped: glfw3 not found")
1919
return()
20+
else()
21+
message(STATUS "Example ${target}")
2022
endif()
2123

2224

source/examples/cubescape-glfw/CMakeLists.txt source/examples/cubescape-glfw-gl/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ find_package(glfw3 QUIET)
1111
#
1212

1313
# Target name
14-
set(target cubescape-glfw)
14+
set(target cubescape-glfw-gl)
1515

1616
# Exit here if required dependencies are not met
1717
if (NOT glfw3_FOUND)
1818
message("Example ${target} skipped: glfw3 not found")
1919
return()
20+
else()
21+
message(STATUS "Example ${target}")
2022
endif()
2123

2224

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
2+
#
3+
# External dependencies
4+
#
5+
6+
find_package(glfw3 QUIET)
7+
8+
9+
#
10+
# Executable name and options
11+
#
12+
13+
# Target name
14+
set(target cubescape-glfw-gles)
15+
16+
# Exit here if required dependencies are not met
17+
if (NOT glfw3_FOUND)
18+
message("Example ${target} skipped: glfw3 not found")
19+
return()
20+
else()
21+
message(STATUS "Example ${target}")
22+
endif()
23+
24+
25+
#
26+
# Sources
27+
#
28+
29+
set(sources
30+
main.cpp
31+
)
32+
33+
34+
#
35+
# Create executable
36+
#
37+
38+
# Build executable
39+
add_executable(${target}
40+
MACOSX_BUNDLE
41+
${sources}
42+
)
43+
44+
# Create namespaced alias
45+
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})
46+
47+
48+
#
49+
# Project options
50+
#
51+
52+
set_target_properties(${target}
53+
PROPERTIES
54+
${DEFAULT_PROJECT_OPTIONS}
55+
INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}"
56+
FOLDER "${IDE_FOLDER}"
57+
)
58+
59+
60+
#
61+
# Include directories
62+
#
63+
64+
target_include_directories(${target}
65+
PRIVATE
66+
${DEFAULT_INCLUDE_DIRECTORIES}
67+
${PROJECT_BINARY_DIR}/source/include
68+
SYSTEM
69+
)
70+
71+
72+
#
73+
# Libraries
74+
#
75+
76+
target_link_libraries(${target}
77+
PRIVATE
78+
${DEFAULT_LIBRARIES}
79+
glfw
80+
${META_PROJECT_NAME}::glbinding
81+
${META_PROJECT_NAME}::glbinding-aux
82+
${META_PROJECT_NAME}::cubescape-shared-gles
83+
)
84+
85+
86+
#
87+
# Compile definitions
88+
#
89+
90+
target_compile_definitions(${target}
91+
PRIVATE
92+
${DEFAULT_COMPILE_DEFINITIONS}
93+
GLFW_INCLUDE_NONE
94+
)
95+
96+
97+
#
98+
# Compile options
99+
#
100+
101+
target_compile_options(${target}
102+
PRIVATE
103+
${DEFAULT_COMPILE_OPTIONS_PRIVATE}
104+
PUBLIC
105+
${DEFAULT_COMPILE_OPTIONS_PUBLIC}
106+
)
107+
108+
109+
#
110+
# Linker options
111+
#
112+
113+
target_link_libraries(${target}
114+
PRIVATE
115+
${DEFAULT_LINKER_OPTIONS}
116+
)
117+
118+
119+
#
120+
# Target Health
121+
#
122+
123+
perform_health_checks(
124+
${target}
125+
${sources}
126+
)
127+
128+
129+
#
130+
# Deployment
131+
#
132+
133+
# Executable
134+
install(TARGETS ${target}
135+
RUNTIME DESTINATION ${INSTALL_EXAMPLES} COMPONENT examples_glfw
136+
BUNDLE DESTINATION ${INSTALL_EXAMPLES} COMPONENT examples_glfw
137+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
#include <iostream>
3+
4+
#include <GLFW/glfw3.h>
5+
6+
#include <glbinding/glbinding.h>
7+
#include <glbinding/Version.h>
8+
#include <glbinding/FunctionCall.h>
9+
#include <glbinding/CallbackMask.h>
10+
11+
#include <glbinding/gl/gl.h>
12+
#include <glbinding/getProcAddress.h>
13+
14+
#include <glbinding-aux/ContextInfo.h>
15+
#include <glbinding-aux/Meta.h>
16+
#include <glbinding-aux/types_to_string.h>
17+
#include <glbinding-aux/ValidVersions.h>
18+
#include <glbinding-aux/debug.h>
19+
20+
#include <CubeScape.h>
21+
22+
23+
using namespace gl;
24+
using namespace glbinding;
25+
26+
27+
namespace
28+
{
29+
CubeScape * cubescape(nullptr);
30+
}
31+
32+
33+
void error(int errnum, const char * errmsg)
34+
{
35+
std::cerr << errnum << ": " << errmsg << std::endl;
36+
}
37+
38+
39+
void framebuffer_size_callback(GLFWwindow * /*window*/, int width, int height)
40+
{
41+
cubescape->resize(width, height);
42+
}
43+
44+
void key_callback(GLFWwindow * window, int key, int /*scancode*/, int action, int /*mods*/)
45+
{
46+
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
47+
glfwSetWindowShouldClose(window, 1);
48+
49+
bool numCubesChanged = false;
50+
51+
if (key == GLFW_KEY_I && (action == GLFW_PRESS || action == GLFW_REPEAT))
52+
{
53+
cubescape->setNumCubes(cubescape->numCubes() + 1);
54+
numCubesChanged = true;
55+
}
56+
57+
if (key == GLFW_KEY_D && (action == GLFW_PRESS || action == GLFW_REPEAT))
58+
{
59+
cubescape->setNumCubes(cubescape->numCubes() - 1);
60+
numCubesChanged = true;
61+
}
62+
63+
if (numCubesChanged)
64+
{
65+
const int n = cubescape->numCubes();
66+
std::cout << "#cubes = " << n << " * " << n << " = " << n * n << std::endl;
67+
}
68+
}
69+
70+
71+
int main(int, char *[])
72+
{
73+
glfwSetErrorCallback(error);
74+
75+
if (!glfwInit())
76+
return 1;
77+
78+
glfwDefaultWindowHints();
79+
80+
// #ifdef SYSTEM_DARWIN
81+
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
82+
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
83+
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
84+
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
85+
// #endif
86+
87+
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
88+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
89+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
90+
91+
GLFWwindow * window = glfwCreateWindow(640, 480, "", nullptr, nullptr);
92+
if (!window)
93+
{
94+
glfwTerminate();
95+
return -1;
96+
}
97+
98+
glfwSetKeyCallback(window, key_callback);
99+
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
100+
101+
glfwMakeContextCurrent(window);
102+
103+
glbinding::initialize(glfwGetProcAddress, false); // only resolve functions that are actually used (lazy)
104+
glbinding::aux::enableGetErrorCallback();
105+
106+
// print some gl infos (query)
107+
108+
std::cout << std::endl
109+
<< "OpenGL ES Version: " << aux::ContextInfo::version() << std::endl
110+
<< "OpenGL ES Vendor: " << aux::ContextInfo::vendor() << std::endl
111+
<< "OpenGL ES Renderer: " << aux::ContextInfo::renderer() << std::endl;
112+
113+
std::cout << std::endl
114+
<< "Press i or d to either increase or decrease number of cubes." << std::endl << std::endl;
115+
116+
117+
cubescape = new CubeScape();
118+
119+
int width, height; glfwGetFramebufferSize(window, &width, &height);
120+
cubescape->resize(width, height);
121+
122+
while (!glfwWindowShouldClose(window))
123+
{
124+
glfwPollEvents();
125+
cubescape->draw();
126+
glfwSwapBuffers(window);
127+
}
128+
129+
delete cubescape;
130+
cubescape = nullptr;
131+
132+
glfwTerminate();
133+
return 0;
134+
}

source/examples/cubescape-gtk3/CMakeLists.txt source/examples/cubescape-gtk3-gl/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ find_package(GTK3 QUIET)
1111
#
1212

1313
# Target name
14-
set(target cubescape-gtk3)
14+
set(target cubescape-gtk3-gl)
1515

1616
# Exit here if required dependencies are not met
1717
if (NOT TARGET GTK3::GTK3)
1818
message("Example ${target} skipped: GTK 3 not found")
1919
return()
20+
else()
21+
message(STATUS "Example ${target}")
2022
endif()
2123

2224

0 commit comments

Comments
 (0)