Make The LEDs clickable
This commit is contained in:
parent
998d0e3e15
commit
e95b066044
8 changed files with 58 additions and 44 deletions
|
@ -1,7 +1,7 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall
|
||||
LINKER_FLAGS=-lglut -export-dynamic
|
||||
GTKLIBS=`pkg-config --cflags --libs gtkglext-1.0 libglade-2.0 gmodule-export-2.0`
|
||||
GTKLIBS=`pkg-config --cflags --libs gtk+-2.0 gtkglext-1.0 libglade-2.0 gmodule-export-2.0`
|
||||
SRCDIR=src
|
||||
|
||||
all:
|
||||
|
@ -16,5 +16,5 @@ all:
|
|||
clean:
|
||||
rm -f *.o
|
||||
rm -f gui
|
||||
#rm -f ledcube-edit
|
||||
rm -f ledcube-edit
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ void setScene() {
|
|||
}
|
||||
|
||||
// OpenGL Display function
|
||||
void display() {
|
||||
void display(gboolean onlyForPicking) {
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
|
@ -92,19 +92,18 @@ void display() {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
setScene();
|
||||
drawWires();
|
||||
drawLEDs(RENDER_MODE);
|
||||
}
|
||||
|
||||
// Picking function
|
||||
void displayPickingObjects() {
|
||||
setScene();
|
||||
glDisable(GL_DITHER);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
drawLEDs(PICKING_MODE);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DITHER);
|
||||
|
||||
if (onlyForPicking == TRUE) {
|
||||
glDisable(GL_DITHER);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
drawLEDs(PICKING_MODE);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DITHER);
|
||||
} else {
|
||||
drawWires();
|
||||
drawLEDs(RENDER_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
void drawLEDs(int mode);
|
||||
void drawWires();
|
||||
|
||||
void display();
|
||||
void displayPickingObjects();
|
||||
void display(gboolean onlyForPicking);
|
||||
|
||||
void setScene();
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ void on_main_window_delete_event(GtkObject *object, gpointer userData) {
|
|||
|
||||
gboolean on_drawing_area_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) {
|
||||
GdkGLContext *glContext = gtk_widget_get_gl_context(widget);
|
||||
GdkGLDrawable *glDrawable =gtk_widget_get_gl_drawable(widget);
|
||||
GdkGLDrawable *glDrawable = gtk_widget_get_gl_drawable(widget);
|
||||
|
||||
if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return FALSE;
|
||||
|
||||
|
@ -25,26 +25,26 @@ gboolean on_drawing_area_configure_event(GtkWidget *widget, GdkEventConfigure *e
|
|||
|
||||
gboolean on_drawing_area_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
|
||||
GdkGLContext *glContext = gtk_widget_get_gl_context(widget);
|
||||
GdkGLDrawable *glDrawable =gtk_widget_get_gl_drawable(widget);
|
||||
GdkGLDrawable *glDrawable = gtk_widget_get_gl_drawable(widget);
|
||||
|
||||
if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return FALSE;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
display();
|
||||
display(FALSE);
|
||||
|
||||
if (gdk_gl_drawable_is_double_buffered(glDrawable))
|
||||
gdk_gl_drawable_swap_buffers(glDrawable);
|
||||
else
|
||||
glFlush();
|
||||
gdk_gl_drawable_gl_end(glDrawable);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void on_drawing_area_realize(GtkWidget *widget, gpointer data) {
|
||||
GdkGLContext *glContext = gtk_widget_get_gl_context(widget);
|
||||
GdkGLDrawable *glDrawable =gtk_widget_get_gl_drawable(widget);
|
||||
GdkGLDrawable *glDrawable = gtk_widget_get_gl_drawable(widget);
|
||||
if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return;
|
||||
|
||||
gdk_gl_drawable_gl_end(glDrawable);
|
||||
}
|
||||
|
||||
|
@ -67,3 +67,23 @@ void on_drawing_area_key_press_event(GtkWidget *widget, GdkEventKey *event) {
|
|||
gtk_widget_queue_draw_area(widget, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
}
|
||||
|
||||
void on_drawing_area_button_press_event(GtkWidget *widget, gpointer data) {
|
||||
gtk_widget_grab_focus(widget);
|
||||
|
||||
GdkGLContext *glContext = gtk_widget_get_gl_context(widget);
|
||||
GdkGLDrawable *glDrawable =gtk_widget_get_gl_drawable(widget);
|
||||
|
||||
if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
gint x, y;
|
||||
gtk_widget_get_pointer(widget, &x, &y);
|
||||
|
||||
display(TRUE);
|
||||
mouse(x, y);
|
||||
|
||||
gdk_gl_drawable_gl_end(glDrawable);
|
||||
gtk_widget_queue_draw_area(widget, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,23 +23,16 @@ void moveCameraAngle(float angle) {
|
|||
if (eyeAngle < 0) eyeAngle = 0;
|
||||
}
|
||||
|
||||
void mouse(int button, int state, int x, int y) {
|
||||
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
|
||||
int position, viewport[4];
|
||||
GLubyte pixel[3];
|
||||
void mouse(int x, int y) {
|
||||
int position, viewport[4];
|
||||
GLubyte pixel[3];
|
||||
|
||||
displayPickingObjects();
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel);
|
||||
position = ((int)pixel[2]/8)-1; // Selected LED
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel);
|
||||
position = ((int)pixel[2]/8)-1; // Selected LED
|
||||
|
||||
printf("%d\n", position);
|
||||
currentFrame[position] = currentFrame[position] == 0 ? 1 : 0;
|
||||
printf("%d\n", currentFrame[position]);
|
||||
|
||||
// FIXME: Redraw the gl-container
|
||||
//display();
|
||||
}
|
||||
printf("%d\n", position);
|
||||
currentFrame[position] = currentFrame[position] == 0 ? 1 : 0;
|
||||
printf("%d\n", currentFrame[position]);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
void moveCameraPosition(float direction);
|
||||
void moveCameraAngle(float angle);
|
||||
|
||||
void mouse(int button, int state, int x, int y);
|
||||
void mouse(int x, int y);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "input.h"
|
||||
#include "event_callbacks.c"
|
||||
|
||||
// TODO: Refactor to GLib-Datatypes (page 747)
|
||||
|
||||
// Materials
|
||||
float ledOnMaterial[] = {0.0, 0.0, 1.0, 1.0};
|
||||
float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
||||
|
@ -57,10 +59,10 @@ int main(int argc, char *argv[]) {
|
|||
// 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) {
|
||||
g_print("EEE Double buffer not available, trying single buffer.");
|
||||
g_warning("EEE Double buffer not available, trying single buffer.");
|
||||
glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH);
|
||||
if (glConfig == NULL) {
|
||||
g_print("EEE Sorry, can't configure the OpenGL window. Giving up.");
|
||||
g_error("EEE Sorry, can't configure the OpenGL window. Giving up.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,8 +90,9 @@
|
|||
<property name="height_request">500</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK</property>
|
||||
<property name="events">GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK</property>
|
||||
<signal name="expose_event" handler="on_drawing_area_expose_event"/>
|
||||
<signal name="button_press_event" handler="on_drawing_area_button_press_event"/>
|
||||
<signal name="key_press_event" handler="on_drawing_area_key_press_event"/>
|
||||
<signal name="realize" handler="on_drawing_area_realize" after="yes"/>
|
||||
<signal name="configure_event" handler="on_drawing_area_configure_event" after="yes"/>
|
||||
|
|
Loading…
Reference in a new issue