emscripten version actually kind of runs in a browser now. pretty messed up looking, but it's a start.

This commit is contained in:
Mischa S
2014-06-22 01:22:41 -07:00
parent e00f338a29
commit e343f1c80e
13 changed files with 46 additions and 33 deletions

View File

@ -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)

View File

@ -29,7 +29,7 @@
#ifndef _PARSER_H
#define _PARSER_H
//#define PARSE_DEBUG 2
#define PARSE_DEBUG 2
#define PARSE_DEBUG 0
#include <stdio.h>

View File

@ -25,13 +25,10 @@
*/
#include <stdio.h>
//#include <GL/gl.h>
#include <iostream>
#include "Common.hpp"
#include "FBO.hpp"
RenderTarget::~RenderTarget() {

View File

@ -28,17 +28,17 @@
#ifndef _RENDERTARGET_H
#define _RENDERTARGET_H
#ifdef EMSCRIPTEN
#include <GL/gl.h>
#endif
#ifdef USE_FBO
#ifdef USE_NATIVE_GLEW
#include "glew.h"
#else
#include <GL/glew.h>
#endif
#if EMSCRIPTEN
#include <GL/glew.h>
#endif
#endif
#ifdef MACOS

View File

@ -33,7 +33,9 @@ void MilkdropWaveform::Draw(RenderContext &context)
{
WaveformMath(context);
glMatrixMode( GL_MODELVIEW );
#ifndef EMSCRIPTEN
glMatrixMode( GL_MODELVIEW );
#endif
glPushMatrix();
glLoadIdentity();

View File

@ -2,7 +2,11 @@
#include "Common.hpp"
#ifdef USE_GLES1
#include <GLES/gl.h>
#ifdef EMSCRIPTEN
#include <GL/gl.h>
#else
#include <GLES/gl.h>
#endif
#else
#ifdef __APPLE__
#include <OpenGL/gl.h>
@ -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);

View File

@ -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)
{

View File

@ -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];

Binary file not shown.

View File

@ -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")

View File

@ -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;