2 Copyright (c) 2001, Loki software, inc.
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this list
9 of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
15 Neither the name of Loki software nor the names of its contributors may be used
16 to endorse or promote products derived from this software without specific prior
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // OpenGL widget based on GtkGLExt
35 #include <gtk/gtkgl.h>
39 typedef int* attribs_t;
40 typedef const attribs_t* configs_iterator;
42 int config_rgba32[] = {
49 GDK_GL_ATTRIB_LIST_NONE,
59 GDK_GL_ATTRIB_LIST_NONE,
62 const attribs_t configs[] = {
67 GdkGLConfig* glconfig_new()
69 GdkGLConfig* glconfig = NULL;
71 for(configs_iterator i = configs, end = configs + 2; i != end && glconfig == NULL; ++i)
73 glconfig = gdk_gl_config_new(*i);
78 return gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE));
84 int config_rgba32_depth32[] = {
91 GDK_GL_DEPTH_SIZE, 32,
92 GDK_GL_ATTRIB_LIST_NONE,
95 int config_rgba32_depth24[] = {
100 GDK_GL_GREEN_SIZE, 8,
101 GDK_GL_ALPHA_SIZE, 8,
102 GDK_GL_DEPTH_SIZE, 24,
103 GDK_GL_ATTRIB_LIST_NONE,
106 int config_rgba32_depth16[] = {
111 GDK_GL_GREEN_SIZE, 8,
112 GDK_GL_ALPHA_SIZE, 8,
113 GDK_GL_DEPTH_SIZE, 16,
114 GDK_GL_ATTRIB_LIST_NONE,
117 int config_rgba32_depth[] = {
122 GDK_GL_GREEN_SIZE, 8,
123 GDK_GL_ALPHA_SIZE, 8,
124 GDK_GL_DEPTH_SIZE, 1,
125 GDK_GL_ATTRIB_LIST_NONE,
128 int config_rgba_depth16[] = {
133 GDK_GL_GREEN_SIZE, 1,
134 GDK_GL_ALPHA_SIZE, 1,
135 GDK_GL_DEPTH_SIZE, 16,
136 GDK_GL_ATTRIB_LIST_NONE,
139 int config_rgba_depth[] = {
144 GDK_GL_GREEN_SIZE, 1,
145 GDK_GL_ALPHA_SIZE, 1,
146 GDK_GL_DEPTH_SIZE, 1,
147 GDK_GL_ATTRIB_LIST_NONE,
150 const attribs_t configs_with_depth[] =
152 config_rgba32_depth32,
153 config_rgba32_depth24,
154 config_rgba32_depth16,
160 GdkGLConfig* glconfig_new_with_depth()
162 GdkGLConfig* glconfig = NULL;
164 for(configs_iterator i = configs_with_depth, end = configs_with_depth + 6; i != end && glconfig == NULL; ++i)
166 glconfig = gdk_gl_config_new(*i);
171 return gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH));
177 GtkWidget* WINAPI gtk_glwidget_new (gboolean zbuffer, GtkWidget* share)
179 GtkWidget* drawing_area = gtk_drawing_area_new();
180 GdkGLConfig* glconfig = (zbuffer) ? glconfig_new_with_depth() : glconfig_new();
181 GdkGLContext* shared_context = (share) ? gtk_widget_get_gl_context(share) : NULL;
183 gtk_widget_set_gl_capability (drawing_area, glconfig, shared_context, TRUE, GDK_GL_RGBA_TYPE);
188 void WINAPI gtk_glwidget_destroy_context (GtkWidget *widget)
192 void WINAPI gtk_glwidget_create_context (GtkWidget *widget)
196 void WINAPI gtk_glwidget_swap_buffers (GtkWidget *widget)
198 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
199 gdk_gl_drawable_swap_buffers (gldrawable);
202 gboolean WINAPI gtk_glwidget_make_current (GtkWidget *widget)
204 GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
205 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
206 return gdk_gl_drawable_gl_begin (gldrawable, glcontext);
209 GLuint font_list_base;
210 static gchar font_string[] = "courier 8";
211 static gint font_height;
213 void gtk_glwidget_create_font (GtkWidget *widget)
215 PangoFontDescription *font_desc;
217 PangoFontMetrics *font_metrics;
219 font_list_base = qglGenLists (256);
221 font_desc = pango_font_description_from_string (font_string);
223 font = gdk_gl_font_use_pango_font (font_desc, 0, 256, font_list_base);
227 font_metrics = pango_font_get_metrics (font, NULL);
229 font_height = pango_font_metrics_get_ascent (font_metrics) +
230 pango_font_metrics_get_descent (font_metrics);
231 font_height = PANGO_PIXELS (font_height);
233 pango_font_metrics_unref (font_metrics);
236 pango_font_description_free (font_desc);
240 void gtk_glwidget_print_string(const char *s)
242 qglListBase(font_list_base);
243 qglCallLists(strlen(s), GL_UNSIGNED_BYTE, (unsigned char *)s);
246 void gtk_glwidget_print_char(char s)
248 qglListBase(font_list_base);
249 qglCallLists(1, GL_UNSIGNED_BYTE, (unsigned char *) &s);