Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[NOT READY] Basic text rendering #4

Merged
merged 52 commits into from
Mar 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f0b821d
add glyph atlas class
kkaefer Feb 4, 2014
f8a096a
use templated function to reduce code
kkaefer Mar 11, 2014
8171c7b
add empty classes for rendering glyphs
kkaefer Mar 11, 2014
9f1a537
fix binpack compile
kkaefer Mar 11, 2014
31d3c63
parse faces
kkaefer Mar 11, 2014
a37dced
parse label shaping
kkaefer Mar 11, 2014
1170782
add text buffer code
kkaefer Mar 11, 2014
a26ddf8
parse feature objects so that we can access all tags
kkaefer Mar 11, 2014
45c341b
use external library
kkaefer Mar 12, 2014
29e4ecb
add text styling
kkaefer Mar 12, 2014
ceb75b7
use feature_type to distinguish between geometry type and bucket type
kkaefer Mar 12, 2014
df56f9f
they return bool values
kkaefer Mar 12, 2014
d958957
extract label shaping
kkaefer Mar 12, 2014
be44b6b
add glyph atlas to map
kkaefer Mar 12, 2014
99cef81
move tile parsing to its own object
kkaefer Mar 12, 2014
3c5bac0
add debug window showing the glyph atlas
kkaefer Mar 14, 2014
56e06f5
remove unused glyphs from atlas again
kkaefer Mar 14, 2014
10c72f8
port rotationrange.js (still missing tests)
kkaefer Mar 14, 2014
168ee46
rename text shader file
kkaefer Mar 17, 2014
85449e0
add gtest
kkaefer Mar 17, 2014
e8db543
add rotation range tests
kkaefer Mar 17, 2014
88af0b8
add interpolate function
kkaefer Mar 17, 2014
1f2c71e
port of collision class
kkaefer Mar 17, 2014
bf6a600
format fixes
kkaefer Mar 17, 2014
bed8de2
force explicit types
kkaefer Mar 17, 2014
6c61fb7
missing braces
kkaefer Mar 17, 2014
25ff0b2
merge vec2 and Coordinate
kkaefer Mar 18, 2014
98bb797
explicit names
kkaefer Mar 18, 2014
4ee0cf1
port remainder of the the placement algorithm
kkaefer Mar 19, 2014
3413ee5
Merge branch 'master' into sdf
kkaefer Mar 21, 2014
a7b9b96
add textshader
kkaefer Mar 21, 2014
ea6b24d
add text rendering code
kkaefer Mar 21, 2014
af8c936
fix color parsing
kkaefer Mar 24, 2014
67a8882
use the correct glyphs
kkaefer Mar 24, 2014
3191273
update style
kkaefer Mar 24, 2014
5c613b5
normalizedZoom() == zoom level of the visual appearance
kkaefer Mar 24, 2014
c00ec64
exponential functions
kkaefer Mar 24, 2014
f9759d7
set correct strata
kkaefer Mar 24, 2014
1455291
parse text-specific style properties
kkaefer Mar 24, 2014
75cd64d
add toString method for Value variant
kkaefer Mar 24, 2014
541c626
update style.cpp
kkaefer Mar 24, 2014
84ea959
fix glyph debug image on retina
kkaefer Mar 24, 2014
8b573f9
fix glyphs that have no pixels but an advance (e.g. spaces)
kkaefer Mar 24, 2014
5c11bcf
don't treat negative values as placement failure
kkaefer Mar 24, 2014
76d3d7b
explicitly specify font size in class
kkaefer Mar 24, 2014
9621038
implement alwaysVisible
kkaefer Mar 24, 2014
b4a67a9
remove commented out js code
kkaefer Mar 24, 2014
afe27ed
only animate when we need to fade the text
kkaefer Mar 24, 2014
d5b4c11
add shader optimizer and reorder components
kkaefer Mar 25, 2014
3a9a904
reorder vertices
kkaefer Mar 25, 2014
25e2d85
debug changes
kkaefer Mar 25, 2014
713acbb
add package.json with reference to shader optimizer
kkaefer Mar 25, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/ios/build
/config.gypi
/config.mk
/build
/build
/node_modules
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ all: llmr
llmr: config.gypi src llmr.gyp
@if [ ! -f out ]; then echo 'please run ./configure first'; else $(MAKE) -C out BUILDTYPE=Release V=$(V) llmr-x86; fi;

