From bda0d37e4b235d132a290ff1cb860c46b7077a72 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Thu, 22 Dec 2011 01:07:43 +0100 Subject: [PATCH] Remove some unused signals and prettyfy the rendering --- editor/Makefile | 1 + editor/src/display.c | 8 +++----- editor/src/event_callbacks.c | 28 ++++------------------------ editor/src/main.c | 14 +++++++++----- editor/src/main_gui.glade | 2 -- 5 files changed, 17 insertions(+), 36 deletions(-) diff --git a/editor/Makefile b/editor/Makefile index cdb975c..993fc85 100644 --- a/editor/Makefile +++ b/editor/Makefile @@ -7,6 +7,7 @@ SRCDIR=src all: $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/display.c $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/input.c + $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/usb.c $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/main.c $(CC) $(CFLAGS) $(LINKER_FLAGS) $(GTKLIBS) -o ledcube-edit main.o display.o input.o diff --git a/editor/src/display.c b/editor/src/display.c index 0a31d1f..a086ac4 100644 --- a/editor/src/display.c +++ b/editor/src/display.c @@ -24,6 +24,7 @@ void drawLEDs(int mode) { glColor3ub(0, 0, ledIndex*8); } else { glMaterialfv(GL_FRONT, GL_AMBIENT, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial)); + glMaterialfv(GL_FRONT, GL_DIFFUSE, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial)); } glPushMatrix(); @@ -69,6 +70,7 @@ void drawWires() { } void setScene() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0); @@ -81,16 +83,12 @@ void setScene() { // OpenGL Display function void display(gboolean onlyForPicking) { glClearColor(0.0, 0.0, 0.0, 1.0); - glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT0); - glLightfv(GL_LIGHT0, GL_POSITION, light0Pos); glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - setScene(); if (onlyForPicking == TRUE) { @@ -102,8 +100,8 @@ void display(gboolean onlyForPicking) { glEnable(GL_LIGHTING); glEnable(GL_DITHER); } else { - drawWires(); drawLEDs(RENDER_MODE); + drawWires(); } } diff --git a/editor/src/event_callbacks.c b/editor/src/event_callbacks.c index c0a7bf1..2f389a7 100644 --- a/editor/src/event_callbacks.c +++ b/editor/src/event_callbacks.c @@ -11,18 +11,6 @@ void on_main_window_delete_event(GtkObject *object, gpointer userData) { gtk_main_quit(); } -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); - - if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return FALSE; - - setScene(); - - gdk_gl_drawable_gl_end(glDrawable); - return FALSE; -} - 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); @@ -41,13 +29,6 @@ gboolean on_drawing_area_expose_event(GtkWidget *widget, GdkEventExpose *event, 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); - if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return; - gdk_gl_drawable_gl_end(glDrawable); -} - void on_drawing_area_key_press_event(GtkWidget *widget, GdkEventKey *event) { switch (event->keyval) { case GDK_KEY_Left: @@ -71,14 +52,13 @@ 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); + GdkGLDrawable *glDrawable = gtk_widget_get_gl_drawable(widget); + gint x, y; + + gtk_widget_get_pointer(widget, &x, &y); 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); diff --git a/editor/src/main.c b/editor/src/main.c index cc9329a..dd9ab68 100644 --- a/editor/src/main.c +++ b/editor/src/main.c @@ -15,10 +15,10 @@ // TODO: Refactor to GLib-Datatypes (page 747) // Materials -float ledOnMaterial[] = {0.0, 0.0, 1.0, 1.0}; +float ledOnMaterial[] = {0.0, 0.0, 1.0, 0.4}; float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0}; float wireMaterial[] = {0.7, 0.7, 0.7, 1.0}; -float innerWireMaterial[] = {0.2, 0.2, 0.2, 0.3}; +float innerWireMaterial[] = {0.3, 0.3, 0.3, 0.3}; // Colors float backgroundColor[] = {0.3, 0.3, 0.3, 0.4}; @@ -50,11 +50,15 @@ int main(int argc, char *argv[]) { gluQuadricNormals(quadric, GLU_SMOOTH); gluQuadricDrawStyle(quadric, GLU_FILL); - glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); - moveCameraPosition(0); - currentFrame[0] = 1; // TODO: remove + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, light0Pos); + glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); + + glMatrixMode(GL_MODELVIEW); + moveCameraPosition(0); // Configure the OpenGL widget glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE); diff --git a/editor/src/main_gui.glade b/editor/src/main_gui.glade index 6b9a1d9..e759a7a 100644 --- a/editor/src/main_gui.glade +++ b/editor/src/main_gui.glade @@ -94,8 +94,6 @@ - - 2