Skip to content

Commit 8fda48e

Browse files
committed
Towards refactored shader include example
1 parent 24a3c7e commit 8fda48e

File tree

4 files changed

+65
-23
lines changed

4 files changed

+65
-23
lines changed

source/examples/shaderincludes/CMakeLists.txt

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

3030
set(sources
3131
main.cpp
32+
3233
ScreenAlignedQuad.h
3334
ScreenAlignedQuad.cpp
35+
contextinfo.inl
36+
datapath.inl
3437
)
3538

3639

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#include <iostream>
3+
4+
5+
namespace common
6+
{
7+
8+
void printContextInfo()
9+
{
10+
std::cout << std::endl
11+
<< "OpenGL Version: " << glbinding::ContextInfo::version() << std::endl
12+
<< "OpenGL Vendor: " << glbinding::ContextInfo::vendor() << std::endl
13+
<< "OpenGL Renderer: " << glbinding::ContextInfo::renderer() << std::endl << std::endl;
14+
}
15+
16+
}
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+
}

source/examples/shaderincludes/main.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,15 @@
1818

1919
#include "ScreenAlignedQuad.h"
2020

21+
// example commons
22+
#include "contextinfo.inl"
23+
#include "datapath.inl"
24+
2125

2226
using namespace gl;
2327
using namespace globjects;
2428

2529

26-
namespace
27-
{
28-
29-
// taken from iozeug::FilePath::toPath
30-
std::string normalizePath(const std::string & filepath)
31-
{
32-
auto copy = filepath;
33-
std::replace( copy.begin(), copy.end(), '\\', '/');
34-
auto i = copy.find_last_of('/');
35-
if (i == copy.size()-1)
36-
{
37-
copy = copy.substr(0, copy.size()-1);
38-
}
39-
return copy;
40-
}
41-
42-
}
43-
44-
4530
namespace
4631
{
4732

@@ -74,10 +59,10 @@ GLFWwindow * createWindow(bool fs = false)
7459
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
7560

7661
// Create a context and, if valid, make it current
77-
GLFWwindow * window = glfwCreateWindow(1024, 768, "", fs ? glfwGetPrimaryMonitor() : NULL, NULL);
62+
GLFWwindow * window = glfwCreateWindow(640, 480, "globjects Shader Includes Shader", fs ? glfwGetPrimaryMonitor() : NULL, NULL);
7863
if (window == nullptr)
7964
{
80-
critical() << "Context creation failed. Terminate execution.";
65+
globjects::critical() << "Context creation failed. Terminate execution.";
8166

8267
glfwTerminate();
8368
exit(1);
@@ -98,7 +83,7 @@ GLFWwindow * createWindow(bool fs = false)
9883
<< "OpenGL Version: " << glbinding::ContextInfo::version() << std::endl
9984
<< "OpenGL Vendor: " << glbinding::ContextInfo::vendor() << std::endl
10085
<< "OpenGL Renderer: " << glbinding::ContextInfo::renderer() << std::endl;
101-
}
86+
}
10287

10388
glClearColor(0.2f, 0.3f, 0.4f, 1.f);
10489

@@ -118,7 +103,7 @@ void initialize()
118103

119104
// Get data path
120105
std::string dataPath = moduleInfo.value("dataPath");
121-
dataPath = normalizePath(dataPath);
106+
dataPath = common::normalizePath(dataPath);
122107
if (dataPath.size() > 0) dataPath = dataPath + "/";
123108
else dataPath = "data/";
124109

0 commit comments

Comments
 (0)