Skip to content

Commit 5b35a34

Browse files
committed
Merge branch 'master' of github.com:cginternals/globjects
2 parents 0fecc3c + 5319aa2 commit 5b35a34

File tree

3 files changed

+58
-89
lines changed

3 files changed

+58
-89
lines changed

source/examples/programpipelines/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include <glm/glm.hpp>
2+
#include <glm/vec2.hpp>
33

44
#include <glbinding/gl/gl.h>
55
#include <glbinding/ContextInfo.h>
@@ -169,7 +169,7 @@ int main(int /*argc*/, char * /*argv*/[])
169169
globjects::init();
170170
common::printContextInfo();
171171

172-
globjects::info() << "Press F5 to reload compute shader." << std::endl << std::endl;
172+
globjects::info() << "Press F5 to reload shaders." << std::endl << std::endl;
173173

174174

175175
initialize();

source/examples/qtexample/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int main(int argc, char * argv[])
149149
Window * glwindow = new Window(format);
150150

151151
QMainWindow window;
152-
window.setMinimumSize(320, 240);
152+
window.setMinimumSize(640, 480);
153153
window.setWindowTitle("globjects and Qt");
154154
window.setCentralWidget(QWidget::createWindowContainer(glwindow));
155155

source/examples/shaderincludes/main.cpp

Lines changed: 55 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <glbinding/ContextInfo.h>
99
#include <glbinding/Version.h>
1010

11+
#include <glm/vec2.hpp>
12+
1113
#include <GLFW/glfw3.h>
1214

1315
#include <globjects/globjects.h>
@@ -24,139 +26,106 @@
2426

2527

2628
using namespace gl;
27-
using namespace globjects;
2829

2930

3031
namespace
3132
{
3233

33-
bool g_toggleFS = false;
34-
bool g_isFS = false;
34+
ScreenAlignedQuad * g_quad = nullptr;
35+
36+
auto g_size = glm::ivec2{};
37+
}
3538

36-
ScreenAlignedQuad * g_quad = nullptr;
3739

40+
void initialize()
41+
{
42+
const auto dataPath = common::retrieveDataPath("globjects", "dataPath");
43+
globjects::NamedString::create("/color.glsl", new globjects::File(dataPath + "shaderincludes/color.glsl"));
44+
45+
g_quad = new ScreenAlignedQuad(globjects::Shader::fromFile(GL_FRAGMENT_SHADER, dataPath + "shaderincludes/test.frag"));
46+
g_quad->ref();
3847
}
3948

49+
void deinitialize()
50+
{
51+
g_quad->unref();
52+
53+
globjects::detachAllObjects();
54+
}
55+
56+
void draw()
57+
{
58+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
59+
g_quad->draw();
60+
}
61+
62+
63+
void error(int errnum, const char * errmsg)
64+
{
65+
globjects::critical() << errnum << ": " << errmsg << std::endl;
66+
}
67+
68+
void framebuffer_size_callback(GLFWwindow * /*window*/, int width, int height)
69+
{
70+
g_size = glm::ivec2{ width, height };
71+
}
4072

4173
void key_callback(GLFWwindow * window, int key, int /*scancode*/, int action, int /*modes*/)
4274
{
4375
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
4476
glfwSetWindowShouldClose(window, true);
45-
46-
if (key == GLFW_KEY_F5 && action == GLFW_RELEASE)
47-
File::reloadAll();
48-
49-
if (key == GLFW_KEY_F11 && action == GLFW_RELEASE)
50-
g_toggleFS = true;
5177
}
5278