gtest: config.gypi src llmr.gyp
deps/run_gyp llmr.gyp -Goutput_dir=./out/ --depth=. --generator-output=./build/gtest -f make
make -C build/gtest gtest V=$(V)

# build OS X app with pure make
app: config.gypi src macosx/llmr-app.gyp
deps/run_gyp macosx/llmr-app.gyp -Goutput_dir=./out/ --depth=. --generator-output=./build/macosx-make -f make
Expand Down Expand Up @@ -58,6 +62,13 @@ isim: config.gypi src ios/llmr-app.gyp
# does not work
#"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator" -SimulateApplication ios/build/Release-iphonesimulator/llmr.app/llmr

test: config.gypi src test/test.gyp
deps/run_gyp test/test.gyp -Goutput_dir=. --depth=. --generator-output=./build/test -f make
make -C build/test V=$(V)
@for FILE in build/test/Release/test_*; do \
$${FILE}; \
done

clean:
-rm -rf out
-rm -rf build
Expand All @@ -71,7 +82,4 @@ distclean:
-rm -rf macosx/llmr-app.xcodeproj
-rm -rf ios/llmr-app.xcodeproj

test: all
echo test

.PHONY: test linux
36 changes: 36 additions & 0 deletions bin/build-shaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
var fs = require('fs');
var path = require('path');

var glsl;
try { glsl = require('glsl-optimizer'); } catch(err) {}

module.exports = function() {
var name;
var shaders = {};

var shaderFiles = fs.readdirSync('src/shader');


// Load shaders
for (var i = 0; i < shaderFiles.length; i++) {
var parts = shaderFiles[i].match(/^(.+)\.(vertex|fragment)\.glsl$/);
if (parts) {
Expand All @@ -22,6 +27,36 @@ module.exports = function() {
}
}


// Optimize shader
if (glsl) {
var compiler = new glsl.Compiler(glsl.TARGET_OPENGLES20);
for (name in shaders) {
var vertex_shader = new glsl.Shader(compiler, glsl.VERTEX_SHADER, shaders[name].vertex);
if (vertex_shader.compiled()) {
shaders[name].vertex = vertex_shader.output();
} else {
console.warn('failed to optimize %s vertex shader', name);
process.exit(1);
}
vertex_shader.dispose();

var fragment_shader = new glsl.Shader(compiler, glsl.FRAGMENT_SHADER, shaders[name].fragment);
if (fragment_shader.compiled()) {
shaders[name].fragment = fragment_shader.output();
} else {
console.warn('failed to optimize %s fragment shader', name);
process.exit(1);
}
fragment_shader.dispose();
}
compiler.dispose();
} else {
console.warn('Not optimizing shaders');
}


// Save to file
var lines = [];
var consts = [];
for (var name in shaders) {
Expand Down Expand Up @@ -69,6 +104,7 @@ module.exports = function() {
code += '\n};\n';

fs.writeFileSync('src/shader/shaders.cpp', code);

};

module.exports();
64 changes: 60 additions & 4 deletions bin/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,45 @@ module.exports = {
"value": ["Restaurant"],
"type": "point"
},
"country_label": {
"source": "streets",
"type": "text",
"layer": "country_label",
"feature_type": "point",
"padding": 10,
"text_field": "name",
"path": "horizontal",
"font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS",
"fontSize": 16
},
"place_label": {
"source": "streets",
"type": "text",
"layer": "place_label",
"feature_type": "point",
"text_field": "name",
"path": "horizontal",
"font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS",
"fontSize": 18,
"alwaysVisible": true
},
"road_label": {
"source": "streets",
"type": "text",
"layer": "road_label",
"feature_type": "line",
"text_field": "name",
"path": "curve",
"font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS",
"fontSize": 12,
"textMinDistance": 250,
"maxAngleDelta": 1.04, // radians
},
},
"sprite": "img/maki-sprite",
"constants": {
"park": "#c8df9f",
"text": "#000000",
},
"structure": [
{ "name": "park", "bucket": "park" },
Expand All @@ -105,6 +140,9 @@ module.exports = {
{ "name": "embassy_poi", "bucket": "embassy_poi" },
{ "name": "park_poi", "bucket": "park_poi" },
{ "name": "restaurant_poi", "bucket": "restaurant_poi" },
{ "name": "country_label", "bucket": "country_label" },
{ "name": "place_label", "bucket": "place_label" },
{ "name": "road_label", "bucket": "road_label" },
],
"classes": [
{
Expand Down Expand Up @@ -156,8 +194,8 @@ module.exports = {
{ z: 0, val: 0.5 },
{ z: 13, val: 0.5 },
{ z: 16, val: 2 },
{ z: 20, val: 32 },
{ z: 30, val: 32 }
{ z: 20, val: 16 },
{ z: 30, val: 16 }
],
},
"road_large": {
Expand All @@ -169,8 +207,8 @@ module.exports = {
{ z: 11, val: 0.5 },
{ z: 13, val: 1 },
{ z: 16, val: 4 },
{ z: 20, val: 64 },
{ z: 30, val: 64 }
{ z: 20, val: 32 },
{ z: 30, val: 32 }
],
},
"alcohol_poi": {
Expand Down Expand Up @@ -208,6 +246,24 @@ module.exports = {
"image": "restaurant",
"opacity": [ "linear", 15, 0, 1.0, 0, 0.75 ]
},
"country_label": {
"type": "text",
"stroke": [ 1, 1, 1, 0.7 ],
"color": "text",
"size": 16
},
"place_label": {
"type": "text",
"stroke": [1,1,1,0.7],
"color": "text",
"size": 18
},
"road_label": {
"type": "text",
"color": "text",
"stroke": [1,1,1,0.7],
"size": ["exponential", 14, 8, 1, 8, 12]
},
}
}
]
Expand Down
13 changes: 8 additions & 5 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
'cflags_cc': ['-std=c++11'],
'configurations': {
'Debug': {
'cflags': [ '-g', '-O0' ],
'cflags': [ '-g', '-O0', '-I<(boost_root)/include' ],
'defines': [ 'DEBUG' ],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [ '-g']
'OTHER_CPLUSPLUSFLAGS': [ '-g', '-I<(boost_root)/include' ]
}
},
'Release': {
'cflags': [ '-O3'],
'defines': [ 'NDEBUG' ]
'cflags': [ '-O3', '-I<(boost_root)/include' ],
'defines': [ 'NDEBUG' ],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [ '-I<(boost_root)/include' ]
}
}
}
}
}
}
42 changes: 39 additions & 3 deletions common/map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ class MapView {
glfwSetKeyCallback(window, key);
}


