put the revision number in the splash screen (scons and make)
[blender.git] / source / creator / creator.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32 #include <stdlib.h>
33 #include <string.h>
34
35 /* This little block needed for linking to Blender... */
36
37 #include "MEM_guardedalloc.h"
38
39 #ifdef WIN32
40 #include "BLI_winstuff.h"
41 #endif
42
43 #include "GEN_messaging.h"
44
45 #include "DNA_ID.h"
46 #include "DNA_scene_types.h"
47
48 #include "BLI_blenlib.h"
49 #include "blendef.h" /* for MAXFRAME */
50
51
52 #include "BKE_utildefines.h"
53 #include "BKE_blender.h"
54 #include "BKE_font.h"
55 #include "BKE_global.h"
56 #include "BKE_main.h"
57 #include "BKE_material.h"
58 #include "BKE_packedFile.h"
59 #include "BKE_scene.h"
60 #include "BKE_node.h"
61
62 #include "BIF_gl.h"
63 #include "BIF_graphics.h"
64 #include "BIF_mainqueue.h"
65 #include "BIF_graphics.h"
66 #include "BIF_editsound.h"
67 #include "BIF_usiblender.h"
68 #include "BIF_drawscene.h"      /* set_scene() */
69 #include "BIF_screen.h"         /* waitcursor and more */
70 #include "BIF_usiblender.h"
71 #include "BIF_toolbox.h"
72
73 #include "BLO_writefile.h"
74 #include "BLO_readfile.h"
75
76 #include "BDR_drawmesh.h"
77
78 #include "IMB_imbuf.h"  // for quicktime_init
79
80 #include "BPY_extern.h"
81
82 #include "RE_pipeline.h"
83
84 #include "playanim_ext.h"
85 #include "mydevice.h"
86 #include "nla.h"
87 #include "datatoc.h"
88
89 /* for passing information between creator and gameengine */
90 #include "SYS_System.h"
91
92 #include <signal.h>
93
94 #ifdef __FreeBSD__
95 # include <sys/types.h>
96 # include <floatingpoint.h>
97 # include <sys/rtprio.h>
98 #endif
99
100 // from buildinfo.c
101 #ifdef BUILD_DATE
102 extern char * build_date;
103 extern char * build_time;
104 extern char * build_platform;
105 extern char * build_type;
106 #endif
107
108 /*      Local Function prototypes */
109 static void print_help();
110 static void print_version();
111
112
113 /* defined in ghostwinlay and winlay, we can't include carbon here, conflict with DNA */
114 #ifdef __APPLE__
115 extern int checkAppleVideoCard(void);
116 extern void getMacAvailableBounds(short *top, short *left, short *bottom, short *right);
117 extern void     winlay_get_screensize(int *width_r, int *height_r);
118 extern void     winlay_process_events(int wait_for_event);
119 #endif
120
121
122 /* for the callbacks: */
123
124 extern int pluginapi_force_ref(void);  /* from blenpluginapi:pluginapi.c */
125
126 char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */
127
128
129 /* Initialise callbacks for the modules that need them */
130 void setCallbacks(void); 
131
132 #if defined(__sgi) || defined(__alpha__)
133 static void fpe_handler(int sig)
134 {
135         // printf("SIGFPE trapped\n");
136 }
137 #endif
138
139 /* handling ctrl-c event in console */
140 static void blender_esc(int sig)
141 {
142         static int count = 0;
143         
144         G.afbreek = 1;  /* forces render loop to read queue, not sure if its needed */
145         
146         if (sig == 2) {
147                 if (count) {
148                         printf("\nBlender killed\n");
149                         exit(2);
150                 }
151                 printf("\nSent an internal break event. Press ^C again to kill Blender\n");
152                 count++;
153         }
154 }
155
156 static void print_version(void)
157 {
158 #ifdef BUILD_DATE
159         printf ("Blender %d.%02d (sub %d) Build\n", G.version/100, G.version%100, BLENDER_SUBVERSION);
160         printf ("\tbuild date: %s\n", build_date);
161         printf ("\tbuild time: %s\n", build_time);
162         printf ("\tbuild revision: %s\n", build_rev);
163         printf ("\tbuild platform: %s\n", build_platform);
164         printf ("\tbuild type: %s\n", build_type);
165 #else
166         printf ("Blender %d.%02d (sub %d) Build\n", G.version/100, G.version%100, BLENDER_SUBVERSION);
167 #endif
168 }
169
170 static void print_help(void)
171 {
172         printf ("Blender %d.%02d (sub %d) Build\n", G.version/100, G.version%100, BLENDER_SUBVERSION);
173         printf ("Usage: blender [options ...] [file]\n");
174         
175         printf ("\nRender options:\n");
176         printf ("  -b <file>\tRender <file> in background\n");
177         printf ("    -S <name>\tSet scene <name>\n");
178         printf ("    -f <frame>\tRender frame <frame> and save it\n");                          
179         printf ("    -s <frame>\tSet start to frame <frame> (use with -a)\n");
180         printf ("    -e <frame>\tSet end to frame (use with -a)<frame>\n");
181         printf ("    -o <path>\tSet the render path and file name.\n");
182         printf ("      Use // at the start of the path to\n");
183         printf ("        render relative to the blend file.\n");
184         printf ("      The frame number will be added at the end of the filename.\n");
185         printf ("      eg: blender -b foobar.blend -o //render_ -F PNG -x 1\n");
186         printf ("    -F <format>\tSet the render format, Valid options are..\n");
187         printf ("    \tTGA IRIS HAMX FTYPE JPEG MOVIE IRIZ RAWTGA\n");
188         printf ("    \tAVIRAW AVIJPEG PNG BMP FRAMESERVER\n");
189         printf ("    (formats that can be compiled into blender, not available on all systems)\n");
190         printf ("    \tHDR TIFF EXR MPEG AVICODEC QUICKTIME CINEON DPX\n");
191         printf ("    -x <bool>\tSet option to add the file extension to the end of the file.\n");
192         printf ("    -t <threads>\tUse amount of <threads> for rendering\n");
193         printf ("\nAnimation options:\n");
194         printf ("  -a <file(s)>\tPlayback <file(s)>\n");
195         printf ("    -p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>\n");
196         printf ("    -m\t\tRead from disk (Don't buffer)\n");
197                                 
198         printf ("\nWindow options:\n");
199         printf ("  -w\t\tForce opening with borders (default)\n");
200         printf ("  -W\t\tForce opening without borders\n");
201         printf ("  -p <sx> <sy> <w> <h>\tOpen with lower left corner at <sx>, <sy>\n");
202         printf ("                      \tand width and height <w>, <h>\n");
203         printf ("\nGame Engine specific options:\n");
204         printf ("  -g fixedtime\t\tRun on 50 hertz without dropping frames\n");
205         printf ("  -g vertexarrays\tUse Vertex Arrays for rendering (usually faster)\n");
206         printf ("  -g noaudio\t\tNo audio in Game Engine\n");
207         printf ("  -g nomipmap\t\tNo Texture Mipmapping\n");
208         printf ("  -g linearmipmap\tLinear Texture Mipmapping instead of Nearest (default)\n");
209
210         printf ("\nMisc options:\n");
211         printf ("  -d\t\tTurn debugging on\n");
212         printf ("  -noaudio\tDisable audio on systems that support audio\n");
213         printf ("  -h\t\tPrint this help text\n");
214         printf ("  -y\t\tDisable script links, use -Y to find out why its -y\n");
215         printf ("  -P <filename>\tRun the given Python script (filename or Blender Text)\n");
216 #ifdef WIN32
217         printf ("  -R\t\tRegister .blend extension\n");
218 #endif
219         printf ("  -v\t\tPrint Blender version and exit\n");
220         printf ("  --\t\tEnds option processing.  Following arguments are \n");
221         printf ("    \t\t   passed unchanged.  Access via Python's sys.argv\n");
222 }
223
224
225 double PIL_check_seconds_timer(void);
226 extern void winlay_get_screensize(int *width_r, int *height_r);
227
228 int main(int argc, char **argv)
229 {
230         int a, i, stax, stay, sizx, sizy;
231         SYS_SystemHandle syshandle;
232         Scene *sce;
233
234 #if defined(WIN32) || defined (__linux__)
235         int audio = 1;
236 #else
237         int audio = 0;
238 #endif
239
240         setCallbacks();
241 #ifdef __APPLE__
242                 /* patch to ignore argument finder gives us (pid?) */
243         if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) {
244                 extern int GHOST_HACK_getFirstFile(char buf[]);
245                 static char firstfilebuf[512];
246                 int scr_x,scr_y;
247
248                 argc= 1;
249
250         /* first let us check if we are hardware accelerated and with VRAM > 16 Mo */
251         
252         if (checkAppleVideoCard()) {
253                         short top, left, bottom, right;
254                         
255                         winlay_get_screensize(&scr_x, &scr_y); 
256                         getMacAvailableBounds(&top, &left, &bottom, &right);
257                         setprefsize(left +10,scr_y - bottom +10,right-left -20,bottom - 64, 0);
258
259         } else {
260                                 winlay_get_screensize(&scr_x, &scr_y);
261
262                 /* 40 + 684 + (headers) 22 + 22 = 768, the powerbook screen height */
263                 setprefsize(120, 40, 850, 684, 0);
264         }
265     
266                 winlay_process_events(0);
267                 if (GHOST_HACK_getFirstFile(firstfilebuf)) {
268                         argc= 2;
269                         argv[1]= firstfilebuf;
270                 }
271         }
272
273 #endif
274
275 #ifdef __FreeBSD__
276         fpsetmask(0);
277 #endif
278 #ifdef __linux__
279     #ifdef __alpha__
280         signal (SIGFPE, fpe_handler);
281     #else
282         if ( getenv("SDL_AUDIODRIVER") == NULL) {
283                 setenv("SDL_AUDIODRIVER", "dma", 1);
284         }
285     #endif
286 #endif
287 #if defined(__sgi)
288         signal (SIGFPE, fpe_handler);
289 #endif
290
291         // copy path to executable in bprogname. playanim and creting runtimes
292         // need this.
293
294         BLI_where_am_i(bprogname, argv[0]);
295
296                 /* Hack - force inclusion of the plugin api functions,
297                  * see blenpluginapi:pluginapi.c
298                  */
299         pluginapi_force_ref();
300         
301         init_nodesystem();
302         
303         initglobals();  /* blender.c */
304
305         syshandle = SYS_GetSystem();
306         GEN_init_messaging_system();
307
308         /* first test for background */
309
310         G.f |= G_DOSCRIPTLINKS; /* script links enabled by default */
311
312         for(a=1; a<argc; a++) {
313
314                 /* Handle unix and windows style help requests */
315                 if ((!strcmp(argv[a], "--help")) || (!strcmp(argv[a], "/?"))){
316                         print_help();
317                         exit(0);
318                 }
319
320                 /* end argument processing after -- */
321                 if (!strcmp( argv[a], "--")){
322                         a = argc;
323                         break;
324                 }
325
326                 /* Handle long version request */
327                 if (!strcmp(argv[a], "--version")){
328                         print_version();
329                         exit(0);
330                 }
331
332                 /* Handle -* switches */
333                 else if(argv[a][0] == '-') {
334                         switch(argv[a][1]) {
335                         case 'a':
336                                 playanim(argc-1, argv+1);
337                                 exit(0);
338                                 break;
339                         case 'b':
340                         case 'B':
341                                 G.background = 1;
342                                 a= argc;
343                                 break;
344
345                         case 'y':
346                                 G.f &= ~G_DOSCRIPTLINKS;
347                                 break;
348
349                         case 'Y':
350                                 printf ("-y was used to disable script links because,\n");
351                                 printf ("\t-p being taken, Ton was of the opinion that Y\n");
352                                 printf ("\tlooked like a split (disabled) snake, and also\n");
353                                 printf ("\twas similar to a python's tongue (unproven).\n\n");
354
355                                 printf ("\tZr agreed because it gave him a reason to add a\n");
356                                 printf ("\tcompletely useless text into Blender.\n\n");
357                                 
358                                 printf ("\tADDENDUM! Ton, in defense, found this picture of\n");
359                                 printf ("\tan Australian python, exhibiting her (his/its) forked\n");
360                                 printf ("\tY tongue. It could be part of an H Zr retorted!\n\n");
361                                 printf ("\thttp://www.users.bigpond.com/snake.man/\n");
362                                 
363                                 exit(252);
364                                 
365                         case 'h':                       
366                                 print_help();
367                                 exit(0);
368                         case 'v':
369                                 print_version();
370                                 exit(0);
371                         default:
372                                 break;
373                         }
374                 }
375         }
376
377 #ifdef __sgi
378         setuid(getuid()); /* end superuser */
379 #endif
380
381         /* for all platforms, even windos has it! */
382         if(G.background) signal(SIGINT, blender_esc);   /* ctrl c out bg render */
383
384         /* background render uses this font too */
385         BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
386         
387         init_def_material();
388
389         if(G.background==0) {
390                 for(a=1; a<argc; a++) {
391                         if(argv[a][0] == '-') {
392                                 switch(argv[a][1]) {
393                                 case 'p':       /* prefsize */
394                                         if (argc-a < 5) {
395                                                 printf ("-p requires four arguments\n");
396                                                 exit(1);
397                                         }
398                                         a++;
399                                         stax= atoi(argv[a]);
400                                         a++;
401                                         stay= atoi(argv[a]);
402                                         a++;
403                                         sizx= atoi(argv[a]);
404                                         a++;
405                                         sizy= atoi(argv[a]);
406
407                                         setprefsize(stax, stay, sizx, sizy, 0);
408                                         break;
409                                 case 'd':
410                                         G.f |= G_DEBUG;         /* std output printf's */ 
411                                         printf ("Blender %d.%02d (sub %d) Build\n", G.version/100, G.version%100, BLENDER_SUBVERSION);
412                                         MEM_set_memory_debug();
413 #ifdef NAN_BUILDINFO
414                                         printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
415
416 #endif // NAN_BUILDINFO
417                                         for (i = 0; i < argc; i++) {
418                                                 printf("argv[%d] = %s\n", i, argv[i]);
419                                         }
420                                         break;
421             
422                                 case 'w':
423                                         /* XXX, fixme zr, with borders */
424                                         /* there probably is a better way to do
425                                          * this, right now do as if blender was
426                                          * called with "-p 0 0 xres yres" -- sgefant
427                                          */ 
428                                         winlay_get_screensize(&sizx, &sizy);
429                                         setprefsize(0, 0, sizx, sizy, 1);
430                                         G.windowstate = G_WINDOWSTATE_BORDER;
431                                         break;
432                                 case 'W':
433                                         /* XXX, fixme zr, borderless on win32 */
434                                         /* now on all platforms as of 20070411 - DJC */
435                                         G.windowstate = G_WINDOWSTATE_FULLSCREEN;
436                                         break;
437                                 case 'R':
438                                         /* Registering filetypes only makes sense on windows...      */
439 #ifdef WIN32
440                                         RegisterBlendExtension(argv[0]);
441 #endif
442                                         break;
443                                 case 'n':
444                                 case 'N':
445                                         if (BLI_strcasecmp(argv[a], "-noaudio") == 0|| BLI_strcasecmp(argv[a], "-nosound") == 0) {
446                                                 /**
447                                                         notify the gameengine that no audio is wanted, even if the user didn't give
448                                                         the flag -g noaudio.
449                                                 */
450
451                                                 SYS_WriteCommandLineInt(syshandle,"noaudio",1);
452                                                 audio = 0;
453                                                 if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
454                                         }
455                                         break;
456                                 }
457                         }
458                 }
459
460                 BPY_start_python(argc, argv);
461                 
462                 /**
463                  * NOTE: sound_init_audio() *must be* after start_python,
464                  * at least on FreeBSD.
465                  * added note (ton): i removed it altogether
466                  */
467
468                 BIF_init();
469
470         }
471         else {
472                 BPY_start_python(argc, argv);
473                 
474                 // (ton) Commented out. I have no idea whats thisfor... will mail around!
475                 // SYS_WriteCommandLineInt(syshandle,"noaudio",1);
476         // audio = 0;
477         // sound_init_audio();
478         // if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
479         }
480
481         /**
482          * NOTE: the U.pythondir string is NULL until BIF_init() is executed,
483          * so we provide the BPY_ function below to append the user defined
484          * pythondir to Python's sys.path at this point.  Simply putting
485          * BIF_init() before BPY_start_python() crashes Blender at startup.
486          * Update: now this function also inits the bpymenus, which also depend
487          * on U.pythondir.
488          */
489         BPY_post_start_python();
490
491 #ifdef WITH_QUICKTIME
492
493         quicktime_init();
494
495 #endif /* WITH_QUICKTIME */
496
497         /* dynamically load libtiff, if available */
498         libtiff_init();
499         if (!G.have_libtiff && (G.f & G_DEBUG)) {
500                 printf("Unable to load: libtiff.\n");
501                 printf("Try setting the BF_TIFF_LIB environment variable if you want this support.\n");
502                 printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n");
503         }
504
505         /* OK we are ready for it */
506
507         for(a=1; a<argc; a++) {
508                 if (G.afbreek==1) break;
509
510                 if(argv[a][0] == '-') {
511                         switch(argv[a][1]) {
512                         case '-':  /* -- ends argument processing */
513                                 a = argc;
514                                 break;
515                                 
516                         case 'p':       /* prefsize */
517                                 a+= 4;
518                                 break;
519
520                         case 'g':
521                                 {
522                                 /**
523                                 gameengine parameters are automaticly put into system
524                                 -g [paramname = value]
525                                 -g [boolparamname]
526                                 example:
527                                 -g novertexarrays
528                                 -g maxvertexarraysize = 512
529                                 */
530
531                                         if(++a < argc)
532                                         {
533                                                 char* paramname = argv[a];
534                                                 /* check for single value versus assignment */
535                                                 if (a+1 < argc && (*(argv[a+1]) == '='))
536                                                 {
537                                                         a++;
538                                                         if (a+1 < argc)
539                                                         {
540                                                                 a++;
541                                                                 /* assignment */
542                                                                 SYS_WriteCommandLineString(syshandle,paramname,argv[a]);
543                                                         }  else
544                                                         {
545                                                                 printf("error: argument assignment (%s) without value.\n",paramname);
546                                                         }
547                                                         /* name arg eaten */
548
549                                                 } else
550                                                 {
551                                                         SYS_WriteCommandLineInt(syshandle,argv[a],1);
552
553                                                         /* doMipMap */
554                                                         if (!strcmp(argv[a],"nomipmap"))
555                                                         {
556                                                                 set_mipmap(0); //doMipMap = 0;
557                                                         }
558                                                         /* linearMipMap */
559                                                         if (!strcmp(argv[a],"linearmipmap"))
560                                                         {
561                                                                 set_linear_mipmap(1); //linearMipMap = 1;
562                                                         }
563
564
565                                                 } /* if (*(argv[a+1]) == '=') */
566                                         } /*    if(++a < argc)  */
567                                         break;
568                                 }
569                         case 'f':
570                                 a++;
571                                 if (G.scene) {
572                                         if (a < argc) {
573                                                 int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
574                                                 Render *re= RE_NewRender(G.scene->id.name);
575                                                 RE_BlenderAnim(re, G.scene, frame, frame);
576                                         }
577                                 } else {
578                                         printf("\nError: no blend loaded. cannot use '-f'.\n");
579                                 }
580                                 break;
581                         case 'a':
582                                 if (G.scene) {
583                                         Render *re= RE_NewRender(G.scene->id.name);
584                                         RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
585                                 } else {
586                                         printf("\nError: no blend loaded. cannot use '-a'.\n");
587                                 }
588                                 break;
589                         case 'S':
590                                 if(++a < argc) {
591                                         set_scene_name(argv[a]);
592                                 }
593                                 break;
594                         case 's':
595                                 a++;
596                                 if(G.scene) {
597                                         int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
598                                         if (a < argc) (G.scene->r.sfra) = frame;
599                                 } else {
600                                         printf("\nError: no blend loaded. cannot use '-s'.\n");
601                                 }
602                                 break;
603                         case 'e':
604                                 a++;
605                                 if(G.scene) {
606                                         int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
607                                         if (a < argc) (G.scene->r.efra) = frame;
608                                 } else {
609                                         printf("\nError: no blend loaded. cannot use '-e'.\n");
610                                 }
611                                 break;
612                         case 'P':
613                                 a++;
614                                 if (a < argc) BPY_run_python_script (argv[a]);
615                                 else printf("\nError: you must specify a Python script after '-P '.\n");
616                                 break;
617                         case 'o':
618                                 a++;
619                                 if (a < argc){
620                                         if(G.scene) {
621                                                 BLI_strncpy(G.scene->r.pic, argv[a], FILE_MAXDIR);
622                                         } else {
623                                                 printf("\nError: no blend loaded. cannot use '-o'.\n");
624                                         }
625                                 } else {
626                                         printf("\nError: you must specify a path after '-o '.\n");
627                                 }
628                                 break;
629                         case 'F':
630                                 a++;
631                                 if (a < argc){
632                                         if(!G.scene) {
633                                                 printf("\nError: no blend loaded. order the arguments so '-F ' is after the blend is loaded.\n");
634                                         } else {
635                                                 if      (!strcmp(argv[a],"TGA")) G.scene->r.imtype = R_TARGA;
636                                                 else if (!strcmp(argv[a],"IRIS")) G.scene->r.imtype = R_IRIS;
637                                                 else if (!strcmp(argv[a],"HAMX")) G.scene->r.imtype = R_HAMX;
638                                                 else if (!strcmp(argv[a],"FTYPE")) G.scene->r.imtype = R_FTYPE;
639                                                 else if (!strcmp(argv[a],"JPEG")) G.scene->r.imtype = R_JPEG90;
640                                                 else if (!strcmp(argv[a],"MOVIE")) G.scene->r.imtype = R_MOVIE;
641                                                 else if (!strcmp(argv[a],"IRIZ")) G.scene->r.imtype = R_IRIZ;
642                                                 else if (!strcmp(argv[a],"RAWTGA")) G.scene->r.imtype = R_RAWTGA;
643                                                 else if (!strcmp(argv[a],"AVIRAW")) G.scene->r.imtype = R_AVIRAW;
644                                                 else if (!strcmp(argv[a],"AVIJPEG")) G.scene->r.imtype = R_AVIJPEG;
645                                                 else if (!strcmp(argv[a],"PNG")) G.scene->r.imtype = R_PNG;
646                                                 else if (!strcmp(argv[a],"AVICODEC")) G.scene->r.imtype = R_AVICODEC;
647                                                 else if (!strcmp(argv[a],"QUICKTIME")) G.scene->r.imtype = R_QUICKTIME;
648                                                 else if (!strcmp(argv[a],"BMP")) G.scene->r.imtype = R_BMP;
649                                                 else if (!strcmp(argv[a],"HDR")) G.scene->r.imtype = R_RADHDR;
650                                                 else if (!strcmp(argv[a],"TIFF")) G.scene->r.imtype = R_IRIS;
651                                                 else if (!strcmp(argv[a],"EXR")) G.scene->r.imtype = R_OPENEXR;
652                                                 else if (!strcmp(argv[a],"MPEG")) G.scene->r.imtype = R_FFMPEG;
653                                                 else if (!strcmp(argv[a],"FRAMESERVER")) G.scene->r.imtype = R_FRAMESERVER;
654                                                 else if (!strcmp(argv[a],"CINEON")) G.scene->r.imtype = R_CINEON;
655                                                 else if (!strcmp(argv[a],"DPX")) G.scene->r.imtype = R_DPX;
656                                                 else printf("\nError: Format from '-F ' not known.\n");
657                                         }
658                                 } else {
659                                         printf("\nError: no blend loaded. cannot use '-x'.\n");
660                                 }
661                                 break;
662                                 
663                         case 't':
664                                 a++;
665                                 if(G.background) {
666                                         RE_set_max_threads(atoi(argv[a]));
667                                 }
668                                 break;
669                         case 'x': /* extension */
670                                 a++;
671                                 if (a < argc) {
672                                         if(G.scene) {
673                                                 if (argv[a][0] == '0') {
674                                                         G.scene->r.scemode &= ~R_EXTENSION;
675                                                 } else if (argv[a][0] == '1') {
676                                                         G.scene->r.scemode |= R_EXTENSION;
677                                                 } else {
678                                                         printf("\nError: Use '-x 1' or '-x 0' To set the extension option.\n");
679                                                 }
680                                         } else {
681                                                 printf("\nError: no blend loaded. order the arguments so '-o ' is after '-x '.\n");
682                                         }
683                                 } else {
684                                         printf("\nError: you must specify a path after '- '.\n");
685                                 }
686                                 break;
687                         }
688                 }
689                 else {
690                         BKE_read_file(argv[a], NULL);
691                         sound_initialize_sounds();
692                         
693                         /* happens for the UI on file reading too */
694                         BKE_reset_undo();
695                         BKE_write_undo("original");     /* save current state */
696                 }
697         }
698
699         if(G.background) {
700                 /* actually incorrect, but works for now (ton) */
701                 exit_usiblender();
702         }
703
704         setscreen(G.curscreen);
705
706         if(G.main->scene.first==0) {
707                 sce= add_scene("1");
708                 set_scene(sce);
709         }
710
711         screenmain();
712
713         return 0;
714 } /* end of int main(argc,argv) */
715
716 static void error_cb(char *err)
717 {
718         error("%s", err);
719 }
720
721 static void mem_error_cb(char *errorStr)
722 {
723         fprintf(stderr, errorStr);
724         fflush(stderr);
725 }
726
727 void setCallbacks(void)
728 {
729         /* Error output from the alloc routines: */
730         MEM_set_error_callback(mem_error_cb);
731
732
733         /* BLI_blenlib: */
734
735         BLI_setErrorCallBack(error_cb); /* */
736         BLI_setInterruptCallBack(blender_test_break);
737
738 }