Skip to content

Commit 57f0d96

Browse files
committed
revise examples
1 parent 28a6365 commit 57f0d96

File tree

9 files changed

+141
-152
lines changed

9 files changed

+141
-152
lines changed

source/examples/computeshader/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ int main()
172172
globjects::info() << "Press F5 to reload compute shader." << std::endl << std::endl;
173173

174174

175-
initialize();
176175
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
176+
initialize();
177177

178178
// Main loop
179179
while (!glfwWindowShouldClose(window))

source/examples/programpipelines/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ int main(int /*argc*/, char * /*argv*/[])
170170
<< "OpenGL Vendor: " << glbinding::ContextInfo::vendor() << std::endl
171171
<< "OpenGL Renderer: " << glbinding::ContextInfo::renderer() << std::endl << std::endl;
172172

173-
initialize();
174173
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
174+
initialize();
175175

176176
// Main loop
177177
while (!glfwWindowShouldClose(window))

source/examples/shaderincludes/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ int main(int /*argc*/, char * /*argv*/[])
119119
globjects::info() << "Press F5 to reload shaders." << std::endl << std::endl;
120120

121121

122-
initialize();
123122
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
123+
initialize();
124124

125125
// Main loop
126126
while (!glfwWindowShouldClose(window))

source/examples/sparsetexture/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ int main(int /*argc*/, char * /*argv*/[])
207207
<< "OpenGL Vendor: " << glbinding::ContextInfo::vendor() << std::endl
208208
<< "OpenGL Renderer: " << glbinding::ContextInfo::renderer() << std::endl << std::endl;
209209

210-
initialize();
211210
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
211+
initialize();
212212

213213
// Main loop
214214
while (!glfwWindowShouldClose(window))

source/examples/ssbo/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ int main(int /*argc*/, char * /*argv*/[])
141141
globjects::info() << "Press F5 to reload shaders." << std::endl << std::endl;
142142

143143

144-
initialize();
145144
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
145+
initialize();
146146

147147
// Main loop
148148
while (!glfwWindowShouldClose(window))

source/examples/states/main.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929

3030
using namespace gl;
31-
using namespace glm;
3231

3332

3433
namespace
@@ -86,20 +85,17 @@ void initialize()
8685
globjects::Shader::fromFile(GL_VERTEX_SHADER, dataPath + "states/standard.vert")
8786
, globjects::Shader::fromFile(GL_FRAGMENT_SHADER, dataPath + "states/standard.frag"));
8887

89-
g_buffer->setData(std::vector<vec2>({
90-
vec2(-0.8f, 0.8f), vec2(-0.4f, 0.8f), vec2( 0.0f, 0.8f), vec2( 0.4f, 0.8f), vec2( 0.8f, 0.8f)
91-
, vec2(-0.8f, 0.6f), vec2(-0.4f, 0.6f), vec2( 0.0f, 0.6f), vec2( 0.4f, 0.6f), vec2( 0.8f, 0.6f)
92-
, vec2(-0.8f, 0.4f), vec2(-0.4f, 0.4f), vec2( 0.0f, 0.4f), vec2( 0.4f, 0.4f), vec2( 0.8f, 0.4f)
93-
, vec2(-0.8f, 0.2f), vec2(-0.4f, 0.2f), vec2( 0.0f, 0.2f), vec2( 0.4f, 0.2f), vec2( 0.8f, 0.2f)
94-
, vec2(-0.8f, 0.0f), vec2(-0.4f, 0.0f), vec2( 0.0f, 0.0f), vec2( 0.4f, 0.0f), vec2( 0.8f, 0.0f)
95-
, vec2(-0.8f,-0.2f), vec2(-0.4f,-0.2f), vec2( 0.0f,-0.2f), vec2( 0.4f,-0.2f), vec2( 0.8f,-0.2f)
96-
, vec2(-0.8f,-0.4f), vec2(-0.4f,-0.4f), vec2( 0.0f,-0.4f), vec2( 0.4f,-0.4f), vec2( 0.8f,-0.4f)
97-
, vec2(-0.8f,-0.6f), vec2(-0.4f,-0.6f), vec2( 0.0f,-0.6f), vec2( 0.4f,-0.6f), vec2( 0.8f,-0.6f)
98-
, vec2(-0.8f,-0.8f), vec2(-0.4f,-0.8f), vec2( 0.0f,-0.8f), vec2( 0.4f,-0.8f), vec2( 0.8f,-0.8f) })
99-
, GL_STATIC_DRAW );
88+
static auto data = std::vector<glm::vec2>();
89+
if (data.empty())
90+
{
91+
for (auto y = 0.8f; y > -1.f; y -= 0.2f)
92+
for (auto x = -0.8f; x < 1.f; x += 0.4f)
93+
data.push_back(glm::vec2(x, y));
94+
}
95+
g_buffer->setData(data, GL_STATIC_DRAW );
10096

10197
g_vao->binding(0)->setAttribute(0);
102-
g_vao->binding(0)->setBuffer(g_buffer, 0, sizeof(vec2));
98+
g_vao->binding(0)->setBuffer(g_buffer, 0, sizeof(glm::vec2));
10399
g_vao->binding(0)->setFormat(2, GL_FLOAT);
104100
g_vao->enable(0);
105101
}
@@ -203,7 +199,7 @@ int main(int /*argc*/, char * /*argv*/[])
203199
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
204200

205201
// Create a context and, if valid, make it current
206-
GLFWwindow * window = glfwCreateWindow(320, 240, "globjects States", NULL, NULL);
202+
GLFWwindow * window = glfwCreateWindow(640, 480, "globjects States", NULL, NULL);
207203
if (window == nullptr)
208204
{
209205
globjects::critical() << "Context creation failed. Terminate execution.";
@@ -227,8 +223,8 @@ int main(int /*argc*/, char * /*argv*/[])
227223
globjects::info() << "Press F5 to reload shaders." << std::endl << std::endl;
228224

229225

230-
initialize();
231226
glfwGetFramebufferSize(window, &g_size[0], &g_size[1]);
227+
initialize();
232228

233229
// Main loop
234230
while (!glfwWindowShouldClose(window))

source/examples/tessellation/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ message(STATUS "Example ${target}")
2929

3030
set(sources
3131
main.cpp
32+
3233
Icosahedron.h
3334
Icosahedron.cpp
35+
datapath.inl
3436
)
3537

3638

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
#include <string>
3+
4+
#include <cpplocate/cpplocate.h>
5+
#include <cpplocate/ModuleInfo.h>
6+
7+
8+
namespace common
9+
{
10+
11+
std::string normalizePath(const std::string & filepath)
12+
{
13+
auto copy = filepath;
14+
std::replace(copy.begin(), copy.end(), '\\', '/');
15+
16+
auto i = copy.find_last_of('/');
17+
if (i == copy.size() - 1)
18+
copy = copy.substr(0, copy.size() - 1);
19+
20+
return copy;
21+
}
22+
23+
std::string retrieveDataPath(const std::string & module, const std::string & key)
24+
{
25+
const auto moduleInfo = cpplocate::findModule(module);
26+
27+
auto dataPath = moduleInfo.value(key);
28+
dataPath = normalizePath(dataPath);
29+
30+
if (dataPath.empty())
31+
dataPath = "data/";
32+
else
33+
dataPath += "/";
34+
35+
return dataPath;
36+
}
37+
38+
}

0 commit comments

Comments
 (0)