]> Pileus Git - grits/blob - src/plugins/test.c
Add preliminary support for points/markers
[grits] / src / plugins / test.c
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <gtk/gtkgl.h>
19 #include <GL/gl.h>
20 #include <GL/glu.h>
21
22 #include <gis.h>
23
24 #include "test.h"
25
26 /***********
27  * Methods *
28  ***********/
29 GisPluginTest *gis_plugin_test_new(GisWorld *world, GisView *view, GisOpenGL *opengl)
30 {
31         g_debug("GisPluginTest: new");
32         GisPluginTest *self = g_object_new(GIS_TYPE_PLUGIN_TEST, NULL);
33         self->view   = view;
34         self->opengl = opengl;
35         return self;
36 }
37
38 static void gis_plugin_test_expose(GisPlugin *_self)
39 {
40         GisPluginTest *self = GIS_PLUGIN_TEST(_self);
41         g_debug("GisPluginTest: expose");
42
43         double width  = GTK_WIDGET(self->opengl)->allocation.width;
44         double height = GTK_WIDGET(self->opengl)->allocation.height;
45
46         // St. Charles
47         // lat =  38.841847
48         // lon = -90.491982
49         gdouble px, py, pz;
50         gis_opengl_project(self->opengl,
51                 38.841847, -90.491982, 0, &px, &py, &pz);
52         py = height-py;
53
54         //cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
55         //cairo_t *cairo = cairo_create(surface);
56         //cairo_set_source_rgba(cairo, 1, 1, 1, 1);
57         //cairo_arc(cairo, px, py, 4, 0, 2*G_PI);
58         //cairo_fill(cairo);
59         //cairo_move_to(cairo, px+4, py-8);
60         //cairo_set_font_size(cairo, 10);
61         //cairo_show_text(cairo, "Marker!");
62
63         //guint tex;
64         //glEnable(GL_TEXTURE_2D);
65         //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
66         //glPixelStorei(GL_PACK_ALIGNMENT, 1);
67         //glGenTextures(1, &tex);
68         //glBindTexture(GL_TEXTURE_2D, tex);
69         //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
70         //              cairo_image_surface_get_data(surface));
71         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
72         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
73
74         //glMatrixMode(GL_PROJECTION);
75         //glLoadIdentity();
76         //glMatrixMode(GL_MODELVIEW);
77         //glLoadIdentity();
78
79         //glDisable(GL_COLOR_MATERIAL);
80         //glDisable(GL_CULL_FACE);
81         //glDisable(GL_DEPTH_TEST);
82         //glDisable(GL_LIGHTING);
83         //glBegin(GL_QUADS);
84         //glTexCoord2d(0, 0); glVertex3f(-1,  1, 1);
85         //glTexCoord2d(1, 0); glVertex3f( 1,  1, 1);
86         //glTexCoord2d(1, 1); glVertex3f( 1, -1, 1);
87         //glTexCoord2d(0, 1); glVertex3f(-1, -1, 1);
88         //glEnd();
89         //glDeleteTextures(1, &tex);
90         //cairo_destroy(cairo);
91         //cairo_surface_destroy(surface);
92 }
93
94
95 /****************
96  * GObject code *
97  ****************/
98 /* Plugin init */
99 static void gis_plugin_test_plugin_init(GisPluginInterface *iface);
100 G_DEFINE_TYPE_WITH_CODE(GisPluginTest, gis_plugin_test, G_TYPE_OBJECT,
101                 G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN,
102                         gis_plugin_test_plugin_init));
103 static void gis_plugin_test_plugin_init(GisPluginInterface *iface)
104 {
105         g_debug("GisPluginTest: plugin_init");
106         /* Add methods to the interface */
107         iface->expose     = gis_plugin_test_expose;
108 }
109 /* Class/Object init */
110 static void gis_plugin_test_init(GisPluginTest *self)
111 {
112         g_debug("GisPluginTest: init");
113         /* Set defaults */
114         self->view   = NULL;
115         self->opengl = NULL;
116 }
117 static void gis_plugin_test_dispose(GObject *gobject)
118 {
119         g_debug("GisPluginTest: dispose");
120         GisPluginTest *self = GIS_PLUGIN_TEST(gobject);
121         /* Drop references */
122         G_OBJECT_CLASS(gis_plugin_test_parent_class)->dispose(gobject);
123 }
124 static void gis_plugin_test_finalize(GObject *gobject)
125 {
126         g_debug("GisPluginTest: finalize");
127         GisPluginTest *self = GIS_PLUGIN_TEST(gobject);
128         /* Free data */
129         G_OBJECT_CLASS(gis_plugin_test_parent_class)->finalize(gobject);
130
131 }
132 static void gis_plugin_test_class_init(GisPluginTestClass *klass)
133 {
134         g_debug("GisPluginTest: class_init");
135         GObjectClass *gobject_class = (GObjectClass*)klass;
136         gobject_class->dispose  = gis_plugin_test_dispose;
137         gobject_class->finalize = gis_plugin_test_finalize;
138 }