From: APTX Date: Thu, 3 Feb 2011 21:40:16 +0000 (+0100) Subject: Make openlase build on windows with msvc (C++ mode) and clang (C mode) X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;ds=sidebyside;p=openlase-old.git Make openlase build on windows with msvc (C++ mode) and clang (C mode) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b2fc33..8507a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,4 +30,4 @@ set(CMAKE_C_FLAGS "-Wall -O3 -g") add_subdirectory (libol) add_subdirectory (output) add_subdirectory (tools) -add_subdirectory (examples) +#add_subdirectory (examples) diff --git a/include/ilda.h b/include/ilda.h index e408de6..9e63071 100644 --- a/include/ilda.h +++ b/include/ilda.h @@ -22,6 +22,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { float x; float y; @@ -46,4 +50,7 @@ void olDrawIlda(IldaFile *ild); void olDrawIlda3D(IldaFile *ild); void olFreeIlda(IldaFile *ild); +#ifdef __cplusplus +} +#endif #endif \ No newline at end of file diff --git a/include/libol.h b/include/libol.h index 5a24b35..181c6e9 100644 --- a/include/libol.h +++ b/include/libol.h @@ -22,6 +22,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include +#ifdef __cplusplus +extern "C" { +#endif + enum { OL_LINESTRIP, OL_BEZIERSTRIP, @@ -139,4 +143,7 @@ typedef void (*LogCallbackFunc)(const char *msg); void olSetLogCallback(LogCallbackFunc f); +#ifdef __cplusplus +} +#endif #endif diff --git a/include/text.h b/include/text.h index cd9c155..d2afdc1 100644 --- a/include/text.h +++ b/include/text.h @@ -23,6 +23,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { int flag; float x; @@ -47,4 +51,7 @@ float olGetCharOverlap(Font *font, float height); float olDrawChar(Font *fnt, float x, float y, float height, uint32_t color, char c); float olDrawString(Font *fnt, float x, float y, float height, uint32_t color, const char *s); +#ifdef __cplusplus +} +#endif #endif diff --git a/libol/CMakeLists.txt b/libol/CMakeLists.txt index 53b6806..79ce717 100644 --- a/libol/CMakeLists.txt +++ b/libol/CMakeLists.txt @@ -16,14 +16,14 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # -include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/windeps/include) find_package(Threads) -add_library (openlase libol.c text.c ilda.c ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c) -find_library (PTHREAD pthread) -target_link_libraries (openlase ${CMAKE_THREAD_LIBS_INIT} m jack) +add_library (openlase libol.cpp text.cpp ilda.cpp ${CMAKE_CURRENT_BINARY_DIR}/fontdef.cpp ${CMAKE_SOURCE_DIR}/windeps/src/wincompat.cpp) +#find_library (PTHREAD pthread) +target_link_libraries (openlase ${CMAKE_THREAD_LIBS_INIT} jack) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fontdef.cpp DEPENDS ${CMAKE_SOURCE_DIR}/tools/genfont.py MAIN_DEPENDENCY laserfont.svg - COMMAND python ${CMAKE_SOURCE_DIR}/tools/genfont.py ${CMAKE_CURRENT_SOURCE_DIR}/laserfont.svg ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c default_font) + COMMAND python ${CMAKE_SOURCE_DIR}/tools/genfont.py ${CMAKE_CURRENT_SOURCE_DIR}/laserfont.svg ${CMAKE_CURRENT_BINARY_DIR}/fontdef.cpp default_font) diff --git a/libol/ilda.c b/libol/ilda.cpp similarity index 91% rename from libol/ilda.c rename to libol/ilda.cpp index 7019420..e2d2639 100644 --- a/libol/ilda.c +++ b/libol/ilda.cpp @@ -28,6 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include + #if BYTE_ORDER == LITTLE_ENDIAN static inline uint16_t swapshort(uint16_t v) { return (v >> 8) | (v << 8); @@ -81,7 +83,7 @@ IldaFile *olLoadIlda(const char *filename) return NULL; } - ild = malloc(sizeof(*ild)); + ild = (IldaFile *) malloc(sizeof(*ild)); memset(ild, 0, sizeof(*ild)); @@ -113,10 +115,10 @@ IldaFile *olLoadIlda(const char *filename) hdr.framecount = swapshort(hdr.framecount); switch (hdr.format) { - case 0: + case 0: { olLog("ILD: Got 3D frame, %d points\n", hdr.count); - ild->points = malloc(sizeof(IldaPoint) * hdr.count); - struct icoord3d *tmp3d = malloc(sizeof(struct icoord3d) * hdr.count); + ild->points = (IldaPoint *) malloc(sizeof(IldaPoint) * hdr.count); + struct icoord3d *tmp3d = (struct icoord3d *) malloc(sizeof(struct icoord3d) * hdr.count); if (fread(tmp3d, sizeof(struct icoord3d), hdr.count, fd) != hdr.count) { olLog("ILDA: error while reading frame\n"); olFreeIlda(ild); @@ -131,11 +133,11 @@ IldaFile *olLoadIlda(const char *filename) } free(tmp3d); ild->count = hdr.count; - break; - case 1: + break; } + case 1: { olLog("Got 2D frame, %d points\n", hdr.count); - ild->points = malloc(sizeof(IldaPoint) * hdr.count); - struct icoord2d *tmp2d = malloc(sizeof(struct icoord2d) * hdr.count); + ild->points = (IldaPoint *) malloc(sizeof(IldaPoint) * hdr.count); + struct icoord2d *tmp2d = (struct icoord2d *) malloc(sizeof(struct icoord2d) * hdr.count); if (fread(tmp2d, sizeof(struct icoord2d), hdr.count, fd) != hdr.count) { olLog("ILDA: error while reading frame\n"); olFreeIlda(ild); @@ -150,7 +152,7 @@ IldaFile *olLoadIlda(const char *filename) } free(tmp2d); ild->count = hdr.count; - break; + break; } case 2: olLog("ILDA: Got color palette section, %d entries\n", hdr.count); olLog("ILDA: NOT SUPPORTED\n"); diff --git a/libol/libol.c b/libol/libol.cpp similarity index 96% rename from libol/libol.c rename to libol/libol.cpp index eb2385c..d2efc69 100644 --- a/libol/libol.c +++ b/libol/libol.cpp @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "libol.h" #include #include @@ -25,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +// Yes this file is needed twice! +#include typedef jack_default_audio_sample_t sample_t; typedef jack_nframes_t nframes_t; @@ -113,7 +116,14 @@ int coldp = 0; uint32_t cols[MTX_STACK_DEPTH]; uint32_t curcol; +#ifdef __cplusplus +Point __cplusplus_point(float x, float y, uint32_t color) +{Point p = {x, y, color};return p;} +#define POINT(x, y, color) __cplusplus_point(x,y,color) +#else +// Not really sure why it doesn't just work (just msvc or standard) #define POINT(x, y, color) ((Point){x,y,color}) +#endif ShaderFunc vpreshader; ShaderFunc vshader; @@ -245,16 +255,16 @@ int olInit(int buffer_count, int max_points) first_output_frame = 0; memset(&wframe, 0, sizeof(Frame)); wframe.objmax = 16; - wframe.objects = malloc(wframe.objmax * sizeof(Object)); + wframe.objects = (Object *) malloc(wframe.objmax * sizeof(Object)); wframe.psmax = max_points; - wframe.points = malloc(wframe.psmax * sizeof(Point)); - frames = malloc(fbufs * sizeof(RenderedFrame)); + wframe.points = (Point *) malloc(wframe.psmax * sizeof(Point)); + frames = (RenderedFrame *) malloc(fbufs * sizeof(RenderedFrame)); for (i=0; i #include #include #include diff --git a/output/output_settings.cpp b/output/output_settings.cpp index c98acfc..5826282 100644 --- a/output/output_settings.cpp +++ b/output/output_settings.cpp @@ -17,7 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "output_settings.moc" +#include "output_settings.h" + #include #include diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 7643ab3..0900465 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -16,14 +16,14 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # -include_directories (${CMAKE_SOURCE_DIR}/include) -link_directories (${CMAKE_BINARY_DIR}/libol) +include_directories (${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/windeps/include) +link_directories (${CMAKE_BINARY_DIR}/libol ${CMAKE_SOURCE_DIR}/windeps/lib) -add_executable(playilda playilda.c) +add_executable(playilda playilda.cpp ${CMAKE_SOURCE_DIR}/windeps/src/wincompat.cpp) target_link_libraries(playilda ${JACK_LIBRARIES}) -add_executable(playvid playvid.c trace.c) -target_link_libraries(playvid openlase avformat avcodec) +add_executable(playvid playvid.cpp trace.cpp ${CMAKE_SOURCE_DIR}/windeps/src/wincompat.cpp) +target_link_libraries(playvid openlase avformat avcodec avutil) include_directories (${CMAKE_SOURCE_DIR}/include) link_directories (${CMAKE_BINARY_DIR}/libol) @@ -31,7 +31,7 @@ link_directories (${CMAKE_BINARY_DIR}/libol) find_package(OpenGL REQUIRED) find_package(GLUT REQUIRED) -add_executable(simulator simulator.c) +add_executable(simulator simulator.cpp ${CMAKE_SOURCE_DIR}/windeps/src/wincompat.cpp) include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS}) target_link_libraries(simulator ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${JACK_LIBRARIES}) diff --git a/tools/genfont.py b/tools/genfont.py index 92557cd..232abc5 100644 --- a/tools/genfont.py +++ b/tools/genfont.py @@ -424,9 +424,13 @@ for id, x, y, w, h in handler.rects: cdefs.append((chrval, w, "NULL")) output += "\nstatic const FontChar font_chars[256] = {\n" - -for chrval, width, sym in cdefs: - output += "\t['%s'] = {%8.4f, %s},\n"%(chr(chrval),width,sym) +for i in range(255): + for chrval, width, sym in cdefs: + if (chrval == i): + output += "\t{%8.4f, %s},\n"%(width,sym) + break + else: + output += "\t{0, 0},\n" output += "};\n\n" diff --git a/tools/playilda.c b/tools/playilda.cpp similarity index 97% rename from tools/playilda.c rename to tools/playilda.cpp index f738c9b..5616da1 100644 --- a/tools/playilda.c +++ b/tools/playilda.cpp @@ -320,10 +320,10 @@ int loadild(const char *fname, struct frame *frame) hdr.framecount = swapshort(hdr.framecount); switch (hdr.format) { - case 0: + case 0: { printf("Got 3D frame, %d points\n", hdr.count); - frame->points = malloc(sizeof(struct coord3d) * hdr.count); - struct icoord3d *tmp3d = malloc(sizeof(struct icoord3d) * hdr.count); + frame->points = (struct coord3d *) malloc(sizeof(struct coord3d) * hdr.count); + struct icoord3d *tmp3d = (struct icoord3d *) malloc(sizeof(struct icoord3d) * hdr.count); if (fread(tmp3d, sizeof(struct icoord3d), hdr.count, ild) != hdr.count) { fprintf(stderr, "error while reading frame\n"); return -1; @@ -337,11 +337,11 @@ int loadild(const char *fname, struct frame *frame) } free(tmp3d); frame->count = hdr.count; - break; - case 1: + break; } + case 1: { printf("Got 2D frame, %d points\n", hdr.count); - frame->points = malloc(sizeof(struct coord3d) * hdr.count); - struct icoord2d *tmp2d = malloc(sizeof(struct icoord2d) * hdr.count); + frame->points = (struct coord3d *) malloc(sizeof(struct coord3d) * hdr.count); + struct icoord2d *tmp2d = (struct icoord2d *) malloc(sizeof(struct icoord2d) * hdr.count); if (fread(tmp2d, sizeof(struct icoord2d), hdr.count, ild) != hdr.count) { fprintf(stderr, "error while reading frame\n"); return -1; @@ -355,7 +355,7 @@ int loadild(const char *fname, struct frame *frame) } free(tmp2d); frame->count = hdr.count; - break; + break; } case 2: printf("Got color palette section, %d entries\n", hdr.count); if (fread(palette, 3, hdr.count, ild) != hdr.count) { @@ -425,7 +425,7 @@ int loadild(const char *fname, struct frame *frame) } int ocount = frame->count * rate / pointrate; - struct coord3d *opoints = malloc(sizeof(struct coord3d) * ocount); + struct coord3d *opoints = (struct coord3d *) malloc(sizeof(struct coord3d) * ocount); float mul = (float)frame->count / (float)ocount; diff --git a/tools/playvid.c b/tools/playvid.cpp similarity index 98% rename from tools/playvid.c rename to tools/playvid.cpp index a4474bc..888aab4 100644 --- a/tools/playvid.c +++ b/tools/playvid.cpp @@ -53,8 +53,16 @@ is a hack. #include #include +#include + +#ifdef __cplusplus +extern "C" { +#endif #include #include +#ifdef __cplusplus +} +#endif #define FRAMES_BUF 8 @@ -136,7 +144,7 @@ void moreaudio(float *lb, float *rb, int samples) input_samples = bytes / (sizeof(short)*pACodecCtx->channels); - buffered_samples = audio_resample(resampler, (void*)oabuf, iabuf, input_samples); + buffered_samples = audio_resample(resampler, (short *) oabuf, iabuf, input_samples); poabuf = oabuf; } @@ -465,7 +473,7 @@ int main (int argc, char *argv[]) else thresh = thresh_dark; - obj = trace(frame->data[0], tmp, thresh, + obj = trace(frame->data[0], (uint8_t *) tmp, thresh, pCodecCtx->width, pCodecCtx->height, frame->linesize[0], decimate); ftime = olRenderFrame(100); diff --git a/tools/simulator.c b/tools/simulator.cpp similarity index 100% rename from tools/simulator.c rename to tools/simulator.cpp diff --git a/tools/trace.c b/tools/trace.cpp similarity index 100% rename from tools/trace.c rename to tools/trace.cpp diff --git a/tools/trace.h b/tools/trace.h index 1551a89..641bc3c 100644 --- a/tools/trace.h +++ b/tools/trace.h @@ -20,6 +20,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef TRACE_H #define TRACE_H +#ifdef __cplusplus +extern "C" { +#endif + int trace(uint8_t *field, uint8_t *tmp, uint8_t thresh, int width, int height, int stride, int decimate); +#ifdef __cplusplus +} +#endif + #endif \ No newline at end of file diff --git a/windeps/include/unistd.h b/windeps/include/unistd.h new file mode 100644 index 0000000..daf4e94 --- /dev/null +++ b/windeps/include/unistd.h @@ -0,0 +1 @@ +#include "wincompat.h" \ No newline at end of file diff --git a/windeps/include/wincompat.h b/windeps/include/wincompat.h new file mode 100644 index 0000000..c2a73b5 --- /dev/null +++ b/windeps/include/wincompat.h @@ -0,0 +1,73 @@ +#ifdef DrawState +#undef DrawState +#endif + +#ifdef near +#undef near +#endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#ifdef _MSC_VER +#define __attribute__(x) +#endif + +// Only msvc? +#ifndef UINT64_C +#define UINT64_C(x) x##ui64 +#endif + +#ifndef HAVE_WINCOMPAT +#define HAVE_WINCOMPAT + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *HANDLE; +typedef HANDLE pthread_t; + +typedef int int32_t; +typedef unsigned int uint32_t; +typedef unsigned short uint16_t; +typedef unsigned long long uint64_t; + + +extern float fmaxf(float a, float b); + +/* ---------------------------------------------------------------------------------- + usleep + ---------------------------------------------------------------------------------- */ + +extern int usleep(unsigned int useconds); + +/* ---------------------------------------------------------------------------------- + getopt + ---------------------------------------------------------------------------------- */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +extern int opterr; +extern int optind; +extern int optopt; +extern char *optarg; + +extern int optreset; + +extern int +getopt( + int nargc, + char *const * nargv, + const char *ostr +); + +#ifdef __cplusplus +} +#endif + +#endif // HAVE_WINCOMPAT \ No newline at end of file diff --git a/windeps/src/wincompat.cpp b/windeps/src/wincompat.cpp new file mode 100644 index 0000000..885060c --- /dev/null +++ b/windeps/src/wincompat.cpp @@ -0,0 +1,110 @@ +#include + +float fmaxf(float a, float b) +{ + return a < b ? b : a; +} + +/* ---------------------------------------------------------------------------------- + usleep + ---------------------------------------------------------------------------------- */ + +#include + +int usleep(unsigned int useconds) +{ + HANDLE timer; + LARGE_INTEGER due; + + due.QuadPart = -(10 * (__int64)useconds); + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &due, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); + return 0; +} + +/* ---------------------------------------------------------------------------------- + getopt + ---------------------------------------------------------------------------------- */ + +#include +#include + +int opterr = 0; +int optind = 1; +int optopt = 0; +char *optarg = 0; + +int optreset = 0; + +int +getopt( + int nargc, + char *const * nargv, + const char *ostr +) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) + { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') + { + place = EMSG; + return -1; + } + if (place[1] && *++place == '-' && place[1] == '\0') + { /* found "--" */ + ++optind; + place = EMSG; + return -1; + } + } /* option letter okay? */ + if ((optopt = (int) *place++) == (int) ':' || + !(oli = strchr((char *) ostr, optopt))) + { + /* + * if the user didn't specify '-' as an option, assume it means -1. + */ + if (optopt == (int) '-') + return -1; + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void) fprintf(stderr, + "illegal option -- %c\n", optopt); + return BADCH; + } + if (*++oli != ':') + { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else + { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) + { /* no arg */ + place = EMSG; + if (*ostr == ':') + return BADARG; + if (opterr) + (void) fprintf(stderr, + "option requires an argument -- %c\n", + optopt); + return BADCH; + } + else + /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return optopt; /* dump back option letter */ +} \ No newline at end of file