summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfcolin2000-12-20 15:58:44 +0000
committerfcolin2000-12-20 15:58:44 +0000
commitf94ece0bcc51dba3f431d82032c3d82d4e4a616a (patch)
treedb2d5a13a4b5b1b8d202e830132a2b28aabae756 /src
parentab5818d2b6b0a373e558b48a854e3cdbe570a5f4 (diff)
downloadivy-c-f94ece0bcc51dba3f431d82032c3d82d4e4a616a.zip
ivy-c-f94ece0bcc51dba3f431d82032c3d82d4e4a616a.tar.gz
ivy-c-f94ece0bcc51dba3f431d82032c3d82d4e4a616a.tar.bz2
ivy-c-f94ece0bcc51dba3f431d82032c3d82d4e4a616a.tar.xz
initial version for the glut eventloop
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ivyglutloop.c131
-rwxr-xr-xsrc/ivyglutloop.h56
2 files changed, 187 insertions, 0 deletions
diff --git a/src/ivyglutloop.c b/src/ivyglutloop.c
new file mode 100755
index 0000000..b78c183
--- /dev/null
+++ b/src/ivyglutloop.c
@@ -0,0 +1,131 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Main loop based on GLUT ( OpenGL ) Toolkit
+ *
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
+ *
+ * $Id$
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#ifdef WIN32
+#else
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <signal.h>
+#endif
+
+
+#include <GL/Glut.h>
+
+#include "ivychannel.h"
+#include "ivyglutloop.h"
+
+struct _channel {
+ GLUTInputId id_read;
+ GLUTInputId id_delete;
+ void *data;
+ ChannelHandleDelete handle_delete;
+ ChannelHandleRead handle_read;
+ };
+
+
+static int channel_initialized = 0;
+
+ChannelInit channel_init = IvyGlutChannelInit;
+ChannelSetUp channel_setup = IvyGlutChannelSetUp;
+ChannelClose channel_close = IvyGlutChannelClose;
+
+
+void IvyGlutChannelInit(void)
+{
+
+ if ( channel_initialized ) return;
+
+ /* pour eviter les plantages quand les autres applis font core-dump */
+#ifndef WIN32
+ signal( SIGPIPE, SIG_IGN);
+#endif
+ channel_initialized = 1;
+}
+
+void IvyGlutChannelClose( Channel channel )
+{
+
+ if ( channel->handle_delete )
+ (*channel->handle_delete)( channel->data );
+ glutRemoveInput( channel->id_read );
+ glutRemoveInput( channel->id_delete );
+}
+
+
+static void IvyGlutHandleChannelRead( int source, GLUTInputId id, void *data )
+{
+ Channel channel = (Channel)data;
+#ifdef DEBUG
+ printf("Handle Channel read %d\n",source );
+#endif
+ (*channel->handle_read)(channel,source,channel->data);
+}
+
+static void IvyGlutHandleChannelDelete( int source, GLUTInputId id, void *data )
+{
+ Channel channel = (Channel)data;
+#ifdef DEBUG
+ printf("Handle Channel delete %d\n",source );
+#endif
+ (*channel->handle_delete)(channel->data);
+}
+
+Channel IvyGlutChannelSetUp(HANDLE fd, void *data,
+ ChannelHandleDelete handle_delete,
+ ChannelHandleRead handle_read
+ )
+{
+ Channel channel;
+
+ channel = (Channel)malloc( sizeof(struct _channel) );
+ if ( !channel )
+ {
+ fprintf(stderr,"NOK Memory Alloc Error\n");
+ exit(0);
+ }
+
+ channel->handle_delete = handle_delete;
+ channel->handle_read = handle_read;
+ channel->data = data;
+
+ channel->id_read = glutAddInput( fd, IvyGlutHandleChannelRead, channel);
+ channel->id_delete = glutAddInput( fd, IvyGlutHandleChannelDelete, channel);
+
+ return channel;
+}
+
+
+void
+IvyStop ()
+{
+ /* To be implemented */
+}
+
diff --git a/src/ivyglutloop.h b/src/ivyglutloop.h
new file mode 100755
index 0000000..0819a93
--- /dev/null
+++ b/src/ivyglutloop.h
@@ -0,0 +1,56 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Main loop based on GLUT ( OpenGL ) Toolkit
+ *
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
+ *
+ * $Id$
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+
+#ifndef IVYGLUTLOOP_H
+#define IVYGLUTLOOP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <GL/Glut.h>
+
+/* general Handle */
+
+#define ANYPORT 0
+
+#ifdef WIN32
+#include <windows.h>
+#define HANDLE SOCKET
+#else
+#define HANDLE int
+#endif
+
+#include "ivychannel.h"
+
+extern void IvyGlutChannelInit(void);
+
+extern Channel IvyGlutChannelSetUp(
+ HANDLE fd,
+ void *data,
+ ChannelHandleDelete handle_delete,
+ ChannelHandleRead handle_read
+);
+
+extern void IvyGlutChannelClose( Channel channel );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+