Exemplo n.º 1
0
bool Engine::init() {
	if (!app) {
		Log::print("App not informed");
		return false;
	}

	if (!initSDL()) {
		return false;
	}

	setupOpenGL();

	if (!initSDLWindow()) {
		return false;
	}

	if (!initSDLGLContext()) {
		return false;
	}

	if (!initGLEW()) {
		return false;
	}

	printVersions();

	if (!app->init()) {
		return false;
	}

	reshape();

	return true;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int allowEdit, allowHintSub, fixStems, debug, badParam;
	char *fontInfoFileName=NULL; /* font info file name, or suffix of environment variable holding the fontfino string. */
	char *fontinfo = NULL; /* the string of fontinfo data */
	int firstFileNameIndex = -1; /* arg index for first bez file name, or  suffix of environment variable holding the bez string. */
	register char *current_arg;
	short total_files = 0; 
	int result, argi;
  
	badParam = fixStems = debug = doAligns = doStems = allstems = FALSE;
	allowEdit = allowHintSub = TRUE;
	fileSuffix = (char*)dfltExt;

	/* read in options */
	argi = 0;
	while (++argi < argc)
		{
	   current_arg = argv[argi];
	   
		if (current_arg[0] == '\0')
			continue;
		else if (current_arg[0] != '-')
			{
			if (firstFileNameIndex == -1)
				firstFileNameIndex = argi;
			total_files++;
			continue;
			}
		else if (firstFileNameIndex != -1)
			{
			fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-\" option found after first file name.\n");
			exit(1);
 			}

		switch (current_arg[1])
			{
			case '\0':
				badParam = TRUE;
				break;
			case 'u':
				printUsage();
				#ifdef EXECUTABLE
				  exit(0);
				#else
					longjmp(aclibmark, 1);
				#endif
				break;
			case 'h':
				printHelp();
				#ifdef EXECUTABLE
				  exit(0);
				#else
					longjmp(aclibmark, 1);
				#endif
				break;
			 case 'e':
				allowEdit = FALSE;
				break;
			 case 'f':
				fontInfoFileName = argv[++argi];
				if  ((fontInfoFileName[0] == '\0') || (fontInfoFileName[0] == '-'))
					{
					fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-f\" option must be followed by a file name.\n");
					exit(1);
					}
				break;
			 case 's':
				fileSuffix = argv[++argi];
				if  ((fileSuffix[0] == '\0') || (fileSuffix[0] == '-'))
					{
					fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-s\" option must be followed by a string, and the string must not begin with '-'.\n");
					exit(1);
					}
				break;
			case 'n':
				allowHintSub = FALSE;
				break;
			case 'q':
				verbose = FALSE;
				break;
			 case 'D':
				debug = TRUE;
				break;
			case 'F':
				fixStems = TRUE;
			  break;
			case 'a':
				allstems = 1;
				break;
				
			case 'r':
				allowEdit = allowHintSub = FALSE;
				fileSuffix = (char *)reportExt;
				switch (current_arg[2])
					{
					case 'a':
						reportRetryCB = reportRetry;
						addCharExtremesCB = charZoneCB;
						addStemExtremesCB = stemZoneCB;
						doAligns = 1;

						addHStemCB = NULL;
						addVStemCB = NULL;
						doStems = 0;
						break;
					case 's':
						reportRetryCB = reportRetry;
						addHStemCB = hstemCB;
						addVStemCB = vstemCB;
						doStems = 1;

						addCharExtremesCB = NULL;
						addStemExtremesCB = NULL;
						doAligns = 0;
						break;
					default:
						fprintf(OUTPUTBUFF, "Error. %s is an invalid parameter.\n", current_arg);
						badParam = TRUE;
						break;
					}
					break;
			case 'v':
				printVersions();
				exit(0);
				break;
			  break;
#if ALLOWCSOUTPUT
			case 'C':
				charstringoutput = TRUE;
				break;
#endif
			default:
				fprintf(OUTPUTBUFF, "Error. %s is an invalid parameter.\n", current_arg);
				badParam = TRUE;
				break;
			}
		}

	if (firstFileNameIndex == -1)
		{
		fprintf(OUTPUTBUFF, "Error. Illegal command line. Must provide bez file name.\n");
		badParam = TRUE;
		}
	if (fontInfoFileName == NULL)
		{
		fprintf(OUTPUTBUFF, "Error. Illegal command line. Must provide font info file name.\n");
		badParam = TRUE;
		}
		
	if (badParam) 
