diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index 78c435ba7..3ec95280e 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -34,12 +34,12 @@ set(PROJECTM_ABI_LEVEL 2) # if (EMSCRIPTEN) - SET(USE_GLES1 OFF) + SET(USE_GLES1 ON) SET(USE_NATIVE_GLEW OFF) SET(USE_THREADS OFF) SET(USE_OPENMP OFF) SET(USE_FTGL OFF) - SET(USE_FBO ON) + SET(USE_FBO OFF) SET(BUILD_PROJECTM_STATIC ON) SET(DISABLE_NATIVE_PRESETS ON) SET(USE_CG OFF) @@ -47,7 +47,6 @@ if (EMSCRIPTEN) SET(LINUX ) SET(OPENGL_gl_LIBRARY "fake_gl_lib.a") SET(GLEW_LIBRARY "gl.symbols") - ADD_DEFINITIONS(-DEMSCRIPTEN) ADD_DEFINITIONS(-DDISABLE_NATIVE_PRESETS) endif (EMSCRIPTEN) diff --git a/src/libprojectM/MilkdropPresetFactory/Parser.hpp b/src/libprojectM/MilkdropPresetFactory/Parser.hpp index 803541723..8c0e19d27 100755 --- a/src/libprojectM/MilkdropPresetFactory/Parser.hpp +++ b/src/libprojectM/MilkdropPresetFactory/Parser.hpp @@ -29,7 +29,7 @@ #ifndef _PARSER_H #define _PARSER_H //#define PARSE_DEBUG 2 -#define PARSE_DEBUG 2 +#define PARSE_DEBUG 0 #include diff --git a/src/libprojectM/MilkdropPresetFactory/libMilkdropPresetFactory.a b/src/libprojectM/MilkdropPresetFactory/libMilkdropPresetFactory.a index 06b3a9986..8763c0bf3 100644 Binary files a/src/libprojectM/MilkdropPresetFactory/libMilkdropPresetFactory.a and b/src/libprojectM/MilkdropPresetFactory/libMilkdropPresetFactory.a differ diff --git a/src/libprojectM/Renderer/FBO.cpp b/src/libprojectM/Renderer/FBO.cpp index fac240831..64a097774 100755 --- a/src/libprojectM/Renderer/FBO.cpp +++ b/src/libprojectM/Renderer/FBO.cpp @@ -25,13 +25,10 @@ */ #include -//#include #include #include "Common.hpp" #include "FBO.hpp" - - RenderTarget::~RenderTarget() { diff --git a/src/libprojectM/Renderer/FBO.hpp b/src/libprojectM/Renderer/FBO.hpp index 0448189d6..28940b940 100755 --- a/src/libprojectM/Renderer/FBO.hpp +++ b/src/libprojectM/Renderer/FBO.hpp @@ -28,17 +28,17 @@ #ifndef _RENDERTARGET_H #define _RENDERTARGET_H + +#ifdef EMSCRIPTEN +#include +#endif + #ifdef USE_FBO #ifdef USE_NATIVE_GLEW #include "glew.h" #else #include #endif - -#if EMSCRIPTEN -#include -#endif - #endif #ifdef MACOS diff --git a/src/libprojectM/Renderer/MilkdropWaveform.cpp b/src/libprojectM/Renderer/MilkdropWaveform.cpp index d18250ca3..105b8c242 100644 --- a/src/libprojectM/Renderer/MilkdropWaveform.cpp +++ b/src/libprojectM/Renderer/MilkdropWaveform.cpp @@ -33,7 +33,9 @@ void MilkdropWaveform::Draw(RenderContext &context) { WaveformMath(context); - glMatrixMode( GL_MODELVIEW ); + #ifndef EMSCRIPTEN + glMatrixMode( GL_MODELVIEW ); + #endif glPushMatrix(); glLoadIdentity(); diff --git a/src/libprojectM/Renderer/Renderable.cpp b/src/libprojectM/Renderer/Renderable.cpp index 3693858dd..592e8b50d 100644 --- a/src/libprojectM/Renderer/Renderable.cpp +++ b/src/libprojectM/Renderer/Renderable.cpp @@ -2,7 +2,11 @@ #include "Common.hpp" #ifdef USE_GLES1 -#include + #ifdef EMSCRIPTEN + #include + #else + #include + #endif #else #ifdef __APPLE__ #include @@ -270,7 +274,9 @@ void MotionVectors::Draw(RenderContext &context) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#ifndef EMSCRIPTEN glPointSize(length); +#endif glColor4f(r, g, b, a * masterAlpha); if (x_num + y_num < 600) @@ -331,11 +337,15 @@ void Border::Draw(RenderContext &context) glColor4f(inner_r, inner_g, inner_b, inner_a * masterAlpha); + // glRect doesn't exist in GLES I think + // TODO: replace glRect +#ifndef EMSCRIPTEN glRectd(of, of, of+iff, texof); glRectd(of+iff, of, texof-iff, of+iff); glRectd(texof-iff, of, texof, texof); glRectd(of+iff, texof, texof-iff, texof-iff); - +#endif + float pointsE[4][2] = {{of,of},{of,texof},{of+iff,of},{of+iff,texof}}; glVertexPointer(2,GL_FLOAT,0,pointsE); glDrawArrays(GL_TRIANGLE_STRIP,0,4); diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp index 2c2e0aa57..6be03b0e7 100644 --- a/src/libprojectM/Renderer/Renderer.cpp +++ b/src/libprojectM/Renderer/Renderer.cpp @@ -155,13 +155,11 @@ void Renderer::SetupPass1(const Pipeline &pipeline, const PipelineContext &pipel glMatrixMode(GL_PROJECTION); glLoadIdentity(); -#ifdef USE_GLES1 - glOrthof(0.0, 1, 0.0, 1, -40, 40); -#else glOrtho(0.0, 1, 0.0, 1, -40, 40); -#endif +#ifndef EMSCRIPTEN glMatrixMode(GL_MODELVIEW); +#endif glLoadIdentity(); #ifdef USE_CG @@ -222,20 +220,20 @@ void Renderer::Pass2(const Pipeline &pipeline, const PipelineContext &pipelineCo glBindTexture(GL_TEXTURE_2D, this->renderTarget->textureID[0]); +#ifndef EMSCRIPTEN glMatrixMode(GL_PROJECTION); - glLoadIdentity(); -#ifdef USE_GLES1 - glOrthof(-0.5, 0.5, -0.5, 0.5, -40, 40); -#else - glOrtho(-0.5, 0.5, -0.5, 0.5, -40, 40); #endif + glLoadIdentity(); + glOrtho(-0.5, 0.5, -0.5, 0.5, -40, 40); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize / 512.0); CompositeOutput(pipeline, pipelineContext); +#ifndef EMSCRIPTEN glMatrixMode(GL_MODELVIEW); +#endif glLoadIdentity(); glTranslatef(-0.5, -0.5, 0); @@ -339,8 +337,9 @@ void Renderer::Interpolation(const Pipeline &pipeline) //glVertexPointer(2, GL_FLOAT, 0, p); //glTexCoordPointer(2, GL_FLOAT, 0, t); +#ifndef EMSCRIPTEN glInterleavedArrays(GL_T2F_V3F,0,p); - +#endif if (pipeline.staticPerPixel) { diff --git a/src/libprojectM/Renderer/Waveform.cpp b/src/libprojectM/Renderer/Waveform.cpp index ca9113a1f..4465a0ff6 100644 --- a/src/libprojectM/Renderer/Waveform.cpp +++ b/src/libprojectM/Renderer/Waveform.cpp @@ -49,6 +49,8 @@ void Waveform::Draw(RenderContext &context) if (additive) glBlendFunc(GL_SRC_ALPHA, GL_ONE); else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// webGL doesn't do glPointSize +#ifndef EMSCRIPTEN if (thick) { glLineWidth(context.texsize <= 512 ? 2 : 2*context.texsize/512); @@ -56,7 +58,7 @@ void Waveform::Draw(RenderContext &context) } else glPointSize(context.texsize <= 512 ? 1 : context.texsize/512); - +#endif float *value1 = new float[samples]; float *value2 = new float[samples]; diff --git a/src/libprojectM/Renderer/libRenderer.a b/src/libprojectM/Renderer/libRenderer.a index 6c03a90ee..9945c00a1 100644 Binary files a/src/libprojectM/Renderer/libRenderer.a and b/src/libprojectM/Renderer/libRenderer.a differ diff --git a/src/libprojectM/libprojectM.a b/src/libprojectM/libprojectM.a index 4db8b5975..55ccc6a57 100644 Binary files a/src/libprojectM/libprojectM.a and b/src/libprojectM/libprojectM.a differ diff --git a/src/projectM-emscripten/CMakeLists.txt b/src/projectM-emscripten/CMakeLists.txt index 6306584ab..a17e3bda2 100644 --- a/src/projectM-emscripten/CMakeLists.txt +++ b/src/projectM-emscripten/CMakeLists.txt @@ -8,8 +8,13 @@ if(COMMAND cmake_policy) endif(COMMAND cmake_policy) INCLUDE(../cmake/CPack-projectM.cmake) +SET(PROJECTM_INCLUDE ${PROJECTM_ROOT_SOURCE_DIR}/libprojectM ${PROJECTM_ROOT_SOURCE_DIR}/libprojectM/Renderer) + # we're producing an executable called projectEM, it has one source input -ADD_EXECUTABLE(projectEM projectM_SDL_emscripten.cpp ${PROJECTM_ROOT_SOURCE_DIR}/libprojectM/PresetFactory.cpp) +ADD_EXECUTABLE(projectEM projectM_SDL_emscripten.cpp + ${PROJECTM_ROOT_SOURCE_DIR}/libprojectM/PresetFactory.cpp + ${PROJECTM_ROOT_SOURCE_DIR}/libprojectM/KeyHandler.cpp +) # openGL SET(OPENGL_gl_LIBRARY "fake_gl_lib.a") @@ -18,11 +23,11 @@ FIND_PACKAGE(OpenGL) # link in projectM # i have no idea if this is correct TARGET_LINK_LIBRARIES(projectEM projectM ${OPENGL_LIBRARIES}) -SET(PROJECTM_INCLUDE ${PROJECTM_ROOT_SOURCE_DIR}/libprojectM) SET(PROJECTM_LINK ${LIBPROJECTM_LDFLAGS}) INCLUDE_DIRECTORIES(${PROJECTM_INCLUDE}) LINK_DIRECTORIES(${PROJECTM_LINK}) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s LEGACY_GL_EMULATION=1 ") -SET_TARGET_PROPERTIES(projectEM PROPERTIES LINK_FLAGS " -s REGAL_SYS_EMSCRIPTEN=1 -o build/projectEM.html --emrun") +SET_TARGET_PROPERTIES(projectEM PROPERTIES LINK_FLAGS " -s REGAL_SYS_EMSCRIPTEN=1 --embed-file build/presets -o build/projectEM.html --emrun") #SET_TARGET_PROPERTIES(projectEM PROPERTIES LINK_FLAGS "--emrun") diff --git a/src/projectM-emscripten/projectM_SDL_emscripten.cpp b/src/projectM-emscripten/projectM_SDL_emscripten.cpp index 1a06c2658..3e01e1c49 100755 --- a/src/projectM-emscripten/projectM_SDL_emscripten.cpp +++ b/src/projectM-emscripten/projectM_SDL_emscripten.cpp @@ -87,7 +87,7 @@ void renderFrame() { #if SDL_MAJOR_VERSION==2 SDL_RenderPresent(rend); #elif SDL_MAJOR_VERSION==1 - SDL_Flip(screen); + SDL_GL_SwapBuffers(); #endif } @@ -150,13 +150,12 @@ int main( int argc, char *argv[] ) { settings.shuffleEnabled = 1; settings.softCutRatingsEnabled = 1; // ??? #ifdef EMSCRIPTEN - settings.presetURL = "http://./presets"; + settings.presetURL = "/build/presets"; #else settings.presetURL = "presets"; #endif // init projectM - printf("initting\n"); globalPM = new projectM(settings); printf("init projectM\n"); globalPM->selectRandom(true); @@ -166,7 +165,7 @@ int main( int argc, char *argv[] ) { // mainloop. non-emscripten version here for comparison/testing #ifdef EMSCRIPTEN - emscripten_set_main_loop(renderFrame, 30, 0); + emscripten_set_main_loop(renderFrame, 0, 0); #else // standard main loop const Uint32 frame_delay = 1000/FPS;