37df17e3bad2c869b6f0a86c4887f2186ff3757c
[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         /* temporary: prevent people to make/use 64 bits versions without them knowing it might be
239                 risky. I don't know for sure yet if we get problems, but I rather not get the burden of
240                 having to fix all faulty saved 64 bits files (ton) */
241         if(sizeof(void *)==8) {
242                 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"); 
243                 exit(0);
244         }
245
246         setCallbacks();
247 #ifdef __APPLE__
248                 /* patch to ignore argument finder gives us (pid?) */
249         if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) {
250                 extern int GHOST_HACK_getFirstFile(char buf[]);
251                 static char firstfilebuf[512];
252                 int scr_x,scr_y;
253
254                 argc= 1;
255
256         /* first let us check if we are hardware accelerated and with VRAM > 16 Mo */
257         
258         if (checkAppleVideoCard()) {
259                         short top, left, bottom, right;
260                         
261                         winlay_get_screensize(&scr_x, &scr_y); 
262                         getMacAvailableBounds(&top, &left, &bottom, &right);
263                         setprefsize(left +10,scr_y - bottom +10,right-left -20,bottom - 64);
264
265         } else {
266                                 winlay_get_screensize(&scr_x, &scr_y);
267
268                 /* 40 + 684 + (headers) 22 + 22 = 768, the powerbook screen height */
269                 setprefsize(120, 40, 850, 684);
270         }
271     
272                 winlay_process_events(0);
273                 if (GHOST_HACK_getFirstFile(firstfilebuf)) {
274                         argc= 2;
275                         argv[1]= firstfilebuf;
276                 }
277         }
278
279 #endif
280
281 #ifdef __FreeBSD__
282         fpsetmask(0);
283 #endif
284 #ifdef __linux__
285     #ifdef __alpha__
286         signal (SIGFPE, fpe_handler);
287     #else
288         if ( getenv("SDL_AUDIODRIVER") == NULL) {
289                 setenv("SDL_AUDIODRIVER", "dma", 1);
290         }
291     #endif
292 #endif
293 #if defined(__sgi)
294         signal (SIGFPE, fpe_handler);
295 #endif
296
297         // copy path to executable in bprogname. playanim and creting runtimes
298         // need this.
299
300         BLI_where_am_i(bprogname, argv[0]);
301
302                 /* Hack - force inclusion of the plugin api functions,
303                  * see blenpluginapi:pluginapi.c
304                  */
305         pluginapi_force_ref();
306         
307         initglobals();  /* blender.c */
308
309         syshandle = SYS_GetSystem();
310         GEN_init_messaging_system();
311
312         /* first test for background */
313
314         G.f |= G_DOSCRIPTLINKS; /* script links enabled by default */
315
316         for(a=1; a<argc; a++) {
317
318                 /* Handle unix and windows style help requests */
319                 if ((!strcmp(argv[a], "--help")) || (!strcmp(argv[a], "/?"))){
320                         print_help();
321                         exit(0);
322                 }
323
324                 /* Handle long version request */
325                 if (!strcmp(argv[a], "--version")){
326                         print_version();
327                         exit(0);
328                 }
329
330                 /* Handle -* switches */
331                 else if(argv[a][0] == '-') {
332                         switch(argv[a][1]) {
333                         case 'a':
334                                 playanim(argc-1, argv+1);
335                                 exit(0);
336                                 break;
337                         case 'b':
338                         case 'B':
339                                 G.background = 1;
340                                 a= argc;
341                                 break;
342
343                         case 'y':
344                                 G.f &= ~G_DOSCRIPTLINKS;
345                                 break;
346
347                         case 'Y':
348                                 printf ("-y was used to disable script links because,\n");
349                                 printf ("\t-p being taken, Ton was of the opinion that Y\n");
350                                 printf ("\tlooked like a split (disabled) snake, and also\n");
351                                 printf ("\twas similar to a python's tongue (unproven).\n\n");
352
353                                 printf ("\tZr agreed because it gave him a reason to add a\n");
354                                 printf ("\tcompletely useless text into Blender.\n\n");
355                                 
356                                 printf ("\tADDENDUM! Ton, in defense, found this picture of\n");
357                                 printf ("\tan Australian python, exhibiting her (his/its) forked\n");
358                                 printf ("\tY tongue. It could be part of an H Zr retorted!\n\n");
359                                 printf ("\thttp://www.users.bigpond.com/snake.man/\n");
360                                 
361                                 exit(252);
362                                 
363                         case 'h':                       
364                                 print_help();
365                                 exit(0);
366                         case 'v':
367                                 print_version();
368                                 exit(0);
369                         default:
370                                 break;
371                         }
372                 }
373         }
374
375 #ifdef __sgi
376         setuid(getuid()); /* end superuser */
377 #endif
378
379         /* for all platforms, even windos has it! */
380         if(G.background) signal(SIGINT, blender_esc);   /* ctrl c out bg render */
381
382                 /* background render uses this font too */
383         BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
384         
385         init_def_material();
386
387         if(G.background==0) {
388                 for(a=1; a<argc; a++) {
389                         if(argv[a][0] == '-') {
390                                 switch(argv[a][1]) {
391                                 case 'p':       /* prefsize */
392                                         if (argc-a < 5) {
393                                                 printf ("-p requires four arguments\n");
394                                                 exit(1);
395                                         }
396                                         a++;
397                                         stax= atoi(argv[a]);
398                                         a++;
399                                         stay= atoi(argv[a]);
400                                         a++;
401                                         sizx= atoi(argv[a]);
402                                         a++;
403                                         sizy= atoi(argv[a]);
404
405                                         setprefsize(stax, stay, sizx, sizy);
406                                         break;
407                                 case 'd':
408                                         G.f |= G_DEBUG;         /* std output printf's */ 
409                                         printf ("Blender V %d.%02d\n", G.version/100, G.version%100);
410                                         MEM_set_memory_debug();
411 #ifdef NAN_BUILDINFO
412                                         printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
413
414 #endif // NAN_BUILDINFO
415                                         for (i = 0; i < argc; i++) {
416                                                 printf("argv[%d] = %s\n", i, argv[i]);
417                                         }
418                                         break;
419             
420                                 case 'w':
421                                         /* XXX, fixme zr, with borders */
422                                         /* there probably is a better way to do
423                                          * this, right now do as if blender was
424                                          * called with "-p 0 0 xres yres" -- sgefant
425                                          */ 
426                                         winlay_get_screensize(&sizx, &sizy);
427                                         setprefsize(0, 0, sizx, sizy);
428 #if 0
429 //#ifdef _WIN32 // FULLSCREEN
430                                         G.windowstate = G_WINDOWSTATE_BORDER;
431 #endif
432                                         break;
433                                 case 'W':
434                                                 /* XXX, fixme zr, borderless on win32 */
435 #if 0
436 //#ifdef _WIN32 // FULLSCREEN
437                                         G.windowstate = G_WINDOWSTATE_FULLSCREEN;
438 #endif
439                                         break;
440                                 case 'R':
441                                 /* Registering filetypes only makes sense on windows...      */
442 #ifdef WIN32
443                                         RegisterBlendExtension(argv[0]);
444 #endif
445                                         break;
446                                 case 'n':
447                                 case 'N':
448                                         if (BLI_strcasecmp(argv[a], "-noaudio") == 0|| BLI_strcasecmp(argv[a], "-nosound") == 0) {
449                                                 /**
450                                                         notify the gameengine that no audio is wanted, even if the user didn't give
451                                                         the flag -g noaudio.
452                                         */
453
454                                                 SYS_WriteCommandLineInt(syshandle,"noaudio",1);
455                                                 audio = 0;
456                                                 if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
457                                         }
458                                         break;
459                                 }
460                         }
461                 }
462
463                 BPY_start_python(argc, argv);
464                 
465                 /**
466                  * NOTE: sound_init_audio() *must be* after start_python,
467                  * at least on FreeBSD.
468                  * added note (ton): i removed it altogether
469                  */
470
471                 BIF_init();
472
473         }
474         else {
475                 BPY_start_python(argc, argv);
476                 
477                 // (ton) Commented out. I have no idea whats thisfor... will mail around!
478                 // SYS_WriteCommandLineInt(syshandle,"noaudio",1);
479         // audio = 0;
480         // sound_init_audio();
481         // if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
482         }
483
484         /**
485          * NOTE: the U.pythondir string is NULL until BIF_init() is executed,
486          * so we provide the BPY_ function below to append the user defined
487          * pythondir to Python's sys.path at this point.  Simply putting
488          * BIF_init() before BPY_start_python() crashes Blender at startup.
489          * Update: now this function also inits the bpymenus, which also depend
490          * on U.pythondir.
491          */
492         BPY_post_start_python();
493
494 #ifdef WITH_QUICKTIME
495
496         quicktime_init();
497
498 #endif /* WITH_QUICKTIME */
499
500         /* dynamically load libtiff, if available */
501         libtiff_init();
502         if (!G.have_libtiff && (G.f & G_DEBUG)) {
503                 printf("Unable to load: libtiff.\n");
504                 printf("Try setting the BF_TIFF_LIB environment variable if you want this support.\n");
505                 printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n");
506         }
507
508         /* OK we are ready for it */
509
510         for(a=1; a<argc; a++) {
511                 if (G.afbreek==1) break;
512
513                 if(argv[a][0] == '-') {
514                         switch(argv[a][1]) {
515                         case 'p':       /* prefsize */
516                                 a+= 4;
517                                 break;
518
519                         case 'g':
520                                 {
521                                 /**
522                                 gameengine parameters are automaticly put into system
523                                 -g [paramname = value]
524                                 -g [boolparamname]
525                                 example:
526                                 -g novertexarrays
527                                 -g maxvertexarraysize = 512
528                                 */
529
530                                         if(++a < argc)
531                                         {
532                                                 char* paramname = argv[a];
533                                                 /* check for single value versus assignment */
534                                                 if (a+1 < argc && (*(argv[a+1]) == '='))
535                                                 {
536                                                         a++;
537                                                         if (a+1 < argc)
538                                                         {
539                                                                 a++;
540                                                                 /* assignment */
541                                                                 SYS_WriteCommandLineString(syshandle,paramname,argv[a]);
542                                                         }  else
543                                                         {
544                                                                 printf("error: argument assignment (%s) without value.\n",paramname);
545                                                         }
546                                                         /* name arg eaten */
547
548                                                 } else
549                                                 {
550                                                         SYS_WriteCommandLineInt(syshandle,argv[a],1);
551
552                                                         /* doMipMap */
553                                                         if (!strcmp(argv[a],"nomipmap"))
554                                                         {
555                                                                 set_mipmap(0); //doMipMap = 0;
556                                                         }
557                                                         /* linearMipMap */
558                                                         if (!strcmp(argv[a],"linearmipmap"))
559                                                         {
560                                                                 set_linear_mipmap(1); //linearMipMap = 1;
561                                                         }
562
563
564                                                 } /* if (*(argv[a+1]) == '=') */
565                                         } /*    if(++a < argc)  */
566                                         break;
567                                 }
568                         case 'f':
569                                 a++;
570                                 if (G.scene) {
571                                         if (a < argc) {
572                                                 int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
573                                                 Render *re= RE_NewRender(G.scene->id.name);
574                                                 RE_BlenderAnim(re, G.scene, frame, frame);
575                                         }
576                                 } else {
577                                         printf("\nError: no blend loaded. cannot use '-f'.\n");
578                                 }
579                                 break;
580                         case 'a':
581                                 if (G.scene) {
582                                         Render *re= RE_NewRender(G.scene->id.name);
583                                         RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
584                                 } else {
585                                         printf("\nError: no blend loaded. cannot use '-a'.\n");
586                                 }
587                                 break;
588                         case 'S':
589                                 if(++a < argc) {
590                                         set_scene_name(argv[a]);
591                                 }
592                                 break;
593                         case 's':
594                                 a++;
595                                 if(G.scene) {
596                                         int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
597                                         if (a < argc) (G.scene->r.sfra) = frame;
598                                 } else {
599                                         printf("\nError: no blend loaded. cannot use '-s'.\n");
600                                 }
601                                 break;
602                         case 'e':
603                                 a++;
604                                 if(G.scene) {
605                                         int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
606                                         if (a < argc) (G.scene->r.efra) = frame;
607                                 } else {
608                                         printf("\nError: no blend loaded. cannot use '-e'.\n");
609                                 }
610                                 break;
611                         case 'P':
612                                 a++;
613                                 if (a < argc) BPY_run_python_script (argv[a]);
614                                 else printf("\nError: you must specify a Python script after '-P '.\n");
615                                 break;
616                         case 'o':
617                                 a++;
618                                 if (a < argc){
619                                         if(G.scene) {
620                                                 BLI_strncpy(G.scene->r.pic, argv[a], FILE_MAXDIR);
621                                         } else {
622                                                 printf("\nError: no blend loaded. cannot use '-o'.\n");
623                                         }
624                                 } else {
625                                         printf("\nError: you must specify a path after '-o '.\n");
626                                 }
627                                 break;
628                         case 'F':
629                                 a++;
630                                 if (a < argc){
631                                         if(!G.scene) {
632                                                 printf("\nError: no blend loaded. order the arguments so '-F ' is after the blend is loaded.\n");
633                                         } else {
634                                                 if      (!strcmp(argv[a],"TGA")) G.scene->r.imtype = R_TARGA;
635                                                 else if (!strcmp(argv[a],"IRIS")) G.scene->r.imtype = R_IRIS;
636                                                 else if (!strcmp(argv[a],"HAMX")) G.scene->r.imtype = R_HAMX;
637                                                 else if (!strcmp(argv[a],"FTYPE")) G.scene->r.imtype = R_FTYPE;
638                                                 else if (!strcmp(argv[a],"JPEG")) G.scene->r.imtype = R_JPEG90;
639                                                 else if (!strcmp(argv[a],"MOVIE")) G.scene->r.imtype = R_MOVIE;
640                                                 else if (!strcmp(argv[a],"IRIZ")) G.scene->r.imtype = R_IRIZ;
641                                                 else if (!strcmp(argv[a],"RAWTGA")) G.scene->r.imtype = R_RAWTGA;
642                                                 else if (!strcmp(argv[a],"AVIRAW")) G.scene->r.imtype = R_AVIRAW;
643                                                 else if (!strcmp(argv[a],"AVIJPEG")) G.scene->r.imtype = R_AVIJPEG;
644                                                 else if (!strcmp(argv[a],"PNG")) G.scene->r.imtype = R_PNG;
645                                                 else if (!strcmp(argv[a],"AVICODEC")) G.scene->r.imtype = R_AVICODEC;
646                                                 else if (!strcmp(argv[a],"QUICKTIME")) G.scene->r.imtype = R_QUICKTIME;
647                                                 else if (!strcmp(argv[a],"BMP")) G.scene->r.imtype = R_BMP;
648                                                 else if (!strcmp(argv[a],"HDR")) G.scene->r.imtype = R_RADHDR;
649                                                 else if (!strcmp(argv[a],"TIFF")) G.scene->r.imtype = R_IRIS;
650                                                 else if (!strcmp(argv[a],"EXR")) G.scene->r.imtype = R_OPENEXR;
651                                                 else if (!strcmp(argv[a],"MPEG")) G.scene->r.imtype = R_FFMPEG;
652                                                 else if (!strcmp(argv[a],"FRAMESERVER")) G.scene->r.imtype = R_FRAMESERVER;
653                                                 else if (!strcmp(argv[a],"CINEON")) G.scene->r.imtype = R_CINEON;
654                                                 else if (!strcmp(argv[a],"DPX")) G.scene->r.imtype = R_DPX;
655                                                 else printf("\nError: Format from '-F ' not known.\n");
656                                         }
657                                 } else {
658                                         printf("\nError: no blend loaded. cannot use '-x'.\n");
659                                 }
660                                 break;
661                                 
662                         case 't':
663                                 a++;
664                                 if(G.background) {
665                                         RE_set_max_threads(atoi(argv[a]));
666                                 }
667                                 break;
668                         case 'x': /* extension */
669                                 a++;
670                                 if (a < argc) {
671                                         if(G.scene) {
672                                                 if (argv[a][0] == '0') {
673                                                         G.scene->r.scemode &= ~R_EXTENSION;
674                                                 } else if (argv[a][0] == '1') {
675                                                         G.scene->r.scemode |= R_EXTENSION;
676                                                 } else {
677                                                         printf("\nError: Use '-x 1' or '-x 0' To set the extension option.\n");
678                                                 }
679                                         } else {
680                                                 printf("\nError: no blend loaded. order the arguments so '-o ' is after '-x '.\n");
681                                         }
682                                 } else {
683                                         printf("\nError: you must specify a path after '- '.\n");
684                                 }
685                                 break;
686                         }
687                 }
688                 else {
689                         BKE_read_file(argv[a], NULL);
690                         sound_initialize_sounds();
691                 }
692         }
693
694         if(G.background) {
695                 /* actually incorrect, but works for now (ton) */
696                 exit_usiblender();
697         }
698
699         setscreen(G.curscreen);
700
701         if(G.main->scene.first==0) {
702                 sce= add_scene("1");
703                 set_scene(sce);
704         }
705
706         screenmain();
707
708         return 0;
709 } /* end of int main(argc,argv) */
710
711 static void error_cb(char *err)
712 {
713         error("%s", err);
714 }
715
716 static void mem_error_cb(char *errorStr)
717 {
718         fprintf(stderr, errorStr);
719 }
720
721 void setCallbacks(void)
722 {
723         /* Error output from the alloc routines: */
724         MEM_set_error_callback(mem_error_cb);
725
726
727         /* BLI_blenlib: */
728
729         BLI_setErrorCallBack(error_cb); /* */
730         BLI_setInterruptCallBack(blender_test_break);
731
732 }