diff options
Diffstat (limited to 'src/others/mimesh/g3dviewer-0.2.99.4/src/main.c')
-rw-r--r-- | src/others/mimesh/g3dviewer-0.2.99.4/src/main.c | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/src/others/mimesh/g3dviewer-0.2.99.4/src/main.c b/src/others/mimesh/g3dviewer-0.2.99.4/src/main.c new file mode 100644 index 0000000..b5d7e0c --- /dev/null +++ b/src/others/mimesh/g3dviewer-0.2.99.4/src/main.c | |||
@@ -0,0 +1,172 @@ | |||
1 | /* $Id: main.c 48 2006-05-25 16:30:38Z mmmaddd $ */ | ||
2 | |||
3 | /* | ||
4 | G3DViewer - 3D object viewer | ||
5 | |||
6 | Copyright (C) 2005, 2006 Markus Dahms <mad@automagically.de> | ||
7 | |||
8 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #ifdef HAVE_CONFIG_H | ||
24 | #include <config.h> | ||
25 | #endif | ||
26 | |||
27 | #include <stdio.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <string.h> | ||
30 | |||
31 | #include <gtk/gtk.h> | ||
32 | #include <gtk/gtkgl.h> | ||
33 | |||
34 | #include <g3d/types.h> | ||
35 | |||
36 | #include "main.h" | ||
37 | #include "model.h" | ||
38 | #include "glarea.h" | ||
39 | #include "gui_glade.h" | ||
40 | #include "trackball.h" | ||
41 | #include "gl.h" | ||
42 | |||
43 | static gboolean parse_only = FALSE; | ||
44 | |||
45 | static int main_parseargs(int *argc, char ***argv, G3DViewer *viewer); | ||
46 | static void main_cleanup(G3DViewer *viewer); | ||
47 | |||
48 | int main(int argc, char **argv) | ||
49 | { | ||
50 | G3DViewer *viewer; | ||
51 | |||
52 | /* localization stuff */ | ||
53 | setlocale(LC_ALL, ""); | ||
54 | bindtextdomain("g3dviewer", LOCALEDIR); | ||
55 | textdomain("g3dviewer"); | ||
56 | |||
57 | #if DEBUG > 3 | ||
58 | /* memory debugging */ | ||
59 | atexit(g_mem_profile); | ||
60 | g_mem_set_vtable(glib_mem_profiler_table); | ||
61 | #endif | ||
62 | |||
63 | gtk_init(&argc, &argv); | ||
64 | |||
65 | #if DEBUG > 0 | ||
66 | /* gdb stack trace in case of error */ | ||
67 | g_on_error_stack_trace(NULL); | ||
68 | #endif | ||
69 | |||
70 | gtk_gl_init(&argc, &argv); | ||
71 | |||
72 | /* create viewer and fill with defaults | ||
73 | * TODO: move to separate function */ | ||
74 | viewer = g_new0(G3DViewer, 1); | ||
75 | viewer->zoom = 45; | ||
76 | viewer->mouse.beginx = 0; | ||
77 | viewer->mouse.beginy = 0; | ||
78 | viewer->filename = NULL; | ||
79 | viewer->bgcolor[0] = 0.9; | ||
80 | viewer->bgcolor[1] = 0.8; | ||
81 | viewer->bgcolor[2] = 0.6; | ||
82 | viewer->bgcolor[3] = 1.0; | ||
83 | viewer->glflags = | ||
84 | /* G3D_FLAG_GL_SPECULAR | */ | ||
85 | G3D_FLAG_GL_SHININESS | | ||
86 | G3D_FLAG_GL_ALLTWOSIDE | | ||
87 | G3D_FLAG_GL_TEXTURES; | ||
88 | |||
89 | viewer->g3dcontext = g3d_context_new(); | ||
90 | |||
91 | main_parseargs(&argc, &argv, viewer); | ||
92 | |||
93 | trackball(viewer->quat, 0.0, 0.0, 0.0, 0.0); | ||
94 | |||
95 | /* the gui related stuff */ | ||
96 | gui_glade_init(viewer); | ||
97 | gui_glade_load(viewer); | ||
98 | |||
99 | /* register gui callbacks */ | ||
100 | g3d_context_set_set_bgcolor_func(viewer->g3dcontext, | ||
101 | gui_glade_set_bgcolor_cb, viewer); | ||
102 | g3d_context_set_update_interface_func(viewer->g3dcontext, | ||
103 | gui_glade_update_interface_cb, viewer); | ||
104 | g3d_context_set_update_progress_bar_func(viewer->g3dcontext, | ||
105 | gui_glade_update_progress_bar_cb, viewer); | ||
106 | |||
107 | /* load model or show open dialog */ | ||
108 | if(viewer->filename != NULL) | ||
109 | { | ||
110 | model_load(viewer); | ||
111 | glarea_update(viewer->interface.glarea); | ||
112 | } | ||
113 | else | ||
114 | gui_glade_open_dialog(viewer); | ||
115 | |||
116 | /* for debugging reasons */ | ||
117 | if(parse_only) | ||
118 | return EXIT_SUCCESS; | ||
119 | |||
120 | /* ... aaaand go! */ | ||
121 | gtk_main(); | ||
122 | |||
123 | /* cleaning up :-/ */ | ||
124 | main_cleanup(viewer); | ||
125 | |||
126 | return EXIT_SUCCESS; | ||
127 | } | ||
128 | |||
129 | static void main_showhelp(void) | ||
130 | { | ||
131 | printf( | ||
132 | "g3dviewer - a 3D model viewer\n" | ||
133 | "\n" | ||
134 | "usage: g3dviewer [--option ...] [<filename>]\n" | ||
135 | "where option can be:\n" | ||
136 | " --help show this help screen\n" | ||
137 | ); | ||
138 | exit(1); | ||
139 | } | ||
140 | |||
141 | static int main_parseargs(int *argc, char ***argv, G3DViewer *viewer) | ||
142 | { | ||
143 | /* program name */ | ||
144 | (*argc)--; | ||
145 | (*argv)++; | ||
146 | while(*argc > 0) | ||
147 | { | ||
148 | #if DEBUG > 3 | ||
149 | g_printerr("arg: %s\n", **argv); | ||
150 | #endif | ||
151 | if(strcmp(**argv, "--help") == 0) main_showhelp(); | ||
152 | else if(strcmp(**argv, "--parse-only") == 0) | ||
153 | { | ||
154 | parse_only = TRUE; | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | viewer->filename = **argv; | ||
159 | } | ||
160 | (*argv)++; | ||
161 | (*argc)--; | ||
162 | } | ||
163 | |||
164 | return EXIT_SUCCESS; | ||
165 | } | ||
166 | |||
167 | static void main_cleanup(G3DViewer *viewer) | ||
168 | { | ||
169 | g3d_context_free(viewer->g3dcontext); | ||
170 | if(viewer->filename != NULL) g_free(viewer->filename); | ||
171 | g_free(viewer); | ||
172 | } | ||