53-
GLFWwindow * createWindow(bool fs = false)
79+
80+
int main(int /*argc*/, char * /*argv*/[])
5481
{
55-
// Set GLFW window hints
56-
glfwSetErrorCallback( [] (int /*error*/, const char * description) { puts(description); } );
82+
// Initialize GLFW
83+
if (!glfwInit())
84+
return 1;
85+
86+
glfwSetErrorCallback(error);
87+
glfwDefaultWindowHints();
88+
89+
glfwSetErrorCallback([](int /*error*/, const char * description) { puts(description); });
5790
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
5891
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
5992
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
6093

6194
// Create a context and, if valid, make it current
62-
GLFWwindow * window = glfwCreateWindow(640, 480, "globjects Shader Includes Shader", fs ? glfwGetPrimaryMonitor() : NULL, NULL);
95+
GLFWwindow * window = glfwCreateWindow(320, 240, "globjects Shader Includes", NULL, NULL);
6396
if (window == nullptr)
6497
{
6598
globjects::critical() << "Context creation failed. Terminate execution.";
6699

67100
glfwTerminate();
68-
exit(1);
101+
return -1;
69102
}
70-
glfwMakeContextCurrent(window);
71-
72-
// Create callback that when user presses ESC, the context should be destroyed and window closed
73103
glfwSetKeyCallback(window, key_callback);
104+
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
105+
106+
glfwMakeContextCurrent(window);
74107

75108
// Initialize globjects (internally initializes glbinding, and registers the current context)
76109
globjects::init();
110+
common::printContextInfo();
77111

78-
// Do only on startup
79-
if (!g_toggleFS)
80-
{
81-
// Dump information about context and graphics card
82-
info() << std::endl
83-
<< "OpenGL Version: " << glbinding::ContextInfo::version() << std::endl
84-
<< "OpenGL Vendor: " << glbinding::ContextInfo::vendor() << std::endl
85-
<< "OpenGL Renderer: " << glbinding::ContextInfo::renderer() << std::endl;
86-
}
87-
88-
glClearColor(0.2f, 0.3f, 0.4f, 1.f);
89-
90-
g_isFS = fs;
91-
return window;
92-
}
112+
globjects::info() << "Press F5 to reload shaders." << std::endl << std::endl;
93113

94-
void destroyWindow(GLFWwindow * window)
95-
{
96-
globjects::detachAllObjects();
97-
glfwDestroyWindow(window);
98-
}
99114

100-
void initialize()
101-
{
102-
cpplocate::ModuleInfo moduleInfo = cpplocate::findModule("globjects");
103-
104-
// Get data path
105-
std::string dataPath = moduleInfo.value("dataPath");
106-
dataPath = common::normalizePath(dataPath);
107-
if (dataPath.size() > 0) dataPath = dataPath + "/";
108-
else dataPath = "data/";
109-
110-
// Initialize OpenGL objects
111-
NamedString::create("/color.glsl", new File(dataPath + "shaderincludes/color.glsl"));
112-
113-
g_quad = new ScreenAlignedQuad(Shader::fromFile(GL_FRAGMENT_SHADER, dataPath + "shaderincludes/test.frag"));
114-
g_quad->ref();
115-
}
116-
117-
void deinitialize()
118-
{
119-
g_quad->unref();
120-
}
121-
122-
void draw()
123-
{
124-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
125-
g_quad->draw();
126-
}
127-
128-
129-
int main(int /*argc*/, char * /*argv*/[])
130-
{
131-
// Initialize GLFW
132-
glfwInit();
133-
134-
GLFWwindow * window = createWindow();
135115
initialize();
116+
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
136117

137118
// Main loop
138119
while (!glfwWindowShouldClose(window))
139120
{
140121
glfwPollEvents();
141-
142-
if (g_toggleFS)
143-
{
144-
deinitialize();
145-
destroyWindow(window);
146-
window = createWindow(!g_isFS);
147-
initialize();
148-
149-
g_toggleFS = false;
150-
}
151-
152122
draw();
153123
glfwSwapBuffers(window);
154124
}
155-
156125
deinitialize();
157126

158127
// Properly shutdown GLFW
159128
glfwTerminate();
160129

161130
return 0;
162-
}
131+
}

0 commit comments

Comments
 (0)