2011-10-19 01:10:15 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-12-06 22:35:48 +01:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gtk/gtkgl.h>
|
|
|
|
#include <glade/glade.h>
|
|
|
|
|
|
|
|
#include <GL/glut.h>
|
2011-10-19 01:10:15 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "input.h"
|
2011-12-06 22:35:48 +01:00
|
|
|
#include "event_callbacks.c"
|
2011-10-31 00:25:07 +01:00
|
|
|
|
|
|
|
// Materials
|
2011-12-27 18:48:15 +01:00
|
|
|
gfloat ledOnMaterial[] = {0.0, 0.0, 1.0, 0.4};
|
|
|
|
gfloat ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
|
|
|
gfloat wireMaterial[] = {0.7, 0.7, 0.7, 1.0};
|
|
|
|
gfloat innerWireMaterial[] = {0.3, 0.3, 0.3, 0.3};
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-31 00:25:07 +01:00
|
|
|
// Colors
|
2011-12-27 18:48:15 +01:00
|
|
|
gfloat backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
|
2011-10-19 01:10:15 +02:00
|
|
|
|
2011-10-31 00:25:07 +01:00
|
|
|
// Positions
|
2011-12-27 18:48:15 +01:00
|
|
|
gfloat light0Pos[] = {70, 70, 70, 0.0};
|
|
|
|
gfloat lookX = 0.0, lookZ = 0.0;
|
|
|
|
gfloat eyePos = 0.0, eyeAngle = 45.0;
|
|
|
|
gint ledOrientation = TOP_ORIENTATION;
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-31 00:25:07 +01:00
|
|
|
// Objects
|
2011-10-20 20:28:00 +02:00
|
|
|
GLUquadricObj *quadric;
|
2011-12-06 22:35:48 +01:00
|
|
|
GdkGLConfig *glConfig;
|
|
|
|
GdkGLContext *glContext;
|
|
|
|
GtkWidget *window, *drawingArea;
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-31 00:25:07 +01:00
|
|
|
// LED data
|
2011-12-27 18:48:15 +01:00
|
|
|
gint currentFrame[27] = {0};
|
2011-10-31 00:25:07 +01:00
|
|
|
|
2011-10-19 01:10:15 +02:00
|
|
|
|
2011-12-28 09:43:29 +01:00
|
|
|
void* connectToLEDCube(void) {
|
|
|
|
int ret = NULL;
|
|
|
|
while (ret == NULL || ret != SUCCESSFULLY_CONNECTED) {
|
|
|
|
ret = lc_init();
|
|
|
|
g_print("connecting ...");
|
|
|
|
sleep(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-27 18:48:15 +01:00
|
|
|
gint main(gint argc, gchar *argv[]) {
|
2011-12-06 22:35:48 +01:00
|
|
|
GladeXML *xml;
|
2011-12-28 09:43:29 +01:00
|
|
|
GThread *connectThread;
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-12-06 22:35:48 +01:00
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
gdk_gl_init(&argc, &argv);
|
|
|
|
glutInit(&argc, argv);
|
2011-10-20 20:28:00 +02:00
|
|
|
|
|
|
|
quadric = gluNewQuadric();
|
|
|
|
gluQuadricNormals(quadric, GLU_SMOOTH);
|
|
|
|
gluQuadricDrawStyle(quadric, GLU_FILL);
|
|
|
|
|
2011-12-06 22:35:48 +01:00
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
|
2011-12-22 01:07:43 +01:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
moveCameraPosition(0);
|
2011-12-06 22:35:48 +01:00
|
|
|
|
|
|
|
// Configure the OpenGL widget
|
|
|
|
glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE);
|
|
|
|
if (glConfig == NULL) {
|
2011-12-28 09:43:29 +01:00
|
|
|
g_warning("Double buffer not available, trying single buffer.");
|
2011-12-06 22:35:48 +01:00
|
|
|
glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH);
|
|
|
|
if (glConfig == NULL) {
|
2011-12-28 09:43:29 +01:00
|
|
|
g_error("Sorry, can't configure the OpenGL window. Giving up.");
|
2011-12-06 22:35:48 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-11 20:11:45 +01:00
|
|
|
xml = glade_xml_new("main_gui.glade", NULL, NULL);
|
2011-12-06 22:35:48 +01:00
|
|
|
|
|
|
|
window = glade_xml_get_widget(xml, "main_window");
|
|
|
|
gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
|
|
|
|
drawingArea = glade_xml_get_widget(xml, "drawing_area");
|
|
|
|
gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
|
|
|
|
|
2011-12-21 21:04:58 +01:00
|
|
|
glade_xml_signal_autoconnect(xml);
|
2011-12-07 21:42:42 +01:00
|
|
|
|
2011-12-28 09:43:29 +01:00
|
|
|
if (g_thread_supported()) {
|
|
|
|
g_print("1");
|
|
|
|
g_thread_init(NULL);
|
|
|
|
g_print("2");
|
|
|
|
gdk_threads_init();
|
|
|
|
g_print("3");
|
|
|
|
} else {
|
|
|
|
g_error("Threads not supported, we die.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
g_thread_init(NULL);
|
|
|
|
if (connectThread = g_thread_create((GThreadFunc)connectToLEDCube, NULL, TRUE, &error) == NULL) {
|
|
|
|
g_error("Can't create the thread, we stop here.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
//g_thread_join(connectThread);
|
|
|
|
|
2011-12-06 22:35:48 +01:00
|
|
|
gtk_widget_show(window);
|
|
|
|
gtk_main();
|
2011-10-19 01:10:15 +02:00
|
|
|
|
2011-12-28 09:43:29 +01:00
|
|
|
lc_close();
|
2011-10-19 01:10:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|