2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
4 This file is part of the 3dengfx, realtime visualization system.
6 3dengfx is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Author: John Tsiombikas 2004
26 #include "3dengfx_config.h"
28 #if GFX_LIBRARY == GTK
32 #include "gfx_library.h"
33 #include "3dengfx/3denginefx.hpp"
34 #include "common/err_msg.h"
37 GtkWidget *gl_drawing_area;
38 GdkGLConfig *glconfig;
40 bool fxwt::init_graphics(GraphicsInitParameters *gparams) {
41 info("Initializing GTK and GTK-GLext");
43 char *argv[] = {"foo", (char*)0};
45 gtk_gl_init(&argc, (char***)&argv);
47 info("Trying to set video mode %dx%dx%d, d:%d s:%d %s",gparams->x, gparams->y, gparams->bpp, gparams->depth_bits, gparams->stencil_bits, gparams->fullscreen ? "fullscreen" : "windowed");
49 int rbits, gbits, bbits;
50 switch(gparams->bpp) {
52 rbits = gbits = bbits = 8;
61 error("%s: Tried to set unsupported pixel format: %d bpp", __func__, gparams->bpp);
66 GDK_GL_USE_GL, GDK_GL_DOUBLEBUFFER, GDK_GL_RGBA,
67 GDK_GL_RED_SIZE, rbits,
68 GDK_GL_GREEN_SIZE, gbits,
69 GDK_GL_BLUE_SIZE, bbits,
70 GDK_GL_DEPTH_SIZE, gparams->depth_bits,
71 GDK_GL_STENCIL_SIZE, gparams->stencil_bits,
72 GDK_GL_ATTRIB_LIST_NONE
75 //GdkGLConfig *glconfig;
76 if(!(glconfig = gdk_gl_config_new(gdkgl_attr))) {
77 if(gparams->depth_bits == 32) gdkgl_attr[10] = 24;
79 if(!(glconfig = gdk_gl_config_new(gdkgl_attr))) {
80 error("%s: Could not set requested video mode", __func__);
84 // now check the actual video mode we got
85 int arbits, agbits, abbits, azbits, astencilbits;
86 gdk_gl_config_get_attrib(glconfig, GDK_GL_RED_SIZE, &arbits);
87 gdk_gl_config_get_attrib(glconfig, GDK_GL_GREEN_SIZE, &agbits);
88 gdk_gl_config_get_attrib(glconfig, GDK_GL_BLUE_SIZE, &abbits);
89 gdk_gl_config_get_attrib(glconfig, GDK_GL_DEPTH_SIZE, &azbits);
90 gdk_gl_config_get_attrib(glconfig, GDK_GL_STENCIL_SIZE, &astencilbits);
92 info("Initialized video mode:");
93 info(" bpp: %d (%d%d%d)", arbits + agbits + abbits, arbits, agbits, abbits);
94 info("zbuffer: %d", azbits);
95 info("stencil: %d", astencilbits);
97 /* if the dont_care_flags does not contain DONT_CARE_BPP and our color bits
98 * does not match, we should return failure, however we test against
99 * the difference allowing a +/-1 difference in order to allow for 16bpp
100 * formats of either 565 or 555 and consider them equal.
102 if(!(gparams->dont_care_flags & DONT_CARE_BPP) && abs(arbits - rbits) > 1 && abs(agbits - gbits) > 1 && abs(abbits - bbits) > 1) {
103 error("%s: Could not set requested exact bpp mode", __func__);
107 // now if we don't have DONT_CARE_DEPTH in the dont_care_flags check for
108 // exact depth buffer format, however consider 24 and 32 bit the same
109 if(!(gparams->dont_care_flags & DONT_CARE_DEPTH) && azbits != gparams->depth_bits) {
110 if(!(gparams->depth_bits == 32 && azbits == 24 || gparams->depth_bits == 24 && azbits == 32)) {
111 error("%s: Could not set requested exact zbuffer depth", __func__);
116 // if we don't have DONT_CARE_STENCIL make sure we have the stencil format
118 if(!(gparams->dont_care_flags & DONT_CARE_STENCIL) && astencilbits != gparams->stencil_bits) {
119 error("%s: Could not set exact stencil format", __func__);
123 //gl_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
124 //gtk_window_set_title(gtk_window(gl_window), "3dengfx visualization window");
125 //gtk_container_set_reallocate_redraws(gtk_container(gl_window), TRUE);
126 //g_signal_connect(g_object(gl_window), "delete_event", g_callback(gtk_main_quit), NULL);
128 gl_drawing_area = gtk_drawing_area_new();
129 gtk_widget_set_size_request(gl_drawing_area, gparams->x, gparams->y);
131 if(!gtk_widget_set_gl_capability(gl_drawing_area, glconfig, 0, TRUE, GDK_GL_RGBA_TYPE)) {
132 error("%s: gtk_widget_set_gl_capability() failed", __func__);
136 extern void set_gtk_callbacks(GtkWidget*);
137 set_gtk_callbacks(gl_drawing_area);
139 //gtk_container_add(gtk_container(gl_window), gl_drawing_area);
140 //gtk_widget_show(gl_drawing_area);
141 //gtk_widget_show(gl_window);
146 void fxwt::destroy_graphics() {
147 info("Shutting down GTK+");