#ifdef EXECUTABLE
		exit(NONFATALERROR);
#else
		longjmp(aclibmark, -1);
#endif

#if ALLOWCSOUTPUT
	if (charstringoutput)
		read_char_widths();
#endif

	AC_SetReportCB(reportCB, verbose);
	fontinfo = getFileData(fontInfoFileName);
	argi = firstFileNameIndex-1;
	while (++argi < argc)
		{
		char *bezdata;
		char *output;
		size_t outputsize = 0;
		bezName = argv[argi];
		bezdata = getFileData(bezName);
		outputsize = 4*strlen(bezdata);
		output = malloc(outputsize); 

		if (doAligns || doStems)
			openReportFile(bezName, fileSuffix);
			
		result = AutoColorString(bezdata, fontinfo, output, (int*)&outputsize, allowEdit, allowHintSub, debug);
		if (result == AC_DestBuffOfloError)
			{
			free(output);
			if (reportFile != NULL)
				closeReportFile();
			if (doAligns || doStems)
				openReportFile(bezName, fileSuffix);
			output = malloc(outputsize); 
			/* printf("NOTE: trying again. Input size %d output size %d.\n", strlen(bezdata), outputsize); */
			AC_SetReportCB(reportCB, FALSE);
			result = AutoColorString(bezdata, fontinfo, output, (int*)&outputsize, allowEdit, allowHintSub, debug);
			AC_SetReportCB(reportCB, verbose);
			}
		if (reportFile != NULL)
			closeReportFile();
		else
			{
			if ((outputsize != 0) && (result == AC_Success))
				writeFileData(bezName, output, fileSuffix);
			}
		free(output);
		main_cleanup( (result == AC_Success) ? OK : FATALERROR);
		}
		

  return 0;
  }
Exemplo n.º 3
0
static void printUsage(void)
	{
	fprintf(OUTPUTBUFF, "Usage: autohintexe [-u] [-h]\n");
	fprintf(OUTPUTBUFF, "       autohintexe  -f <font info name> [-e] [-n] [-q] [-s <suffix>] [-ra] [-rs] -a] [<file1> <file2> ... <filen>]\n");
	printVersions();
	}
