diff --git a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
index a984e36422e..3a4714b3be7 100644
--- a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
+++ b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
@@ -31,7 +31,10 @@ var LibraryHTML5Audio = {
try {
// Fix up for prefixing
window.AudioContext = window.AudioContext || window.webkitAudioContext;
- var context = new AudioContext();
+ var context = new AudioContext({
+ latencyHint: "interactive",
+ sampleRate: 44100
+ });
// Fix issue with chrome autoplay policy
document.addEventListener('mousedown', function cb(event) {
diff --git a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp
index b17505f59b4..2c0b23a7753 100644
--- a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp
+++ b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp
@@ -58,7 +58,7 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){
EGLint majorVersion;
EGLint minorVersion;
EGLConfig config;
- EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
+ EGLint contextAttribs[] = { EGL_CONTEXT_MAJOR_VERSION, 3, EGL_NONE, EGL_NONE };
std::vector attribList =
{
EGL_RED_SIZE, EGL_DONT_CARE,
@@ -68,12 +68,25 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){
EGL_DEPTH_SIZE, EGL_DONT_CARE,
EGL_STENCIL_SIZE, EGL_DONT_CARE,
EGL_SAMPLE_BUFFERS, EGL_DONT_CARE,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
EGL_NONE
};
+
+ // We'll try these alpha sizes in order ending with EGL_DONT_CARE if we don't get anything higher.
+ std::vector alphaPreference = {8, EGL_DONT_CARE};
+ // Find the index for the value EGL_ALPHA_SIZE uses, so we can try a few different values till we get a successful config.
+ int attribListAlphaIndex = -1;
+ for(int i = 0; i < attribList.size(); i++){
+ if( attribList[i] == EGL_ALPHA_SIZE ){
+ attribListAlphaIndex = i+1;
+ break;
+ }
+ }
+
// We'll try these depth sizes in order ending with EGL_DONT_CARE if we don't get anything higher.
std::vector depthPreference = {24, 16, EGL_DONT_CARE};
-
+
// Find the index for the value EGL_DEPTH_SIZE uses, so we can try a few different values till we get a successful config.
int attribListDepthIndex = -1;
for(int i = 0; i < attribList.size(); i++){
@@ -83,6 +96,18 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){
}
}
+ // We'll try these sample buffers in order ending with EGL_DONT_CARE if we don't get anything higher.
+ std::vector sampleBuffersPreference = {1, EGL_DONT_CARE};
+
+ // Find the index for the value EGL_SAMPLE_BUFFERS uses, so we can try a few different values till we get a successful config.
+ int attribListSampleBuffersIndex = -1;
+ for(int i = 0; i < attribList.size(); i++){
+ if( attribList[i] == EGL_SAMPLE_BUFFERS ){
+ attribListSampleBuffersIndex = i+1;
+ break;
+ }
+ }
+
// Get Display
display = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
if ( display == EGL_NO_DISPLAY ){
@@ -102,6 +127,27 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){
return;
}
+ // Choose the config based on our attribute list
+ // Try higher EGL_ALPHA_SIZE first
+ for(int i = 0; i < alphaPreference.size(); i++){
+ // Set EGL_ALPHA_SIZE
+ attribList[attribListAlphaIndex] = alphaPreference[i];
+
+ // Try out that depth value
+ if ( !eglChooseConfig(display, &attribList[0], &config, 1, &numConfigs) ){
+
+ // Finally fail like we did before if no preference works
+ if( alphaPreference[i] == EGL_DONT_CARE ){
+ ofLogError() << "couldn't choose display";
+ return;
+ }
+
+ }else{
+ // Got a good configuration. Stop searching.
+ break;
+ }
+ }
+
// Choose the config based on our attribute list
// Try higher EGL_DEPTH_SIZE first
for(int i = 0; i < depthPreference.size(); i++){
@@ -122,6 +168,27 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){
break;
}
}
+
+ // Choose the config based on our attribute list
+ // Try higher EGL_SAMPLE_BUFFERS first
+ for(int i = 0; i < sampleBuffersPreference.size(); i++){
+ // Set EGL_SAMPLE_BUFFERS
+ attribList[attribListSampleBuffersIndex] = sampleBuffersPreference[i];
+
+ // Try out that depth value
+ if ( !eglChooseConfig(display, &attribList[0], &config, 1, &numConfigs) ){
+
+ // Finally fail like we did before if no preference works
+ if( sampleBuffersPreference[i] == EGL_DONT_CARE ){
+ ofLogError() << "couldn't choose display";
+ return;
+ }
+
+ }else{
+ // Got a good configuration. Stop searching.
+ break;
+ }
+ }
// Create a surface
surface = eglCreateWindowSurface(display, config, NULL, NULL);
@@ -148,16 +215,16 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){
_renderer = make_shared(this);
((ofGLProgrammableRenderer*)_renderer.get())->setup(2,0);
- emscripten_set_keydown_callback(0,this,1,&keydown_cb);
- emscripten_set_keyup_callback(0,this,1,&keyup_cb);
- emscripten_set_mousedown_callback(0,this,1,&mousedown_cb);
- emscripten_set_mouseup_callback(0,this,1,&mouseup_cb);
- emscripten_set_mousemove_callback(0,this,1,&mousemoved_cb);
+ emscripten_set_keydown_callback("#canvas",this,1,&keydown_cb);
+ emscripten_set_keyup_callback("#canvas",this,1,&keyup_cb);
+ emscripten_set_mousedown_callback("#canvas",this,1,&mousedown_cb);
+ emscripten_set_mouseup_callback("#canvas",this,1,&mouseup_cb);
+ emscripten_set_mousemove_callback("#canvas",this,1,&mousemoved_cb);
- emscripten_set_touchstart_callback(0,this,1,&touch_cb);
- emscripten_set_touchend_callback(0,this,1,&touch_cb);
- emscripten_set_touchmove_callback(0,this,1,&touch_cb);
- emscripten_set_touchcancel_callback(0,this,1,&touch_cb);
+ emscripten_set_touchstart_callback("#canvas",this,1,&touch_cb);
+ emscripten_set_touchend_callback("#canvas",this,1,&touch_cb);
+ emscripten_set_touchmove_callback("#canvas",this,1,&touch_cb);
+ emscripten_set_touchcancel_callback("#canvas",this,1,&touch_cb);
}
void ofxAppEmscriptenWindow::loop(){
@@ -229,9 +296,9 @@ int ofxAppEmscriptenWindow::mouseup_cb(int eventType, const EmscriptenMouseEvent
int ofxAppEmscriptenWindow::mousemoved_cb(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData){
if(ofGetMousePressed()){
- instance->events().notifyMouseDragged(mouseEvent->canvasX,mouseEvent->canvasY,0);
+ instance->events().notifyMouseDragged(mouseEvent->targetX,mouseEvent->targetY,0);
}else{
- instance->events().notifyMouseMoved(mouseEvent->canvasX,mouseEvent->canvasY);
+ instance->events().notifyMouseMoved(mouseEvent->targetX,mouseEvent->targetY);
}
return 0;
@@ -261,8 +328,8 @@ int ofxAppEmscriptenWindow::touch_cb(int eventType, const EmscriptenTouchEvent*
ofTouchEventArgs touchArgs;
touchArgs.type = touchArgsType;
touchArgs.id = i;
- touchArgs.x = e->touches[i].canvasX;
- touchArgs.y = e->touches[i].canvasY;
+ touchArgs.x = e->touches[i].targetX;
+ touchArgs.y = e->touches[i].targetY;
instance->events().notifyTouchEvent(touchArgs);
}
return 0;
@@ -282,21 +349,19 @@ void ofxAppEmscriptenWindow::setWindowPosition(int x, int y){
}
void ofxAppEmscriptenWindow::setWindowShape(int w, int h){
- emscripten_set_canvas_element_size(NULL,w,h);
+ emscripten_set_canvas_size(w,h);
}
-
-
glm::vec2 ofxAppEmscriptenWindow::getWindowPosition(){
return glm::vec2(0,0);
}
-
glm::vec2 ofxAppEmscriptenWindow::getWindowSize(){
int width;
int height;
- emscripten_get_canvas_element_size(NULL, &width, &height);
- return glm::vec2(width,height);
+ int isFullscreen;
+ emscripten_get_canvas_size(&width, &height, &isFullscreen);
+ return glm::vec3(width,height,isFullscreen);
}
glm::vec2 ofxAppEmscriptenWindow::getScreenSize(){
diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp
index 3c815812b50..6bf071099e8 100644
--- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp
+++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp
@@ -614,7 +614,12 @@ bool ofTrueTypeFont::loadFont(string filename, int fontSize, bool bAntiAliased,
//-----------------------------------------------------------
ofTrueTypeFont::glyph ofTrueTypeFont::loadGlyph(uint32_t utf8) const{
glyph aGlyph;
- auto err = FT_Load_Glyph( face.get(), FT_Get_Char_Index( face.get(), utf8 ), settings.antialiased ? FT_LOAD_FORCE_AUTOHINT : FT_LOAD_DEFAULT );
+ bool autoHint = settings.antialiased;
+ #ifdef TARGET_EMSCRIPTEN
+ autoHint = false;
+ #endif
+
+ auto err = FT_Load_Glyph( face.get(), FT_Get_Char_Index( face.get(), utf8 ), autoHint ? FT_LOAD_FORCE_AUTOHINT : FT_LOAD_DEFAULT );
if(err){
ofLogError("ofTrueTypeFont") << "loadFont(): FT_Load_Glyph failed for utf8 code " << utf8 << ": FT_Error " << err;
return aGlyph;