File: test_lib.c

package info (click to toggle)
libg3d 0.0.8-26
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,700 kB
  • sloc: ansic: 27,295; sh: 9,288; xml: 4,123; makefile: 865; cpp: 13
file content (99 lines) | stat: -rw-r--r-- 2,200 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* $Id: test_lib.c,v 1.1.2.2 2006/01/23 17:04:37 dahms Exp $ */

/*
    libg3d - 3D object loading library

    Copyright (C) 2005-2009  Markus Dahms <mad@automagically.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdio.h>
#include <stdlib.h>

#include <g3d/g3d.h>

#if 0
#define DEBUG_MEM 1
#endif

#ifdef DEBUG_MEM
static gpointer (*def_malloc)(gsize size) = NULL;

static void break_here(gsize size)
{
	g_printerr("I'm here (%d bytes)\n", size);
}

static gpointer malloc_debug(gsize size)
{
	if(size == 84)
	{
		break_here(size);
	}

	return def_malloc(size);
}
#endif

int main(int argc, char *argv[])
{
	G3DContext *context;
	G3DModel *model;
	G3DObject *object;
	GSList *oitem;
	guint32 i;

#ifdef DEBUG_MEM
	atexit(g_mem_profile);
	def_malloc = glib_mem_profiler_table->malloc;
	glib_mem_profiler_table->malloc = malloc_debug;
	g_mem_set_vtable(glib_mem_profiler_table);
#endif

	context = g3d_context_new();

	if(argc > 1)
	{
		model = g3d_model_load(context, argv[1]);

		if(model)
		{
			g_print("%s: %d objects:\n", argv[1],
				g_slist_length(model->objects));

			i = 0;
			oitem = model->objects;
			while(oitem)
			{
				object = (G3DObject *)oitem->data;
				g_print("  [%2u] %-50s (%d faces, %d mats)\n",
					i,
					object->name ? object->name : "(NULL)",
					g_slist_length(object->faces),
					g_slist_length(object->materials));

				oitem = oitem->next;
				i ++;
			}

			g3d_model_free(model);
		}
	}

	g3d_context_free(context);

	return EXIT_SUCCESS;
}