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