static void character(GLFWwindow *window, unsigned int codepoint) {

}


static void key(GLFWwindow *window, int key, int scancode, int action, int mods) {
MapView *mapView = (MapView *)glfwGetWindowUserPointer(window);

Expand All @@ -95,7 +93,6 @@ class MapView {
}
}


static void scroll(GLFWwindow *window, double xoffset, double yoffset) {
MapView *mapView = (MapView *)glfwGetWindowUserPointer(window);
double delta = yoffset * 40;
Expand Down Expand Up @@ -234,3 +231,42 @@ class MapView {
llmr::Settings& settings;
llmr::Map map;
};

namespace llmr {
namespace platform {

double time() {
return glfwGetTime();
}


void show_debug_image(std::string name, const char *data, size_t width, size_t height) {
static GLFWwindow *debug_window = nullptr;
if (!debug_window) {
debug_window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr);
if (!debug_window) {
glfwTerminate();
fprintf(stderr, "Failed to initialize window\n");
exit(1);
}
}

GLFWwindow *current_window = glfwGetCurrentContext();

glfwSetWindowSize(debug_window, width, height);
glfwMakeContextCurrent(debug_window);

int fb_width, fb_height;
glfwGetFramebufferSize(debug_window, &fb_width, &fb_height);
float scale = (float)fb_width / (float)width;

glPixelZoom(scale, -scale);
glRasterPos2f(-1.0f, 1.0f);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
glfwSwapBuffers(debug_window);

glfwMakeContextCurrent(current_window);
}

}
}
9 changes: 9 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ parser.add_option("--debug",
dest="debug",
help="Also build debug build")

parser.add_option("--boost",
action="store",
dest="boost_root",
help="Path to boost (defaults to /usr/local)")

parser.add_option("--glfw3",
action="store",
dest="glfw3",
Expand Down Expand Up @@ -55,6 +60,10 @@ def pkg_config(pkg):
return (libs, cflags)

def configure_llmr(o):
if options.boost_root:
o['variables']['boost_root'] = options.boost_root
else:
o['variables']['boost_root'] = '/usr/local'
o['target_defaults']['default_configuration'] = 'Debug' if options.debug else 'Release'

def configure_glfw3(o):
Expand Down
Loading