Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if(NOT DEFINED BUILD_TRACER)
endif()

add_subdirectory (libol)
add_subdirectory (include)
add_subdirectory (output)
add_subdirectory (tools)
add_subdirectory (python)
Expand Down
12 changes: 12 additions & 0 deletions Modules/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ endif (NOT WIN32)
${PC_LIBAVCODEC_LIBRARY_DIRS}
)

find_library(AVRESAMPLE_LIBRARIES NAMES avresample
HINTS
${PC_LIBAVCODEC_LIBDIR}
${PC_LIBAVCODEC_LIBRARY_DIRS}
)



set(FFMPEG_LIBRARIES )
Expand All @@ -94,6 +100,11 @@ endif (NOT WIN32)
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${AVDEVICE_LIBRARIES})
endif (AVDEVICE_LIBRARIES)

if (AVRESAMPLE_LIBRARIES)
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${AVRESAMPLE_LIBRARIES})
set(AVRESAMPLE_FOUND TRUE)
endif (AVRESAMPLE_LIBRARIES)

if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
set(FFMPEG_FOUND TRUE)
endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
Expand Down Expand Up @@ -121,6 +132,7 @@ endif (NOT WIN32)
AVFORMAT_LIBRARIES
AVUTIL_LIBRARIES
AVDEVICE_LIBRARIES
AVRESAMPLE_LIBRARIES
FFMPEG_INCLUDE_DIR
FFMPEG_INCLUDE_DIR_OLD_STYLE)

Expand Down
17 changes: 17 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,42 @@ link_directories (${CMAKE_BINARY_DIR}/libol)

add_executable(circlescope circlescope.c)
target_link_libraries(circlescope ${JACK_LIBRARIES} m)
install(TARGETS circlescope DESTINATION bin)

add_executable(scope scope.c)
target_link_libraries(scope ${JACK_LIBRARIES} m)
install(TARGETS scope DESTINATION bin)

add_executable(simple simple.c)
target_link_libraries(simple openlase)
install(TARGETS simple DESTINATION bin)

add_executable(spin-text spin-text.c)
target_link_libraries(spin-text openlase)
install(TARGETS spin-text DESTINATION bin)

add_executable(show-text show-text.c)
target_link_libraries(show-text openlase)
install(TARGETS show-text DESTINATION bin)

add_executable(pong pong.c)
target_link_libraries(pong openlase)
install(TARGETS pong DESTINATION bin)

add_executable(test-static-frames test-static-frames.c)
target_link_libraries(test-static-frames openlase)

if(ALSA_FOUND)
add_executable(midiview midiview.c)
target_link_libraries(midiview openlase ${ALSA_LIBRARIES})
install(TARGETS midiview DESTINATION bin)
else()
message(STATUS "Will NOT build midiview (ALSA missing)")
endif()

add_executable(harp harp.c)
target_link_libraries(harp openlase)
install(TARGETS harp DESTINATION bin)

#add_subdirectory(27c3_slides)

Expand Down
122 changes: 122 additions & 0 deletions examples/show-text.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* show-text.c Copyright (C) 2013 Kamal Mostafa <kamal@whence.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "libol.h"
#include "text.h"

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <jack/jack.h>
#include <math.h>


void
draw_text_frame( Font *font, float height, char *text )
{
float width;
olLoadIdentity3();
olLoadIdentity();
width = olGetStringWidth(font, height, text);
olDrawString(font, -width/2, height/2, height, C_WHITE, text);
}


