aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/g3dviewer-0.2.99.4/thumbnailer/g3d-thumbnailer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/g3dviewer-0.2.99.4/thumbnailer/g3d-thumbnailer.c')
-rw-r--r--src/others/mimesh/g3dviewer-0.2.99.4/thumbnailer/g3d-thumbnailer.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/others/mimesh/g3dviewer-0.2.99.4/thumbnailer/g3d-thumbnailer.c b/src/others/mimesh/g3dviewer-0.2.99.4/thumbnailer/g3d-thumbnailer.c
new file mode 100644
index 0000000..92acd0b
--- /dev/null
+++ b/src/others/mimesh/g3dviewer-0.2.99.4/thumbnailer/g3d-thumbnailer.c
@@ -0,0 +1,164 @@
1/* $Id: g3d-thumbnailer.c 61 2006-11-09 15:31:12Z 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#include <stdio.h>
24#include <stdlib.h>
25
26#include <X11/Xlib.h>
27#include <GL/glx.h>
28
29#include <gtk/gtk.h>
30#include <glib.h>
31#include <g3d/g3d.h>
32
33#include "gl.h"
34#include "trackball.h"
35#include "screenshot.h"
36#include "texture.h"
37
38static gboolean setup_gl(guint32 width, guint32 height)
39{
40 Display *display;
41 XVisualInfo *visinfo;
42 Pixmap pixmap;
43 GLXPixmap glxpixmap;
44 GLXContext glxctx;
45 char *dpyname;
46 int attrlist_dbl[] = {
47 GLX_RGBA,
48 GLX_DOUBLEBUFFER,
49 GLX_RED_SIZE, 1,
50 GLX_GREEN_SIZE, 1,
51 GLX_BLUE_SIZE, 1,
52 None};
53 int attrlist_sng[] = {
54 GLX_RGBA,
55 GLX_RED_SIZE, 1,
56 GLX_GREEN_SIZE, 1,
57 GLX_BLUE_SIZE, 1,
58 None};
59
60 dpyname = getenv("DISPLAY");
61
62 display = XOpenDisplay(dpyname);
63 if(display == NULL)
64 {
65 g_printerr("ERROR: could not open display '%s'\n",
66 dpyname ? dpyname : "(null)");
67 return FALSE;
68 }
69
70 visinfo = glXChooseVisual(display, DefaultScreen(display), attrlist_sng);
71 if(visinfo == NULL)
72 {
73 /* try with double buffering */
74 visinfo = glXChooseVisual(display, DefaultScreen(display),
75 attrlist_dbl);
76 if(visinfo == NULL)
77 {
78 g_printerr("ERROR: could not get a supported visual\n");
79 return FALSE;
80 }
81 }
82
83 glxctx = glXCreateContext(display, visinfo, 0, GL_FALSE);
84 if(glxctx == NULL)
85 {
86 g_printerr("ERROR: could not create GLX context\n");
87 return FALSE;
88 }
89
90 pixmap = XCreatePixmap(display, RootWindow(display, visinfo->screen),
91 width, height, visinfo->depth);
92 if(pixmap <= 0)
93 {
94 g_printerr("ERROR: could not create pixmap\n");
95 return FALSE;
96 }
97
98 glxpixmap = glXCreateGLXPixmap(display, visinfo, pixmap);
99 if(glxpixmap <= 0)
100 {
101 g_printerr("ERROR: could not create GLX pixmap\n");
102 return FALSE;
103 }
104
105 glXMakeCurrent(display, glxpixmap, glxctx);
106
107 return TRUE;
108}
109
110int main(int argc, char *argv[])
111{
112 G3DContext *context;
113 G3DModel *model;
114 gfloat bgcolor[4] = { 1.0, 1.0, 1.0, 0.0 };
115 gfloat quat[4] = { 0.10, -0.31, -0.87, 0.38 };
116 guint32 width = 128;
117 guint32 height = 128;
118
119 gtk_init(&argc, &argv);
120
121 setup_gl(width, height);
122
123 if(argc < 3)
124 {
125 g_print("usage: %s <input file: model> <output file: image> "
126 "[<width in px>]\n",
127 argv[0]);
128 return EXIT_FAILURE;
129 }
130
131 if(argc > 3)
132 {
133 /* size */
134 width = atoi(argv[3]);
135 /* height = width / 4 * 3; */
136 height = width;
137 }
138
139 context = g3d_context_new();
140 model = g3d_model_load(context, argv[1]);
141
142 if(model)
143 {
144 texture_load_all_textures(model);
145
146 gl_draw(
147 G3D_FLAG_GL_SHININESS | G3D_FLAG_GL_ALLTWOSIDE |
148 G3D_FLAG_GL_TEXTURES,
149 45 /* zoom */,
150 (gfloat)width / (gfloat)height,
151 bgcolor,
152 quat,
153 model);
154
155 glXWaitGL();
156
157 if(screenshot_save(argv[2], width, height))
158 {
159 return EXIT_SUCCESS;
160 }
161 }
162
163 return EXIT_FAILURE;
164}