Initial commit
This commit is contained in:
commit
25f0907c78
30 changed files with 7979 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
build
|
||||
*~
|
33
CMakeLists.txt
Normal file
33
CMakeLists.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
# OpenLase - a realtime laser graphics toolkit
|
||||
#
|
||||
# Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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
|
||||
#
|
||||
|
||||
PROJECT(openlase)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/Modules/")
|
||||
|
||||
find_package(Qt4 REQUIRED)
|
||||
find_package(JACK REQUIRED)
|
||||
|
||||
set(CMAKE_C_FLAGS "-Wall -O3 -g")
|
||||
|
||||
add_subdirectory (libol)
|
||||
add_subdirectory (output)
|
||||
add_subdirectory (tools)
|
||||
add_subdirectory (examples)
|
32
Modules/FindJACK.cmake
Normal file
32
Modules/FindJACK.cmake
Normal file
|
@ -0,0 +1,32 @@
|
|||
# - Try to find JACK
|
||||
# Once done, this will define
|
||||
#
|
||||
# JACK_FOUND - system has JACK
|
||||
# JACK_INCLUDE_DIRS - the JACK include directories
|
||||
# JACK_LIBRARIES - link these to use JACK
|
||||
|
||||
include(LibFindMacros)
|
||||
|
||||
# Dependencies
|
||||
|
||||
set(JACK_PKGCONF_INCLUDE_DIRS /usr/include)
|
||||
set(JACK_PKGCONF_LIBRARY_DIRS /usr/lib)
|
||||
set(JACK_LIBRARY_NAME jack)
|
||||
|
||||
# Include dir
|
||||
find_path(JACK_INCLUDE_DIR
|
||||
NAMES jack/jack.h
|
||||
PATHS ${JACK_PKGCONF_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Finally the library itself
|
||||
find_library(JACK_LIBRARY
|
||||
NAMES ${JACK_LIBRARY_NAME}
|
||||
PATHS ${JACK_PKGCONF_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
# Set the include dir variables and the libraries and let libfind_process do the rest.
|
||||
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
|
||||
set(JACK_PROCESS_INCLUDES JACK_INCLUDE_DIR)
|
||||
set(JACK_PROCESS_LIBS JACK_LIBRARY)
|
||||
libfind_process(JACK)
|
99
Modules/LibFindMacros.cmake
Normal file
99
Modules/LibFindMacros.cmake
Normal file
|
@ -0,0 +1,99 @@
|
|||
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
|
||||
# used for the current package. For this to work, the first parameter must be the
|
||||
# prefix of the current package, then the prefix of the new package etc, which are
|
||||
# passed to find_package.
|
||||
macro (libfind_package PREFIX)
|
||||
set (LIBFIND_PACKAGE_ARGS ${ARGN})
|
||||
if (${PREFIX}_FIND_QUIETLY)
|
||||
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
|
||||
endif (${PREFIX}_FIND_QUIETLY)
|
||||
if (${PREFIX}_FIND_REQUIRED)
|
||||
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
|
||||
endif (${PREFIX}_FIND_REQUIRED)
|
||||
find_package(${LIBFIND_PACKAGE_ARGS})
|
||||
endmacro (libfind_package)
|
||||
|
||||
# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
|
||||
# where they added pkg_check_modules. Consequently I need to support both in my scripts
|
||||
# to avoid those deprecated warnings. Here's a helper that does just that.
|
||||
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
|
||||
macro (libfind_pkg_check_modules PREFIX PKGNAME)
|
||||
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||
include(UsePkgConfig)
|
||||
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
|
||||
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||
find_package(PkgConfig)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(${PREFIX} ${PKGNAME})
|
||||
endif (PKG_CONFIG_FOUND)
|
||||
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||
endmacro (libfind_pkg_check_modules)
|
||||
|
||||
# Do the final processing once the paths have been detected.
|
||||
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
|
||||
# all the variables, each of which contain one include directory.
|
||||
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
|
||||
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
|
||||
# Also handles errors in case library detection was required, etc.
|
||||
macro (libfind_process PREFIX)
|
||||
# Skip processing if already processed during this run
|
||||
if (NOT ${PREFIX}_FOUND)
|
||||
# Start with the assumption that the library was found
|
||||
set (${PREFIX}_FOUND TRUE)
|
||||
|
||||
# Process all includes and set _FOUND to false if any are missing
|
||||
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
|
||||
if (${i})
|
||||
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
|
||||
mark_as_advanced(${i})
|
||||
else (${i})
|
||||
set (${PREFIX}_FOUND FALSE)
|
||||
endif (${i})
|
||||
endforeach (i)
|
||||
|
||||
# Process all libraries and set _FOUND to false if any are missing
|
||||
foreach (i ${${PREFIX}_PROCESS_LIBS})
|
||||
if (${i})
|
||||
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
|
||||
mark_as_advanced(${i})
|
||||
else (${i})
|
||||
set (${PREFIX}_FOUND FALSE)
|
||||
endif (${i})
|
||||
endforeach (i)
|
||||
|
||||
# Print message and/or exit on fatal error
|
||||
if (${PREFIX}_FOUND)
|
||||
if (NOT ${PREFIX}_FIND_QUIETLY)
|
||||
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
|
||||
endif (NOT ${PREFIX}_FIND_QUIETLY)
|
||||
else (${PREFIX}_FOUND)
|
||||
if (${PREFIX}_FIND_REQUIRED)
|
||||
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
|
||||
message("${i}=${${i}}")
|
||||
endforeach (i)
|
||||
message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
|
||||
endif (${PREFIX}_FIND_REQUIRED)
|
||||
endif (${PREFIX}_FOUND)
|
||||
endif (NOT ${PREFIX}_FOUND)
|
||||
endmacro (libfind_process)
|
||||
|
||||
macro(libfind_library PREFIX basename)
|
||||
set(TMP "")
|
||||
if(MSVC80)
|
||||
set(TMP -vc80)
|
||||
endif(MSVC80)
|
||||
if(MSVC90)
|
||||
set(TMP -vc90)
|
||||
endif(MSVC90)
|
||||
set(${PREFIX}_LIBNAMES ${basename}${TMP})
|
||||
if(${ARGC} GREATER 2)
|
||||
set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
|
||||
string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
|
||||
set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
|
||||
endif(${ARGC} GREATER 2)
|
||||
find_library(${PREFIX}_LIBRARY
|
||||
NAMES ${${PREFIX}_LIBNAMES}
|
||||
PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
|
||||
)
|
||||
endmacro(libfind_library)
|
||||
|
29
examples/CMakeLists.txt
Normal file
29
examples/CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
# OpenLase - a realtime laser graphics toolkit
|
||||
#
|
||||
# Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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_directories (${CMAKE_SOURCE_DIR}/include)
|
||||
link_directories (${CMAKE_BINARY_DIR}/libol)
|
||||
|
||||
add_executable(circlescope circlescope.c)
|
||||
target_link_libraries(circlescope ${JACK_LIBRARIES} m)
|
||||
|
||||
add_executable(simple simple.c)
|
||||
target_link_libraries(simple openlase)
|
||||
|
||||
add_executable(pong pong.c)
|
||||
target_link_libraries(pong openlase)
|
134
examples/circlescope.c
Normal file
134
examples/circlescope.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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
|
||||
*/
|
||||
|
||||
#define _BSD_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <jack/jack.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef jack_default_audio_sample_t sample_t;
|
||||
typedef jack_nframes_t nframes_t;
|
||||
|
||||
jack_port_t *in_l;
|
||||
jack_port_t *in_r;
|
||||
jack_port_t *out_x;
|
||||
jack_port_t *out_y;
|
||||
jack_port_t *out_w;
|
||||
|
||||
nframes_t rate;
|
||||
|
||||
sample_t max_size = 1.0f;
|
||||
sample_t min_size = 0.2f;
|
||||
sample_t boost = 8;
|
||||
|
||||
//float w = 110 * (2*M_PI);
|
||||
float w = 523.251131f / 4.0f * (2*M_PI) / 1;
|
||||
float pos = 0.0f;
|
||||
|
||||
#define MAX(a,b) (((a)<(b))?(b):(a))
|
||||
#define MIN(a,b) (((a)>(b))?(b):(a))
|
||||
|
||||
int process (nframes_t nframes, void *arg)
|
||||
{
|
||||
sample_t *i_l = (sample_t *) jack_port_get_buffer (in_l, nframes);
|
||||
sample_t *i_r = (sample_t *) jack_port_get_buffer (in_r, nframes);
|
||||
sample_t *o_x = (sample_t *) jack_port_get_buffer (out_x, nframes);
|
||||
sample_t *o_y = (sample_t *) jack_port_get_buffer (out_y, nframes);
|
||||
sample_t *o_w = (sample_t *) jack_port_get_buffer (out_w, nframes);
|
||||
|
||||
nframes_t frm;
|
||||
for (frm = 0; frm < nframes; frm++) {
|
||||
sample_t val = (*i_l++ + *i_r++) / 2;
|
||||
|
||||
val *= boost;
|
||||
val = MAX(MIN(val,1.0f),-1.0f);
|
||||
val = val * 0.5f + 0.5f;
|
||||
val *= (max_size - min_size);
|
||||
val += min_size;
|
||||
|
||||
*o_w++ = 1.0f;
|
||||
*o_x++ = cosf(pos) * val;
|
||||
*o_y++ = sinf(pos) * val;
|
||||
|
||||
pos += w / rate;
|
||||
while(pos >= (2*M_PI)) {
|
||||
pos -= (2*M_PI);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bufsize (nframes_t nframes, void *arg)
|
||||
{
|
||||
printf ("the maximum buffer size is now %u\n", nframes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int srate (nframes_t nframes, void *arg)
|
||||
{
|
||||
rate = nframes;
|
||||
printf ("Sample rate: %u/sec\n", nframes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jack_shutdown (void *arg)
|
||||
{
|
||||
exit (1);
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
jack_client_t *client;
|
||||
|
||||
if ((client = jack_client_new ("circlescope")) == 0) {
|
||||
fprintf (stderr, "jack server not running?\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
jack_set_process_callback (client, process, 0);
|
||||
jack_set_buffer_size_callback (client, bufsize, 0);
|
||||
jack_set_sample_rate_callback (client, srate, 0);
|
||||
jack_on_shutdown (client, jack_shutdown, 0);
|
||||
|
||||
in_l = jack_port_register (client, "in_l", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
|
||||
in_r = jack_port_register (client, "in_r", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
|
||||
out_x = jack_port_register (client, "out_x", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
|
||||
out_y = jack_port_register (client, "out_y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
|
||||
out_w = jack_port_register (client, "out_w", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
|
||||
|
||||
if (jack_activate (client)) {
|
||||
fprintf (stderr, "cannot activate client");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (1)
|
||||
sleep(1);
|
||||
jack_client_close (client);
|
||||
exit (0);
|
||||
}
|
||||
|
317
examples/pong.c
Normal file
317
examples/pong.c
Normal file
|
@ -0,0 +1,317 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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 <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <jack/jack.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define DIGW 0.06
|
||||
#define DIGH 0.12
|
||||
|
||||
/*
|
||||
Pong! Input is yet another hack. It's meant to be used with one or two PS3
|
||||
controllers connected via event devices. Dealing with permissions is left as
|
||||
an exercise to the reader. Will probably work with other similar input devices.
|
||||
|
||||
Also, the digit code dates to before I had fonts going. However, the default
|
||||
font currently has no digits, so it has a reason to exist for now.
|
||||
*/
|
||||
|
||||
void digit(float x, float y, int d, uint32_t color)
|
||||
{
|
||||
olPushMatrix();
|
||||
olTranslate(x,y);
|
||||
olScale(DIGW*0.8,DIGH*0.4);
|
||||
olBegin(OL_LINESTRIP);
|
||||
switch(d) {
|
||||
case 0:
|
||||
olVertex(0,0,color);
|
||||
olVertex(0,2,color);
|
||||
olVertex(1,2,color);
|
||||
olVertex(1,0,color);
|
||||
olVertex(0,0,color);
|
||||
break;
|
||||
case 1:
|
||||
olVertex(0.5,0,color);
|
||||
olVertex(0.5,2,color);
|
||||
break;
|
||||
case 2:
|
||||
olVertex(0,0,color);
|
||||
olVertex(1,0,color);
|
||||
olVertex(1,1,color);
|
||||
olVertex(0,1,color);
|
||||
olVertex(0,2,color);
|
||||
olVertex(1,2,color);
|
||||
break;
|
||||
case 3:
|
||||
olVertex(0,0,color);
|
||||
olVertex(1,0,color);
|
||||
olVertex(1,1,color);
|
||||
olVertex(0,1,color);
|
||||
olVertex(1,1,C_BLACK);
|
||||
olVertex(1,2,color);
|
||||
olVertex(0,2,color);
|
||||
break;
|
||||
case 4:
|
||||
olVertex(0,0,color);
|
||||
olVertex(0,1,color);
|
||||
olVertex(1,1,color);
|
||||
olVertex(1,0,C_BLACK);
|
||||
olVertex(1,2,color);
|
||||
break;
|
||||
case 5:
|
||||
olVertex(1,0,color);
|
||||
olVertex(0,0,color);
|
||||
olVertex(0,1,color);
|
||||
olVertex(1,1,color);
|
||||
olVertex(1,2,color);
|
||||
olVertex(0,2,color);
|
||||
break;
|
||||
case 6:
|
||||
olVertex(1,0,color);
|
||||
olVertex(0,0,color);
|
||||
olVertex(0,2,color);
|
||||
olVertex(1,2,color);
|
||||
olVertex(1,1,color);
|
||||
olVertex(0,1,color);
|
||||
break;
|
||||
case 7:
|
||||
olVertex(0,0,color);
|
||||
olVertex(1,0,color);
|
||||
olVertex(1,2,color);
|
||||
break;
|
||||
case 8:
|
||||
olVertex(0,0,color);
|
||||
olVertex(0,2,color);
|
||||
olVertex(1,2,color);
|
||||
olVertex(1,0,color);
|
||||
olVertex(0,0,color);
|
||||
olVertex(0,1,C_BLACK);
|
||||
olVertex(1,1,color);
|
||||
break;
|
||||
case 9:
|
||||
olVertex(1,1,color);
|
||||
olVertex(0,1,color);
|
||||
olVertex(0,0,color);
|
||||
olVertex(1,0,color);
|
||||
olVertex(1,2,color);
|
||||
break;
|
||||
}
|
||||
olEnd();
|
||||
olPopMatrix();
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
OLRenderParams params;
|
||||
|
||||
int in1_fd;
|
||||
int in2_fd;
|
||||
|
||||
in1_fd = open(argv[1], O_RDONLY | O_NONBLOCK);
|
||||
in2_fd = open(argv[2], O_RDONLY | O_NONBLOCK);
|
||||
|
||||
memset(¶ms, 0, sizeof params);
|
||||
params.rate = 48000;
|
||||
params.on_speed = 2.0/100.0;
|
||||
params.off_speed = 2.0/20.0;
|
||||
params.start_wait = 12;
|
||||
params.start_dwell = 3;
|
||||
params.curve_dwell = 0;
|
||||
params.corner_dwell = 12;
|
||||
params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg
|
||||
params.end_dwell = 3;
|
||||
params.end_wait = 10;
|
||||
params.snap = 1/100000.0;
|
||||
params.render_flags = RENDER_GRAYSCALE;
|
||||
|
||||
if(olInit(3, 30000) < 0)
|
||||
return 1;
|
||||
olSetRenderParams(¶ms);
|
||||
|
||||
float time = 0;
|
||||
float ftime;
|
||||
|
||||
int frames = 0;
|
||||
|
||||
#define TOP 0.2
|
||||
#define BOTTOM 0.8
|
||||
#define LEFT 0.07
|
||||
#define RIGHT 0.93
|
||||
#define WIDTH (RIGHT-LEFT)
|
||||
#define HEIGHT (BOTTOM-TOP)
|
||||
#define PH 0.12
|
||||
#define PW 0.03
|
||||
#define BW 0.02
|
||||
#define BH 0.02
|
||||
|
||||
float p1 = (HEIGHT-PH)/2;
|
||||
float p2 = (HEIGHT-PH)/2;
|
||||
float bx = 0;
|
||||
float by = HEIGHT/2;
|
||||
float bdx = 0.4;
|
||||
float bdy = 0.2;
|
||||
|
||||
int score1 = 0;
|
||||
int score2 = 0;
|
||||
|
||||
float b1pos = 0, b2pos = 0;
|
||||
float eb1pos,eb2pos;
|
||||
|
||||
while(1) {
|
||||
while(1) {
|
||||
struct input_event ev;
|
||||
if (read(in1_fd, &ev, sizeof(ev)) != sizeof(ev))
|
||||
break;
|
||||
if (ev.type != EV_ABS)
|
||||
continue;
|
||||
if (ev.code == ABS_Y)
|
||||
b1pos = (ev.value - 128) / 255.0;
|
||||
else if (ev.code == 5)
|
||||
b2pos = (ev.value - 128) / 255.0;
|
||||
}
|
||||
while(1) {
|
||||
struct input_event ev;
|
||||
if (read(in2_fd, &ev, sizeof(ev)) != sizeof(ev))
|
||||
break;
|
||||
if (ev.type != EV_ABS)
|
||||
continue;
|
||||
if (ev.code == ABS_Y)
|
||||
b2pos = (ev.value - 128) / 255.0;
|
||||
}
|
||||
|
||||
if (b1pos > 0.1)
|
||||
eb1pos = b1pos - 0.1;
|
||||
else if (b1pos < -0.1)
|
||||
eb1pos = b1pos + 0.1;
|
||||
else
|
||||
eb1pos = 0;
|
||||
|
||||
if (b2pos > 0.1)
|
||||
eb2pos = b2pos - 0.1;
|
||||
else if (b2pos < -0.1)
|
||||
eb2pos = b2pos + 0.1;
|
||||
else
|
||||
eb2pos = 0;
|
||||
|
||||
eb1pos *= 2;
|
||||
eb2pos *= 2;
|
||||
|
||||
printf("ebpos:%f %f\n", eb1pos, eb2pos);
|
||||
|
||||
|
||||
olLoadIdentity();
|
||||
olTranslate(-1,1);
|
||||
olScale(2,-2);
|
||||
// window is now 0.0-1.0 X and Y, Y going down)
|
||||
olRect(0, TOP, 1, BOTTOM, C_WHITE);
|
||||
olRect(LEFT-PW, p1+TOP, LEFT, p1+TOP+PH, C_WHITE);
|
||||
olRect(RIGHT, p2+TOP, RIGHT+PW, p2+TOP+PH, C_WHITE);
|
||||
olRect(LEFT+bx, TOP+by, LEFT+bx+BW, TOP+by+BW, C_WHITE);
|
||||
olLine((LEFT+RIGHT)/2, TOP, (LEFT+RIGHT)/2, BOTTOM, C_GREY(50));
|
||||
|
||||
olTranslate(0,0.08);
|
||||
if (score1 >= 100)
|
||||
digit(0,0,score1/100,C_WHITE);
|
||||
if (score1 >= 10)
|
||||
digit(DIGW,0,score1/10%10,C_WHITE);
|
||||
digit(2*DIGW,0,score1%10,C_WHITE);
|
||||
|
||||
if (score2 >= 100)
|
||||
digit(1-3*DIGW,0,score2/100,C_WHITE);
|
||||
if (score2 >= 10)
|
||||
digit(1-2*DIGW,0,score2/10%10,C_WHITE);
|
||||
digit(1-1*DIGW,0,score2%10,C_WHITE);
|
||||
|
||||
ftime = olRenderFrame(60);
|
||||
|
||||
bx += ftime*bdx;
|
||||
by += ftime*bdy;
|
||||
|
||||
if (by > HEIGHT - BH) {
|
||||
bdy = -bdy;
|
||||
by += 2*ftime*bdy;
|
||||
} else if (by < 0) {
|
||||
bdy = -bdy;
|
||||
by += 2*ftime*bdy;
|
||||
}
|
||||
|
||||
p1 += ftime*eb1pos;
|
||||
if (p1 < 0)
|
||||
p1 = 0;
|
||||
if (p1 > HEIGHT-PH)
|
||||
p1 = HEIGHT-PH;
|
||||
|
||||
|
||||
p2 += ftime*eb2pos;
|
||||
if (p2 < 0)
|
||||
p2 = 0;
|
||||
if (p2 > HEIGHT-PH)
|
||||
p2 = HEIGHT-PH;
|
||||
|
||||
if (bx < 0) {
|
||||
if (by < p1-BH || by > p1+PH) {
|
||||
if (bx < -BW) {
|
||||
by = p2 + PH/2 - BH/2;
|
||||
bx = WIDTH - BW;
|
||||
bdx = -0.4;
|
||||
bdy = 0.2;
|
||||
score2++;
|
||||
}
|
||||
} else {
|
||||
bdx = -bdx;
|
||||
bx += 2*ftime*bdx;
|
||||
}
|
||||
} else if (bx > WIDTH - BW) {
|
||||
if (by < p2-BH || by > p2+PH) {
|
||||
if (bx > WIDTH) {
|
||||
by = p1 + PH/2 - BH/2;
|
||||
bx = 0;
|
||||
bdx = 0.4;
|
||||
bdy = 0.2;
|
||||
score1++;
|
||||
}
|
||||
} else {
|
||||
bdx = -bdx;
|
||||
bx += 2*ftime*bdx;
|
||||
}
|
||||
}
|
||||
|
||||
bdx *= powf(1.1, ftime);
|
||||
|
||||
frames++;
|
||||
time += ftime;
|
||||
printf("Frame time: %f, FPS:%f\n", ftime, frames/time);
|
||||
}
|
||||
|
||||
olShutdown();
|
||||
exit (0);
|
||||
}
|
||||
|
115
examples/simple.c
Normal file
115
examples/simple.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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 <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <jack/jack.h>
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
Simple demonstration, shows two cubes in perspective 3D.
|
||||
*/
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
OLRenderParams params;
|
||||
|
||||
memset(¶ms, 0, sizeof params);
|
||||
params.rate = 48000;
|
||||
params.on_speed = 2.0/100.0;
|
||||
params.off_speed = 2.0/20.0;
|
||||
params.start_wait = 8;
|
||||
params.start_dwell = 3;
|
||||
params.curve_dwell = 0;
|
||||
params.corner_dwell = 8;
|
||||
params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg
|
||||
params.end_dwell = 3;
|
||||
params.end_wait = 7;
|
||||
params.snap = 1/100000.0;
|
||||
params.render_flags = RENDER_GRAYSCALE;
|
||||
|
||||
if(olInit(3, 30000) < 0)
|
||||
return 1;
|
||||
|
||||
olSetRenderParams(¶ms);
|
||||
|
||||
float time = 0;
|
||||
float ftime;
|
||||
int i,j;
|
||||
|
||||
int frames = 0;
|
||||
|
||||
while(1) {
|
||||
olLoadIdentity3();
|
||||
olLoadIdentity();
|
||||
olPerspective(24, 1, 1, 100);
|
||||
olTranslate3(0, 0, 4);
|
||||
|
||||
for(i=0; i<2; i++) {
|
||||
olScale3(0.6, 0.6, 0.6);
|
||||
|
||||
olRotate3Z(time * M_PI * 0.1);
|
||||
olRotate3Y(time * M_PI * 0.8);
|
||||
olRotate3X(time * M_PI * 0.73);
|
||||
|
||||
olBegin(OL_LINESTRIP);
|
||||
olVertex3(-1, -1, -1, C_WHITE);
|
||||
olVertex3( 1, -1, -1, C_WHITE);
|
||||
olVertex3( 1, 1, -1, C_WHITE);
|
||||
olVertex3(-1, 1, -1, C_WHITE);
|
||||
olVertex3(-1, -1, -1, C_WHITE);
|
||||
olVertex3(-1, -1, 1, C_WHITE);
|
||||
olEnd();
|
||||
|
||||
olBegin(OL_LINESTRIP);
|
||||
olVertex3( 1, 1, 1, C_WHITE);
|
||||
olVertex3(-1, 1, 1, C_WHITE);
|
||||
olVertex3(-1, -1, 1, C_WHITE);
|
||||
olVertex3( 1, -1, 1, C_WHITE);
|
||||
olVertex3( 1, 1, 1, C_WHITE);
|
||||
olVertex3( 1, 1, -1, C_WHITE);
|
||||
olEnd();
|
||||
|
||||
olBegin(OL_LINESTRIP);
|
||||
olVertex3( 1, -1, -1, C_WHITE);
|
||||
olVertex3( 1, -1, 1, C_WHITE);
|
||||
olEnd();
|
||||
|
||||
olBegin(OL_LINESTRIP);
|
||||
olVertex3(-1, 1, 1, C_WHITE);
|
||||
olVertex3(-1, 1, -1, C_WHITE);
|
||||
olEnd();
|
||||
|
||||
}
|
||||
|
||||
ftime = olRenderFrame(60);
|
||||
frames++;
|
||||
time += ftime;
|
||||
printf("Frame time: %f, FPS:%f\n", ftime, frames/time);
|
||||
}
|
||||
|
||||
olShutdown();
|
||||
exit (0);
|
||||
}
|
||||
|
49
include/ilda.h
Normal file
49
include/ilda.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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
|
||||
*/
|
||||
|
||||
#ifndef ILD_H
|
||||
#define ILD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
int is_blank;
|
||||
uint8_t color;
|
||||
} IldaPoint;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
float min_x;
|
||||
float max_x;
|
||||
float min_y;
|
||||
float max_y;
|
||||
float min_z;
|
||||
float max_z;
|
||||
IldaPoint *points;
|
||||
} IldaFile;
|
||||
|
||||
IldaFile *olLoadIlda(const char *filename);
|
||||
void olDrawIlda(IldaFile *ild);
|
||||
void olDrawIlda3D(IldaFile *ild);
|
||||
void olFreeIlda(IldaFile *ild);
|
||||
|
||||
#endif
|
133
include/libol.h
Normal file
133
include/libol.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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
|
||||
*/
|
||||
|
||||
#ifndef LIBOL_H
|
||||
#define LIBOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
OL_LINESTRIP,
|
||||
OL_BEZIERSTRIP,
|
||||
OL_POINTS
|
||||
};
|
||||
|
||||
#define C_RED 0xff0000
|
||||
#define C_GREEN 0x00ff00
|
||||
#define C_BLUE 0x0000ff
|
||||
#define C_WHITE 0xffffff
|
||||
#define C_BLACK 0x000000
|
||||
|
||||
#define C_GREY(x) (0x010101 * ((int)(x)))
|
||||
|
||||
enum {
|
||||
RENDER_GRAYSCALE = 1,
|
||||
RENDER_NOREORDER = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int rate;
|
||||
float on_speed;
|
||||
float off_speed;
|
||||
int start_wait;
|
||||
int start_dwell;
|
||||
int curve_dwell;
|
||||
int corner_dwell;
|
||||
int end_dwell;
|
||||
int end_wait;
|
||||
float curve_angle;
|
||||
float flatness;
|
||||
float snap;
|
||||
int render_flags;
|
||||
int min_length;
|
||||
int max_framelen;
|
||||
} OLRenderParams;
|
||||
|
||||
typedef struct {
|
||||
int points;
|
||||
int resampled_points;
|
||||
int resampled_blacks;
|
||||
int padding_points;
|
||||
} OLFrameInfo;
|
||||
|
||||
int olInit(int buffer_count, int max_points);
|
||||
|
||||
void olSetRenderParams(OLRenderParams *params);
|
||||
|
||||
typedef void (*AudioCallbackFunc)(float *leftbuf, float *rightbuf, int samples);
|
||||
|
||||
void olSetAudioCallback(AudioCallbackFunc f);
|
||||
|
||||
void olLoadIdentity(void);
|
||||
void olPushMatrix(void);
|
||||
void olPopMatrix(void);
|
||||
|
||||
void olMultMatrix(float m[9]);
|
||||
void olRotate(float theta);
|
||||
void olTranslate(float x, float y);
|
||||
void olScale(float sx, float sy);
|
||||
|
||||
void olLoadIdentity3(void);
|
||||
void olPushMatrix3(void);
|
||||
void olPopMatrix3(void);
|
||||
|
||||
void olMultMatrix3(float m[16]);
|
||||
void olRotate3X(float theta);
|
||||
void olRotate3Y(float theta);
|
||||
void olRotate3Z(float theta);
|
||||
void olTranslate3(float x, float y, float z);
|
||||
void olScale3(float sx, float sy, float sz);
|
||||
|
||||
void olFrustum (float left, float right, float bot, float ttop, float near, float far);
|
||||
void olPerspective(float fovy, float aspect, float zNear, float zFar);
|
||||
|
||||
void olResetColor(void);
|
||||
void olMultColor(uint32_t color);
|
||||
void olPushColor(void);
|
||||
void olPopColor(void);
|
||||
|
||||
void olBegin(int prim);
|
||||
void olVertex(float x, float y, uint32_t color);
|
||||
void olVertex3(float x, float y, float z, uint32_t color);
|
||||
void olEnd(void);
|
||||
|
||||
void olTransformVertex3(float *x, float *y, float *z);
|
||||
|
||||
typedef void (*ShaderFunc)(float *x, float *y, uint32_t *color);
|
||||
typedef void (*Shader3Func)(float *x, float *y, float *z, uint32_t *color);
|
||||
|
||||
void olSetVertexPreShader(ShaderFunc f);
|
||||
void olSetVertexShader(ShaderFunc f);
|
||||
void olSetVertex3Shader(Shader3Func f);
|
||||
|
||||
void olSetPixelShader(ShaderFunc f);
|
||||
|
||||
void olRect(float x1, float y1, float x2, float y2, uint32_t color);
|
||||
void olLine(float x1, float y1, float x2, float y2, uint32_t color);
|
||||
void olDot(float x, float y, int points, uint32_t color);
|
||||
|
||||
float olRenderFrame(int max_fps);
|
||||
|
||||
void olGetFrameInfo(OLFrameInfo *info);
|
||||
|
||||
void olShutdown(void);
|
||||
|
||||
void olSetScissor (float x0, float y0, float x1, float y1);
|
||||
|
||||
#endif
|
50
include/text.h
Normal file
50
include/text.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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
|
||||
*/
|
||||
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
int flag;
|
||||
float x;
|
||||
float y;
|
||||
} FontPoint;
|
||||
|
||||
typedef struct {
|
||||
float width;
|
||||
const FontPoint *points;
|
||||
} FontChar;
|
||||
|
||||
typedef struct {
|
||||
float height;
|
||||
float overlap;
|
||||
const FontChar *chars;
|
||||
} Font;
|
||||
|
||||
Font *olGetDefaultFont(void);
|
||||
float olGetCharWidth(Font *fnt, char c);
|
||||
float olGetStringWidth(Font *fnt, float height, const char *s);
|
||||
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);
|
||||
|
||||
#endif
|
29
libol/CMakeLists.txt
Normal file
29
libol/CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
# OpenLase - a realtime laser graphics toolkit
|
||||
#
|
||||
# Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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_directories (${CMAKE_SOURCE_DIR}/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_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c
|
||||
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)
|
221
libol/ilda.c
Normal file
221
libol/ilda.c
Normal file
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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 "ilda.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
static inline uint16_t swapshort(uint16_t v) {
|
||||
return (v >> 8) | (v << 8);
|
||||
}
|
||||
# define MAGIC 0x41444C49
|
||||
#else
|
||||
static inline uint16_t swapshort(uint16_t v) {
|
||||
return v;
|
||||
}
|
||||
# define MAGIC 0x494C4441
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct ilda_hdr {
|
||||
uint32_t magic;
|
||||
uint8_t pad1[3];
|
||||
uint8_t format;
|
||||
char name[8];
|
||||
char company[8];
|
||||
uint16_t count;
|
||||
uint16_t frameno;
|
||||
uint16_t framecount;
|
||||
uint8_t scanner;
|
||||
uint8_t pad2;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct icoord3d {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
uint8_t state;
|
||||
uint8_t color;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct icoord2d {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
uint8_t state;
|
||||
uint8_t color;
|
||||
} __attribute__((packed));
|
||||
|
||||
IldaFile *olLoadIlda(const char *filename)
|
||||
{
|
||||
int i;
|
||||
FILE *fd = fopen(filename, "rb");
|
||||
IldaFile *ild;
|
||||
|
||||
if (!fd) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ild = malloc(sizeof(*ild));
|
||||
|
||||
memset(ild, 0, sizeof(*ild));
|
||||
|
||||
ild->min_x = 1.0;
|
||||
ild->min_y = 1.0;
|
||||
ild->min_z = 1.0;
|
||||
ild->max_x = -1.0;
|
||||
ild->max_y = -1.0;
|
||||
ild->max_z = -1.0;
|
||||
|
||||
while(!ild->count) {
|
||||
|
||||
struct ilda_hdr hdr;
|
||||
|
||||
if (fread(&hdr, sizeof(hdr), 1, fd) != 1) {
|
||||
fprintf(stderr, "ILDA: error while reading header\n");
|
||||
olFreeIlda(ild);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (hdr.magic != MAGIC) {
|
||||
fprintf(stderr, "ILDA: Invalid magic 0x%08x\n", hdr.magic);
|
||||
olFreeIlda(ild);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hdr.count = swapshort(hdr.count);
|
||||
hdr.frameno = swapshort(hdr.frameno);
|
||||
hdr.framecount = swapshort(hdr.framecount);
|
||||
|
||||
switch (hdr.format) {
|
||||
case 0:
|
||||
printf("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);
|
||||
if (fread(tmp3d, sizeof(struct icoord3d), hdr.count, fd) != hdr.count) {
|
||||
fprintf(stderr, "ILDA: error while reading frame\n");
|
||||
olFreeIlda(ild);
|
||||
return NULL;
|
||||
}
|
||||
for(i=0; i<hdr.count; i++) {
|
||||
ild->points[i].x = ((int16_t)swapshort(tmp3d[i].x)) / 32768.0f;
|
||||
ild->points[i].y = ((int16_t)swapshort(tmp3d[i].y)) / 32768.0f;
|
||||
ild->points[i].z = ((int16_t)swapshort(tmp3d[i].z)) / 32768.0f;
|
||||
ild->points[i].is_blank = !!(tmp3d[i].state & 0x40);
|
||||
ild->points[i].color = tmp3d[i].color;
|
||||
}
|
||||
free(tmp3d);
|
||||
ild->count = hdr.count;
|
||||
break;
|
||||
case 1:
|
||||
printf("Got 2D frame, %d points\n", hdr.count);
|
||||
ild->points = malloc(sizeof(IldaPoint) * hdr.count);
|
||||
struct icoord2d *tmp2d = malloc(sizeof(struct icoord2d) * hdr.count);
|
||||
if (fread(tmp2d, sizeof(struct icoord2d), hdr.count, fd) != hdr.count) {
|
||||
fprintf(stderr, "ILDA: error while reading frame\n");
|
||||
olFreeIlda(ild);
|
||||
return NULL;
|
||||
}
|
||||
for(i=0; i<hdr.count; i++) {
|
||||
ild->points[i].x = ((int16_t)swapshort(tmp2d[i].x)) / 32768.0f;
|
||||
ild->points[i].y = ((int16_t)swapshort(tmp2d[i].y)) / 32768.0f;
|
||||
ild->points[i].z = 0;
|
||||
ild->points[i].is_blank = !!(tmp2d[i].state & 0x40);
|
||||
ild->points[i].color = tmp2d[i].color;
|
||||
}
|
||||
free(tmp2d);
|
||||
ild->count = hdr.count;
|
||||
break;
|
||||
case 2:
|
||||
printf("ILDA: Got color palette section, %d entries\n", hdr.count);
|
||||
printf("ILDA: NOT SUPPORTED\n");
|
||||
olFreeIlda(ild);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
for(i=0; i<ild->count; i++) {
|
||||
if(ild->points[i].x > ild->max_x)
|
||||
ild->max_x = ild->points[i].x;
|
||||
if(ild->points[i].y > ild->max_y)
|
||||
ild->max_y = ild->points[i].y;
|
||||
if(ild->points[i].z > ild->max_z)
|
||||
ild->max_z = ild->points[i].z;
|
||||
if(ild->points[i].x < ild->min_x)
|
||||
ild->min_x = ild->points[i].x;
|
||||
if(ild->points[i].y < ild->min_y)
|
||||
ild->min_y = ild->points[i].y;
|
||||
if(ild->points[i].z < ild->min_z)
|
||||
ild->min_z = ild->points[i].z;
|
||||
}
|
||||
|
||||
return ild;
|
||||
}
|
||||
|
||||
void olDrawIlda(IldaFile *ild)
|
||||
{
|
||||
if (!ild)
|
||||
return;
|
||||
IldaPoint *p = ild->points;
|
||||
int i;
|
||||
olBegin(OL_POINTS);
|
||||
for (i = 0; i < ild->count; i++) {
|
||||
//printf("%f %f %f %d\n", p->x, p->y, p->z, p->is_blank);
|
||||
if (p->is_blank)
|
||||
olVertex(p->x, p->y, C_BLACK);
|
||||
else
|
||||
olVertex(p->x, p->y, C_WHITE);
|
||||
p++;
|
||||
}
|
||||
olEnd();
|
||||
}
|
||||
|
||||
void olDrawIlda3D(IldaFile *ild)
|
||||
{
|
||||
if (!ild)
|
||||
return;
|
||||
IldaPoint *p = ild->points;
|
||||
int i;
|
||||
olBegin(OL_POINTS);
|
||||
for (i = 0; i < ild->count; i++) {
|
||||
if (p->is_blank)
|
||||
olVertex3(p->x, p->y, p->z, C_BLACK);
|
||||
else
|
||||
olVertex3(p->x, p->y, p->z, C_WHITE);
|
||||
}
|
||||
olEnd();
|
||||
}
|
||||
|
||||
void olFreeIlda(IldaFile *ild)
|
||||
{
|
||||
if(ild->points)
|
||||
free(ild->points);
|
||||
free(ild);
|
||||
}
|
1328
libol/laserfont.svg
Normal file
1328
libol/laserfont.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 74 KiB |
1138
libol/libol.c
Normal file
1138
libol/libol.c
Normal file
File diff suppressed because it is too large
Load diff
101
libol/text.c
Normal file
101
libol/text.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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 <math.h>
|
||||
#include "libol.h"
|
||||
#include "text.h"
|
||||
|
||||
extern Font default_font;
|
||||
|
||||
Font *olGetDefaultFont(void)
|
||||
{
|
||||
return &default_font;
|
||||
}
|
||||
|
||||
float olGetCharWidth(Font *font, char c)
|
||||
{
|
||||
if (!font)
|
||||
return 0;
|
||||
return font->chars[(uint8_t)c].width / font->height;
|
||||
}
|
||||
|
||||
float olGetCharOverlap(Font *font, float height)
|
||||
{
|
||||
if (!font)
|
||||
return 0;
|
||||
float ratio = height / font->height;
|
||||
return font->overlap * ratio;
|
||||
}
|
||||
|
||||
float olDrawChar(Font *font, float x, float y, float height, uint32_t color, char c)
|
||||
{
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
const FontChar *chr = &font->chars[(uint8_t)c];
|
||||
const FontPoint *p = chr->points;
|
||||
|
||||
float ratio = height / font->height;
|
||||
|
||||
if (p) {
|
||||
|
||||
olBegin(OL_BEZIERSTRIP);
|
||||
|
||||
do {
|
||||
olVertex(x + p->x * ratio, y - p->y * ratio, color);
|
||||
if (p->flag == 1) {
|
||||
olEnd();
|
||||
olBegin(OL_BEZIERSTRIP);
|
||||
}
|
||||
} while ((p++)->flag != 2);
|
||||
|
||||
olEnd();
|
||||
}
|
||||
|
||||
return chr->width * ratio;
|
||||
}
|
||||
|
||||
float olDrawString(Font *font, float x, float y, float height, uint32_t color, const char *s)
|
||||
{
|
||||
float w = 0;
|
||||
float ratio = height / font->height;
|
||||
|
||||
while(*s) {
|
||||
w += olDrawChar(font, x+w, y, height, color, *s) - font->overlap * ratio;
|
||||
s++;
|
||||
}
|
||||
|
||||
return w + font->overlap * ratio;
|
||||
}
|
||||
|
||||
|
||||
float olGetStringWidth(Font *font, float height, const char *s)
|
||||
{
|
||||
float w = 0;
|
||||
float ratio = height / font->height;
|
||||
|
||||
while(*s) {
|
||||
w += font->chars[(uint8_t)*s].width * ratio - font->overlap * ratio;
|
||||
s++;
|
||||
}
|
||||
|
||||
return w + font->overlap * ratio;
|
||||
}
|
||||
|
||||
|
28
output/CMakeLists.txt
Normal file
28
output/CMakeLists.txt
Normal file
|
@ -0,0 +1,28 @@
|
|||
# OpenLase - a realtime laser graphics toolkit
|
||||
#
|
||||
# Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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(${QT_USE_FILE})
|
||||
|
||||
QT4_WRAP_UI(output_UIS_H output_settings.ui)
|
||||
QT4_AUTOMOC(output_settings.cpp output.cpp)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(output output.cpp output_settings.cpp ${output_UIS_H})
|
||||
target_link_libraries(output ${JACK_LIBRARIES} ${QT_LIBRARIES})
|
||||
|
265
output/output.cpp
Normal file
265
output/output.cpp
Normal file
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2010 Hector Martin "marcan" <hector@marcansoft.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.
|
||||