Remove some unused signals and prettyfy the rendering
This commit is contained in:
parent
37ea6f5b32
commit
bda0d37e4b
5 changed files with 17 additions and 36 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -94,8 +94,6 @@
|
|||
<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"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
|
|
Loading…
Reference in a new issue