int main (int argc, char *argv[])
{
if ( argc < 2 || argc > 3) {
fprintf(stderr,
"usage: show-text {fontname} ['Text to Render']\n"
" fontname - a Hershey font name (e.g. gothiceng) or 'default'\n"
);
return 1;
}
char *fontname = argv[1];
char *text = NULL;

if ( argc == 3 )
text = argv[2];


OLRenderParams params;

memset(&params, 0, sizeof params);
params.rate = 48000;
params.on_speed = 1.0/100.0;
params.off_speed = 2.0/100.0;
params.start_wait = 8;
params.start_dwell = 7; // helps slow turn-on
params.curve_dwell = 0;
params.corner_dwell = 8;
params.curve_angle = cosf(10.0*(M_PI/180.0)); // 10 deg
params.end_dwell = 3;
params.end_wait = 10; // helps slow turn-off
params.snap = 1/100000.0;
params.render_flags = RENDER_GRAYSCALE;
params.render_flags |= RENDER_NOREORDER;
params.flatness = 0.0000001; // for default font

if(olInit(3, 30000) < 0)
return 1;

olSetRenderParams(&params);

olFontType fonttype;
if ( strcasecmp(fontname,"default") == 0 )
fonttype = OL_FONT_DEFAULT;
else
fonttype = OL_FONT_HERSHEY;

Font *font = olGetFont(fonttype, fontname);
if ( ! font ) {
perror(fontname);
return 1;
}


float height = 0.3;
if ( text ) {

draw_text_frame(font, height, text);
olRenderFrame(120);

printf("Hit Enter to quit...\n");
fflush(stdout);
getchar();

} else {

char buf[1024];
while ( fgets(buf, sizeof(buf), stdin) ) {
int n = strlen(buf);
if ( n == 0 )
continue;
if ( buf[n-1] == '\n' )
buf[--n] = 0;
draw_text_frame(font, height, buf);
olRenderFrame(120);
usleep(n*250000);
}

}

olShutdown();
exit (0);
}

141 changes: 141 additions & 0 deletions examples/spin-text.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* spin-text.c Copyright (C) 2013 Kamal Mostafa <kamal@whence.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "libol.h"
#include "text.h"

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <jack/jack.h>
#include <math.h>


void
draw_spinning_glyph( float x, float y, float rot, Font *font, float fonth, char c )
{
float w = olGetCharWidth(font, fonth, c);
olPushMatrix3();

olRotate3Y(rot);

olDrawChar(font,
//-(4*w0) + i*w0 + (w0-w)/2,
-w/2,
y,
fonth, C_WHITE, c);

olPopMatrix3();

}



int main (int argc, char *argv[])
{
if ( argc < 2 ) {
fprintf(stderr,
"usage: spin-text {fontname} ['Text to Render']\n"
" fontname - a Hershey font name (e.g. gothiceng) or 'default'\n"
);
return 1;
}
char *fontname = argv[1];


OLRenderParams params;

memset(&params, 0, sizeof params);
params.rate = 48000;
params.on_speed = 2.0/100.0;
params.off_speed = 2.0/100.0;
params.start_wait = 8;
params.start_dwell = 7; // helps slow turn-on
params.curve_dwell = 0;
params.corner_dwell = 8;
params.curve_angle = cosf(10.0*(M_PI/180.0)); // 10 deg
params.end_dwell = 3;
params.end_wait = 10; // helps slow turn-off
params.snap = 1/100000.0;
params.render_flags = RENDER_GRAYSCALE;
params.render_flags |= RENDER_NOREORDER;
params.flatness = 0.0000001; // for default font

if(olInit(3, 30000) < 0)
return 1;

olSetRenderParams(&params);

float mytime = 0;
float ftime;

int frames = 0;

olFontType fonttype;
if ( strcasecmp(fontname,"default") == 0 )
fonttype = OL_FONT_DEFAULT;
else
fonttype = OL_FONT_HERSHEY;

Font *font = olGetFont(fonttype, fontname);
if ( ! font ) {
perror(fontname);
return 1;
}


float rflip = M_PI;
float r0 = 0.0;

int spintime = 100;

const char *s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ( argc == 3 )
s = argv[2];

const char *p = s;
char c = *p;
while(1) {
olLoadIdentity3();
olLoadIdentity();

if ( frames % (spintime/2) == (spintime/4) ) {
if ( *p == 0 )
p = s;
c = *p++;
r0 = ( r0 == 0.0 ) ? rflip : 0.0;
}

float rot = (frames % spintime) * M_PI * 2 / spintime - r0;
draw_spinning_glyph(-1.0, 1.0, rot, font, 1.6, c);

ftime = olRenderFrame(60);
frames++;
mytime += ftime;
if ( (frames % 10) == 0 ) {
printf("Frame time: %3.0f msec FPS: %4.1f\r",
ftime*1000, frames/mytime);
fflush(stdout);
}
}

olShutdown();
exit (0);
}

Loading