Remove some unused signals and prettyfy the rendering

This commit is contained in:
Aaron Mueller 2011-12-22 01:07:43 +01:00
parent 37ea6f5b32
commit bda0d37e4b
5 changed files with 17 additions and 36 deletions

View file

@ -7,6 +7,7 @@ SRCDIR=src
all: all:
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/display.c $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/display.c
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/input.c $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/input.c
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/usb.c
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/main.c $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/main.c
$(CC) $(CFLAGS) $(LINKER_FLAGS) $(GTKLIBS) -o ledcube-edit main.o display.o input.o $(CC) $(CFLAGS) $(LINKER_FLAGS) $(GTKLIBS) -o ledcube-edit main.o display.o input.o

View file

@ -24,6 +24,7 @@ void drawLEDs(int mode) {
glColor3ub(0, 0, ledIndex*8); glColor3ub(0, 0, ledIndex*8);
} else { } else {
glMaterialfv(GL_FRONT, GL_AMBIENT, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial)); glMaterialfv(GL_FRONT, GL_AMBIENT, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial));
glMaterialfv(GL_FRONT, GL_DIFFUSE, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial));
} }
glPushMatrix(); glPushMatrix();
@ -69,6 +70,7 @@ void drawWires() {
} }
void setScene() { void setScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0); gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0);
@ -81,16 +83,12 @@ void setScene() {
// OpenGL Display function // OpenGL Display function
void display(gboolean onlyForPicking) { void display(gboolean onlyForPicking) {
glClearColor(0.0, 0.0, 0.0, 1.0); glClearColor(0.0, 0.0, 0.0, 1.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0); glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
setScene(); setScene();
if (onlyForPicking == TRUE) { if (onlyForPicking == TRUE) {
@ -102,8 +100,8 @@ void display(gboolean onlyForPicking) {
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_DITHER); glEnable(GL_DITHER);
} else { } else {
drawWires();
drawLEDs(RENDER_MODE); drawLEDs(RENDER_MODE);
drawWires();
} }
} }

View file

@ -11,18 +11,6 @@ void on_main_window_delete_event(GtkObject *object, gpointer userData) {
gtk_main_quit(); 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) { gboolean on_drawing_area_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
GdkGLContext *glContext = gtk_widget_get_gl_context(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);
@ -41,13 +29,6 @@ gboolean on_drawing_area_expose_event(GtkWidget *widget, GdkEventExpose *event,
return FALSE; 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) { void on_drawing_area_key_press_event(GtkWidget *widget, GdkEventKey *event) {
switch (event->keyval) { switch (event->keyval) {
case GDK_KEY_Left: case GDK_KEY_Left:
@ -72,14 +53,13 @@ void on_drawing_area_button_press_event(GtkWidget *widget, gpointer data) {
GdkGLContext *glContext = gtk_widget_get_gl_context(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; if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gint x, y;
gtk_widget_get_pointer(widget, &x, &y);
display(TRUE); display(TRUE);
mouse(x, y); mouse(x, y);

View file

@ -15,10 +15,10 @@
// TODO: Refactor to GLib-Datatypes (page 747) // TODO: Refactor to GLib-Datatypes (page 747)
// Materials // 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 ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
float wireMaterial[] = {0.7, 0.7, 0.7, 1.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 // Colors
float backgroundColor[] = {0.3, 0.3, 0.3, 0.4}; float backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
@ -50,11 +50,15 @@ int main(int argc, char *argv[]) {
gluQuadricNormals(quadric, GLU_SMOOTH); gluQuadricNormals(quadric, GLU_SMOOTH);
gluQuadricDrawStyle(quadric, GLU_FILL); gluQuadricDrawStyle(quadric, GLU_FILL);
glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH); 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 // Configure the OpenGL widget
glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE); glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE);

View file

@ -94,8 +94,6 @@
<signal name="expose_event" handler="on_drawing_area_expose_event"/> <signal name="expose_event" handler="on_drawing_area_expose_event"/>
<signal name="button_press_event" handler="on_drawing_area_button_press_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="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"/>
</widget> </widget>
<packing> <packing>
<property name="position">2</property> <property name="position">2</property>