glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- double width = GTK_WIDGET(opengl)->allocation.width;
- double height = GTK_WIDGET(opengl)->allocation.height;
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc);
+ double width = alloc.width;
+ double height = alloc.height;
double ang = atan((height/2)/FOV_DIST)*2;
- double atmos = 100000;
- double near = MAX(elev*0.75 - atmos, 50); // View 100km of atmosphere
- double far = elev + 2*EARTH_R + atmos; // on both sides of the earth
+ double atmos = 10000;
+ double near = MAX(elev*0.75 - atmos, 50); // View 100km of atmosphere
+ double far = elev + EARTH_R*1.25 + atmos; // a bit past the cenrt of the earth
glViewport(0, 0, width, height);
gluPerspective(rad2deg(ang), width/height, near, far);
static gboolean run_mouse_move(GritsOpenGL *opengl, GdkEventMotion *event)
{
- gdouble height = GTK_WIDGET(opengl)->allocation.height;
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc);
+
gdouble gl_x = event->x;
- gdouble gl_y = height - event->y;
+ gdouble gl_y = alloc.height - event->y;
gdouble delta = opengl->pickmode ? 200 : 2;
if (opengl->pickmode) {
/* Start ortho */
if (level->num >= GRITS_LEVEL_HUD) {
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc);
glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity();
- gint win_width = GTK_WIDGET(opengl)->allocation.width;
- gint win_height = GTK_WIDGET(opengl)->allocation.height;
- glOrtho(0, win_width, win_height, 0, 1000, -1000);
+ glOrtho(0, alloc.width, alloc.height, 0, 1000, -1000);
}
/* Draw unsorted objects without depth testing,
nunsorted, nsorted);
}
-static gboolean on_expose(GritsOpenGL *opengl, GdkEventExpose *event, gpointer _)
+static gboolean on_expose(GritsOpenGL *opengl, gpointer data, gpointer _)
{
g_debug("GritsOpenGL: on_expose - begin");
if (opengl->pickmode)
- return run_mouse_move(opengl, (GdkEventMotion*)event);
+ return run_mouse_move(opengl, &(GdkEventMotion){});
if (opengl->mouse_queue.type != GDK_NOTHING) {
run_mouse_move(opengl, &opengl->mouse_queue);
static gboolean on_key_press(GritsOpenGL *opengl, GdkEventKey *event, gpointer _)
{
g_debug("GritsOpenGL: on_key_press - key=%x, state=%x, plus=%x",
- event->keyval, event->state, GDK_plus);
+ event->keyval, event->state, GDK_KEY_plus);
guint kv = event->keyval;
/* Testing */
- if (kv == GDK_w) {
+ if (kv == GDK_KEY_w) {
opengl->wireframe = !opengl->wireframe;
grits_viewer_queue_draw(GRITS_VIEWER(opengl));
}
- if (kv == GDK_p) {
+ if (kv == GDK_KEY_p) {
opengl->pickmode = !opengl->pickmode;
grits_viewer_queue_draw(GRITS_VIEWER(opengl));
}
#ifdef ROAM_DEBUG
- else if (kv == GDK_n) roam_sphere_split_one(opengl->sphere);
- else if (kv == GDK_p) roam_sphere_merge_one(opengl->sphere);
- else if (kv == GDK_r) roam_sphere_split_merge(opengl->sphere);
- else if (kv == GDK_u) roam_sphere_update_errors(opengl->sphere);
+ else if (kv == GDK_KEY_n) roam_sphere_split_one(opengl->sphere);
+ else if (kv == GDK_KEY_p) roam_sphere_merge_one(opengl->sphere);
+ else if (kv == GDK_KEY_r) roam_sphere_split_merge(opengl->sphere);
+ else if (kv == GDK_KEY_u) roam_sphere_update_errors(opengl->sphere);
grits_viewer_queue_draw(GRITS_VIEWER(opengl));
#endif
return FALSE;
/* Connect signals and idle functions now that opengl is fully initialized */
gtk_widget_add_events(GTK_WIDGET(opengl), GDK_KEY_PRESS_MASK);
g_signal_connect(opengl, "configure-event", G_CALLBACK(_set_projection), NULL);
+#if GTK_CHECK_VERSION(3,0,0)
+ g_signal_connect(opengl, "draw", G_CALLBACK(on_expose), NULL);
+#else
g_signal_connect(opengl, "expose-event", G_CALLBACK(on_expose), NULL);
+#endif
g_signal_connect(opengl, "key-press-event", G_CALLBACK(on_key_press), NULL);