Exemplo n.º 4
0
void begin()
{
    

    // old-BATB didn't like to be initialized more than once :(
    // hence, ignore re-init for specified parts, and continue with previous state
    static bool empty = true;
    
    // clear exit, making possible to start over again
    //do_exit = false;

        // copied from old::main:
        //MainWindow::winPosX = 100;
        //MainWindow::winPosY = 100;
        //MainWindow::winWidth = 640;
        //MainWindow::winHeight = 480;

        // init glut
        //glutInitWindowPosition(MainWindow::winPosX, MainWindow::winPosY);
        //glutInitWindowSize    (MainWindow::winWidth, MainWindow::winHeight);
        //glutInit              (&argc, argv);
        //glutInitDisplayMode   (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
        //MainWindow::main_window = glutCreateWindow("Beat About the Bush");
        MainWindow::enableDisplayFunc();

        // implemented as GLFW:

        GLFWwindow* win = glfwGetCurrentContext();
        glfwSetKeyCallback( win, MainWindow::glfwKey  );                  //glutKeyboardFunc      (MainWindow::keyDownFn); 
                                                                                          //glutSpecialFunc       (MainWindow::specialDownFn);
                                                                                          ////glutKeyboardUpFunc    (MainWindow::keyUpFn);
                                                                                          ////glutSpecialUpFunc     (MainWindow::specialUpFn);
        glfwSetCursorPosCallback( win, MainWindow::glfwCursorPos );       //glutMouseFunc         (MainWindow::mousefn); 
        glfwSetMouseButtonCallback( win, MainWindow::glfwMouseButton);    //glutMotionFunc        (MainWindow::motionfn);
                                                                                          
        glfwSetWindowSizeCallback( win, MainWindow::glfwWindowSize );     //glutReshapeFunc       (MainWindow::reshapefn);
        glfwSetWindowFocusCallback( win, MainWindow::glfwWindowFocus );   //glutVisibilityFunc    (MainWindow::visibility);
        
        
        
        
    if ( empty )
    {

        // init plib, with no GLUT-binding!
        puInitOLD();

        puSetDefaultStyle        ( PUSTYLE_SMALL_SHADED );
        puSetDefaultColourScheme ( 0.3f, 0.4f, 0.6f, 1.0f);

        // Initialize the "OpenGL Extension Wrangler" library
        //glewInit();
    }

        mainWindow.initLights();

    if ( empty )
    {
        mainWindow.init();
        printVersions();

        // Make sure that OpenGL 2.0 is supported by the driver
        int gl_major, gl_minor;
        getGlVersion(&gl_major, &gl_minor);
        printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);

        if (gl_major < 2)
        {
            printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
            printf("Support for OpenGL 2.0 is required for this demo...exiting\n");
            //exit(1);
            old::exit(1);
            return;
        }

        // init shaders
        GLchar *dayVSSource, *dayFSSource;
        readShaderSource( old::file("shader/day").c_str(), &dayVSSource, &dayFSSource);
        dayShader = installShaders(dayVSSource, dayFSSource);
        float forestGreen[] = {34.0/255, 139.0/255, 34.0/255};
        //float auburn[] = {113.0/255, 47.0/255, 38.0/255};
        float grey[] = {0.5, 0.5, 0.5};
        //float sepia[] = {112.0/255, 66.0/255, 20.0/255};

        setUniform3f(dayShader, "GrassColor", forestGreen[0], forestGreen[1], forestGreen[2]);
        setUniform3f(dayShader, "RockColor", grey[0], grey[1], grey[2]);
        //setUniform3f(dayShader, "DirtColor", sepia[0], sepia[1], sepia[2]);
        //setUniform4f(dayShader, "LightPos", 0.0, 0.0, 100.0, 1.0);
        setUniform1f(dayShader, "Scale", 1.0);
        setUniform1f(dayShader, "TerrainHigh", 0.1);
        setUniform1f(dayShader, "TerrainLow", 0.1);
        setUniform1i(dayShader, "Trees", 0); // sampler
        setUniform1i(dayShader, "AltGrad", 1); // sampler
        setUniform1i(dayShader, "Noise", 2); // sampler

        GLchar *nightVSSource, *nightFSSource;
        readShaderSource( old::file("shader/night3").c_str(), &nightVSSource, &nightFSSource);
        nightShader = installShaders(nightVSSource, nightFSSource);
        setUniform3f(nightShader, "BrickColor", 1.0, 0.3, 0.2);
        setUniform3f(nightShader, "MortarColor", 0.85, 0.86, 0.84);
        setUniform2f(nightShader, "BrickSize", 0.30, 0.15);
        setUniform2f(nightShader, "BrickPct", 0.90, 0.85);
        setUniform1i(nightShader, "numEnabledLights", 2);

        setUniform3f(nightShader, "GrassColor", forestGreen[0], forestGreen[1], forestGreen[2]);
        setUniform3f(nightShader, "RockColor", grey[0], grey[1], grey[2]);
        setUniform1f(nightShader, "Scale", 1.0);
        setUniform1f(nightShader, "TerrainHigh", 0.1);
        setUniform1f(nightShader, "TerrainLow", 0.1);
        setUniform1i(nightShader, "Trees", 0); // sampler
        setUniform1i(nightShader, "AltGrad", 1); // sampler
        setUniform1i(nightShader, "Noise", 2); // sampler

        GLchar *nightTreeVS, *nightTreeFS;
        readShaderSource( old::file("shader/nightTree").c_str(), &nightTreeVS, &nightTreeFS);
        nightTrees = installShaders(nightTreeVS, nightTreeFS);
        setUniform1i(nightTrees, "Trees", 0); // sampler

        // BUGFIX:
        free( dayVSSource );
        free( dayFSSource );
        free( nightVSSource );
        free( nightFSSource );
        free( nightTreeVS );
        free( nightTreeFS );
    }

        // enter main loop
        //if (dayShader && nightShader)
        //    glutMainLoop();

        //return 0;

    empty = false;

}