示例#1
0
文件: ttf2png.c 项目: xltang/quark
int main(int argc, char **argv)
{
	char *fn;
	int  begin=0;
	int  end=255;
	int  size=10;
	int  cpl=0;
	int  cell=0;
	char autohinter=0;
	char seq=0;
	char alpha=0;
	char pack=0;

	FT_Library freetype;
	FT_Face    face;

	int  err;
	int  i;

	char *out_fn="font.png";

	char *def_fn=NULL;

	Font font;

	if(argc<2)
	{
		usage();
		return 1;
	}

	while((i=getopt(argc, argv, "r:s:l:c:o:atvh?ed:p"))!=-1)
	{
		char *ptr;
		int  temp;
		switch(i)
		{
		case 'r':
			if(!strcmp(optarg, "all"))
			{
				begin=0;
				end=0x110000;
			}
			else
			{
				if(!isdigit(optarg[0]))
					temp=-1;
				else
				{
					temp=strtol(optarg, &ptr, 0);
					if(ptr[0]!=',' || !isdigit(ptr[1]))
						temp=-1;
				}
				if(temp<0)
				{
					printf("Not a valid range: %s\n", optarg);
					exit(1);
				}
				else
				{
					begin=temp;
					end=strtol(ptr+1, NULL, 0);
				}
			}
			break;
		case 's':
			size=strtol(optarg, NULL, 0);
			break;
		case 'l':
			cpl=strtol(optarg, NULL, 0);
			break;
		case 'c':
			cell=strtol(optarg, NULL, 0);
			break;
		case 'o':
			out_fn=optarg;
			break;
		case 'a':
			autohinter=1;
			break;
		case 't':
			alpha=1;
			break;
		case 'v':
			++verbose;
			break;
		case 'h':
		case '?':
			usage();
			return 0;
		case 'e':
			seq=1;
			break;
		case 'd':
			def_fn=optarg;
			break;
		case 'p':
			pack=1;
			break;
		}
	}
	if(!strcmp(out_fn, "-"))
		verbose=0;

	if(optind!=argc-1)
	{
		usage();
		return 1;
	}
	
	fn=argv[optind];

	err=FT_Init_FreeType(&freetype);
	if(err)
	{
		fprintf(stderr, "Couldn't initialize FreeType library\n");
		return 1;
	}

	err=FT_New_Face(freetype, fn, 0, &face);
	if(err)
	{
		fprintf(stderr, "Couldn't load font file\n");
		if(err==FT_Err_Unknown_File_Format)
			fprintf(stderr, "Unknown file format\n");
		return 1;
	}

	if(verbose)
	{
		const char *name=FT_Get_Postscript_Name(face);
		printf("Font name: %s\n", name);
		printf("Glyphs:    %ld\n", face->num_glyphs);
	}

	err=FT_Set_Pixel_Sizes(face, 0, size);
	if(err)
	{
		fprintf(stderr, "Couldn't set size\n");
		return 1;
	}

	font.size=size;
	init_font(&font, face, begin, end, autohinter);
	if(pack)
		render_packed(&font);
	else
		render_grid(&font, cell, cpl, seq);
	save_png(out_fn, &font.image, alpha);
	if(def_fn)
		save_defs(def_fn, &font);

	for(i=0; i<font.n_glyphs; ++i)
		free(font.glyphs[i].image.data);
	free(font.glyphs);
	free(font.image.data);

	FT_Done_Face(face);
	FT_Done_FreeType(freetype);

	return 0;
}
示例#2
0
int main(int argc, char *argv[]){

    if(!glfwInit()){
        throw std::runtime_error("glfwInit failed");
    }
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    glfwOpenWindowHint(0, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
    if(!glfwOpenWindow(800, 600, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)){
        throw std::runtime_error("glfwOpenWindow failed. does this hardware work with 3.1");
    }

    glewExperimental = GL_TRUE;
    if(glewInit() != GLEW_OK){
        throw std::runtime_error("glewInit failed");
    }

    if(!GLEW_VERSION_3_1){
        throw std::runtime_error("OpenGL 3.1 API is not available");
    }

    LoadGeometry();
    LoadTexture();
    PrepVertexUniforms();
    init_font();
    printf("All data prepped\n");

    camera.setPosition(glm::vec3(0,0,8));
    camera.setViewportAspectRatio(screenwidth/screenheight);

    light.position = camera.position();
    light.intensities = glm::vec3(1,1,1);

    glfwDisable(GLFW_MOUSE_CURSOR);
    glfwSetMousePos(0, 0);
    glfwSetMouseWheel(0);

    printf("camera prepped\n");

    //turn on depth test so things dont look stupid
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glEnable(GL_CULL_FACE);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    printf("starting main loop\n");
    while(glfwGetWindowParam(GLFW_OPENED)){

        update();
        display();

        //check for errors
        GLenum error = glGetError();
        if(error != GL_NO_ERROR){
            glPrintError();
        }

        //esc == close
        if(glfwGetKey(GLFW_KEY_ESC)){
            glfwCloseWindow();
        }
    }
    glfwTerminate();

    return 0;

}
示例#3
0
int real_main() {
    srand48(time(NULL));

    if (!al_init()) {
        puts("Could not initialise allegro");
        return 1;
    }
    if (!al_install_keyboard()) {
        puts("Could not initialise allegro keyboard subsystem");
        return 1;
    }
    keys = malloc(sizeof(ALLEGRO_KEYBOARD_STATE));
    if (!init_font()) {
        puts("Could not initialise allegro font subsystem");
        return 1;
    }

    al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);

    ALLEGRO_DISPLAY* display = al_create_display(1, 1);
    if (!display) {
        puts("Could not initialise allegro display");
        return 1;
    }

    Vector size = new_vector();
    size.x = al_get_display_width(display);
    size.y = al_get_display_height(display);

    Game* game = new_game(size);
    int i;
    for (i = 0; i < ASTEROIDN; i++)
        spawn_asteroid(game);

    ALLEGRO_TIMER* timer = al_create_timer(1.0/FPS);

    ALLEGRO_EVENT_QUEUE *timereq = al_create_event_queue();
    ALLEGRO_EVENT_QUEUE *genericeq = al_create_event_queue();
    if (!timereq || !genericeq) {
        puts("Could not create allegro event queue");
        return 1;
    }
    al_register_event_source(timereq, al_get_timer_event_source(timer));

    al_register_event_source(genericeq, al_get_keyboard_event_source());
    al_register_event_source(genericeq, al_get_display_event_source(display));

    al_start_timer(timer); // Start generating timer events
    ALLEGRO_EVENT *timerevent = malloc(sizeof(ALLEGRO_EVENT));
    ALLEGRO_EVENT *genericevent = malloc(sizeof(ALLEGRO_EVENT));

    float last_drawn, now;
    last_drawn = now = al_get_time();
    while (game->status != Quit) {
        al_get_keyboard_state(keys);

        al_wait_for_event(timereq, NULL);
        al_get_next_event(timereq, timerevent);
        // No need to fill up the queue if we are late drawing frames
        al_flush_event_queue(timereq);

        handle_key_status(game, keys);

        while(al_get_next_event(genericeq, genericevent))
            switch(genericevent->type) {
            case ALLEGRO_EVENT_KEY_DOWN:
                handle_key_event(game, genericevent->keyboard.keycode);
                break;

            case ALLEGRO_EVENT_DISPLAY_RESIZE:
                game->size.x = genericevent->display.x;
                game->size.y = genericevent->display.y;
                al_acknowledge_resize(display);
                break;

            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                game->status = Quit;
                break;
            }

        now = al_get_time();
        update_game(game, now - last_drawn);
        last_drawn = now;

        draw_game(game, game->status == Playing ? 1 : 0.2);
        switch(game->status) {
        case Playing:
            break;
        case Paused:
            draw_paused(game);
            break;
        case Won:
            draw_won(game);
            break;
        case Lost:
            draw_lost(game);
            break;
        default:
            break;
        }

        al_flip_display();
    }

    free(timerevent);
    free(genericevent);
    delete_game(game);
    return 0;
}
示例#4
0
static void ft2_source_update(void *data, obs_data_t settings)
{
	struct ft2_source *srcdata = data;
	obs_data_t font_obj = obs_data_get_obj(settings, "font");
	bool vbuf_needs_update = false;
	bool word_wrap = false;
	uint32_t color[2];
	uint32_t custom_width = 0;

	const char *font_name  = obs_data_get_string(font_obj, "face");
	const char *font_style = obs_data_get_string(font_obj, "style");
	uint16_t   font_size   = (uint16_t)obs_data_get_int(font_obj, "size");
	uint32_t   font_flags  = (uint32_t)obs_data_get_int(font_obj, "flags");

	if (!font_obj)
		return;

	srcdata->drop_shadow = obs_data_get_bool(settings, "drop_shadow");
	srcdata->outline_text = obs_data_get_bool(settings, "outline");
	word_wrap = obs_data_get_bool(settings, "word_wrap");

	color[0] = (uint32_t)obs_data_get_int(settings, "color1");
	color[1] = (uint32_t)obs_data_get_int(settings, "color2");

	custom_width = (uint32_t)obs_data_get_int(settings, "custom_width");
	if (custom_width >= 100) {
		if (custom_width != srcdata->custom_width) {
			srcdata->custom_width = custom_width;
			vbuf_needs_update = true;
		}
	}
	else {
		if (srcdata->custom_width >= 100)
			vbuf_needs_update = true;
		srcdata->custom_width = 0;
	}

	if (word_wrap != srcdata->word_wrap) {
		srcdata->word_wrap = word_wrap;
		vbuf_needs_update = true;
	}

	if (color[0] != srcdata->color[0] || color[1] != srcdata->color[1]) {
		srcdata->color[0] = color[0];
		srcdata->color[1] = color[1];
		vbuf_needs_update = true;
	}

	bool from_file = obs_data_get_bool(settings, "from_file");
	bool chat_log_mode = obs_data_get_bool(settings, "log_mode");

	srcdata->log_mode = chat_log_mode;

	if (ft2_lib == NULL) goto error;

	if (srcdata->draw_effect == NULL) {
		char *effect_file = NULL;
		char *error_string = NULL;

		effect_file =
			obs_module_file("text_default.effect");

		if (effect_file) {
			obs_enter_graphics();
			srcdata->draw_effect = gs_effect_create_from_file(
				effect_file, &error_string);
			obs_leave_graphics();

			bfree(effect_file);
			if (error_string != NULL)
				bfree(error_string);
		}
	}

	if (srcdata->font_size != font_size ||
	    srcdata->from_file != from_file)
		vbuf_needs_update = true;

	srcdata->file_load_failed = false;
	srcdata->from_file = from_file;

	if (srcdata->font_name != NULL) {
		if (strcmp(font_name,  srcdata->font_name)  == 0 &&
		    strcmp(font_style, srcdata->font_style) == 0 &&
		    font_flags == srcdata->font_flags &&
		    font_size  == srcdata->font_size)
			goto skip_font_load;

		bfree(srcdata->font_name);
		bfree(srcdata->font_style);
		srcdata->font_name = NULL;
		srcdata->font_style = NULL;
		srcdata->max_h = 0;
	}

	srcdata->font_name  = bstrdup(font_name);
	srcdata->font_style = bstrdup(font_style);
	srcdata->font_size  = font_size;
	srcdata->font_flags = font_flags;

	if (!init_font(srcdata) || srcdata->font_face == NULL) {
		blog(LOG_WARNING, "FT2-text: Failed to load font %s",
			srcdata->font_name);
		goto error;
	}
	else {
		FT_Set_Pixel_Sizes(srcdata->font_face, 0, srcdata->font_size); 
		FT_Select_Charmap(srcdata->font_face, FT_ENCODING_UNICODE);
	}

	if (srcdata->texbuf != NULL) {
		bfree(srcdata->texbuf);
		srcdata->texbuf = NULL;
	}
	srcdata->texbuf = bzalloc(texbuf_w * texbuf_h * 4);

	if (srcdata->font_face)
		cache_standard_glyphs(srcdata);
skip_font_load:;
	if (from_file) {
		const char *tmp = obs_data_get_string(settings, "text_file");
		if (!tmp || !*tmp) {
			blog(LOG_WARNING,
				"FT2-text: Failed to open %s for reading", tmp);
			goto error;
		}

		if (srcdata->text_file != NULL &&
		    strcmp(srcdata->text_file, tmp) == 0 &&
		    !vbuf_needs_update)
			goto error;

		bfree(srcdata->text_file);

		srcdata->text_file = bstrdup(tmp);
		if (chat_log_mode)
			read_from_end(srcdata, tmp);
		else
			load_text_from_file(srcdata, tmp);
		srcdata->last_checked = os_gettime_ns();
	}
	else {
		const char *tmp = obs_data_get_string(settings, "text");
		if (!tmp || !*tmp) goto error;

		if (srcdata->text != NULL) {
			bfree(srcdata->text);
			srcdata->text = NULL;
		}

		os_utf8_to_wcs_ptr(tmp, strlen(tmp), &srcdata->text);
	}

	if (srcdata->font_face) {
		cache_glyphs(srcdata, srcdata->text);
		set_up_vertex_buffer(srcdata);
	}

error:
	obs_data_release(font_obj);
}
示例#5
0
文件: main.c 项目: emukidid/swiss-gc
/* Initialise Video, PAD, DVD, Font */
void Initialise (void)
{
	VIDEO_Init ();
	PAD_Init ();  
	DVD_Init(); 
	*(volatile unsigned long*)0xcc00643c = 0x00000000; //allow 32mhz exi bus
	
	// Disable IPL modchips to allow access to IPL ROM fonts
	ipl_set_config(6); 
	usleep(1000); //wait for modchip to disable (overkill)
	
	
	__SYS_ReadROM(IPLInfo,256,0);	// Read IPL tag

	// By default, let libOGC figure out the video mode
	GXRModeObj *vmode = VIDEO_GetPreferredMode(NULL); //Last mode used
	if(is_gamecube()) {	// Gamecube, determine based on IPL
		int retPAD = 0, retCnt = 10000;
		while(retPAD <= 0 && retCnt >= 0) { retPAD = PAD_ScanPads(); usleep(100); retCnt--; }
		// L Trigger held down ignores the fact that there's a component cable plugged in.
		if(VIDEO_HaveComponentCable() && !(PAD_ButtonsDown(0) & PAD_TRIGGER_L)) {
			if(strstr(IPLInfo,"MPAL")!=NULL) {
				swissSettings.sramVideo = 2;
				vmode = &TVMpal480Prog; //Progressive 480p
			}
			else if((strstr(IPLInfo,"PAL")!=NULL)) {
				swissSettings.sramVideo = 1;
				vmode = &TVPal576ProgScale; //Progressive 576p
			}
			else {
				swissSettings.sramVideo = 0;
				vmode = &TVNtsc480Prog; //Progressive 480p
			}
		}
		else {
			//try to use the IPL region
			if(strstr(IPLInfo,"MPAL")!=NULL) {
				swissSettings.sramVideo = 2;
				vmode = &TVMpal480IntDf;        //PAL-M
			}
			else if(strstr(IPLInfo,"PAL")!=NULL) {
				swissSettings.sramVideo = 1;
				vmode = &TVPal576IntDfScale;         //PAL
			}
			else {
				swissSettings.sramVideo = 0;
				vmode = &TVNtsc480IntDf;        //NTSC
			}
		}
	}
	setVideoMode(vmode);

	init_font();
	DrawInit();
	
	drive_version(&driveVersion[0]);
	swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 1 : 0;
	
	if(!driveVersion[0]) {
		// Reset DVD if there was a IPL replacement that hasn't done that for us yet
		uiDrawObj_t *progBox = DrawPublish(DrawProgressBar(true, 0, "Initialise DVD .. (HOLD B if NO DVD Drive)"));
		dvd_reset();	// low-level, basic
		dvd_read_id();
		if(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B)) {
			dvd_set_streaming(*(char*)0x80000008);
		}
		drive_version(&driveVersion[0]);
		swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 2 : 0;
		if(!swissSettings.hasDVDDrive) {
			DrawDispose(progBox);
			progBox = DrawPublish(DrawMessageBox(D_INFO, "No DVD Drive Detected !!"));
			sleep(2);
		}
		DrawDispose(progBox);
	}
}
示例#6
0
static void 
mySDL_init(int w, int h)
{
if (!SDL_WasInit(SDL_INIT_VIDEO))
    {
    int status=SDL_Init(SDL_INIT_VIDEO);
    if (status<0)
        fnError2("sdl-init-video failed.", SDL_GetError());
    }


// init ttf
if (!TTF_WasInit())
    {
    int status=TTF_Init();
    if (status<0)
        fnError2("TTF_Init failed.", SDL_GetError());
    }
    
// FIXME the two following modern fonts do not work properly.
//gFont=TTF_OpenFont("fonts/DroidSansMono.ttf", 12);
//gFont=TTF_OpenFont("fonts/DejaVuSansMono.ttf", 12);
gFont=TTF_OpenFont("fonts/fixedsys.fon", 12);
adjust_cell_size_from_font(gFont);
gFont_zh=TTF_OpenFont("fonts/wqy-zenhei.ttc", 14);
// adjust wide font size according to cell size does not work well, for now.
/*
adjust_wide_font_from_cell_size("fonts/wqy-zenhei.ttc", 
        gDisplay_cell_w, gDisplay_cell_h);
        */

if (gFont==NULL || gFont_zh==NULL)
    fnError2("fail open font cour.ttf/msyh.ttf", SDL_GetError());
int i;
for (i=0; i<4; i++)
    {
    TTF_Font* gFont_tmp= TTF_OpenFont("fonts/fixedsys.fon", 10);
    if (gFont_tmp==NULL)
        fnError2("error load font ", SDL_GetError());
    gDisplayFontNormal[i]=gFont_tmp;
    TTF_SetFontStyle(gFont_tmp, i);
    gDisplayFontWide[i]=gFont_zh;
    }
gDisplayFontCur=gDisplayFontNormal[0];


myInfo_init(500,500);
send_setcellsize_to_adapter(gDisplay_cell_w, gDisplay_cell_h);
myDisplay_init(DISPLAY_W ,DISPLAY_H);
mySDLrunning=1;

/*
info_push_messagef("cell_pix_w=%d, h=%d", gDisplay_cell_w, 
        gDisplay_cell_h);
*/
SDL_Color color={0xff,0xff, 0xff,0xff};
init_font(&myInfoFont, gInfoRenderer, gFont, &color_black);
//init_font(&myDisplayFont, gDisplayRenderer, gFont, &color_black);

SDL_Color textColor={255, 255, 0, 0xff};
static char buf[300]="hello##";
int ii;
for (ii=0; ii<256; ii++)
    buf[ii]=ii+1;
buf[256]=0;
SDL_Surface *textSurface=TTF_RenderText_Blended(gFont, buf, textColor);
if (textSurface==NULL)
    fnWarn("textSurface==NULL");
text_hello=SDL_CreateTextureFromSurface(gInfoRenderer, textSurface);
if (text_hello==NULL)
    fnWarn("text_hello==NULL");
SDL_FreeSurface(textSurface);

}
示例#7
0
文件: main.c 项目: hwirth/may_first
/* main()
 * Program entry point. Initializes everything and runs the main loop.
 * Times are calculated and the frame rate is controlled here.
 */
int main( int argc, char* argv[] )
{
	program_state_t* PS  = &program_state;
	game_state_t*    GS  = &game_state;
	sounds_t*      	 snd = &(GS->sounds);

	PS->program_start_us = get_time();

	init_sdl( PS, GS );     // Create window, load sounds
	init_sound( PS, GS );   // Load music, sounds, set volume
	init_font( PS );        // Load font
	init_opengl( PS );      // Load textures

	play_music( snd->music );

	load_highscore( GS );

	PS->current_time_us    =
	PS->frame_start_us     = get_time();

	// Make the following look nice in debug info
	PS->game_start_us      =
	PS->pause_since_us     = PS->program_start_us - 1;

	PS->tick_fraction_s    = -1;

	PS->highest_frame_time = 0;
	PS->lowest_frame_time  = 99999999;

	PS->run_mode = RM_INTRO;

	while (PS->run_mode != RM_EXIT) {

		PS->current_time_us = get_time();

		// Calculate how much time we need to waste for target FPS
		PS->delay_until_us
			= PS->current_time_us
			+ (1000000 / TARGET_FPS)
		;


		// Keep track of game time (handling pause)
		if ( !(PS->run_mode & (RM_PAUSE | RM_MAIN_MENU)) ) {
			PS->game_time_us
				= PS->current_time_us
				- PS->game_start_us
			;

		}

		// Show intro after main menu idles for a while
		if (PS->run_mode == RM_MAIN_MENU) {
			if (PS->main_menu_since_us
				+ MAIN_MENU_INTRO_SWITCH_TIME < get_time()) {
				PS->run_mode = RM_INTRO;
			}
		}

		// Handle user input
		process_event_queue( PS, GS );

		// Let the universe live for a short moment
		if (PS->run_mode & (RM_RUNNING | RM_AFTER_LIFE)) {
			advance_simulation( PS, GS );
		}

		// Display the current world status as game scene
		draw_frame( PS, GS );

#if LIMIT_FPS
		// Waste time until the next frame needs to be drawn
		while (get_time() < PS->delay_until_us) {
	#if LIMIT_FPS_USING_SDL_DELAY
			SDL_Delay( 1 );
	#endif
		}
#endif
		// Keep track of how many FPS we actually achieved
		PS->frame_time_us   = get_time() - PS->frame_start_us;

		PS->highest_frame_time = max(
			PS->highest_frame_time,
			PS->frame_time_us
		);
		PS->lowest_frame_time = min(
			PS->lowest_frame_time,
			PS->frame_time_us
		);

		PS->frame_start_us  = get_time();
		PS->tick_fraction_s = (real_t)PS->frame_time_us / 1000000.0;

		save_frame_time( PS );   // For average FPS
		PS->average_frame_time = average_frame_time( PS );
	}

	save_highscore( PS, GS );

	glDeleteTextures( 1, &(PS->textures.background) );
	glDeleteTextures( 1, &(PS->textures.digits) );

	Mix_FreeChunk( snd->laser );
	Mix_FreeChunk( snd->hit );
	Mix_FreeChunk( snd->punch );
	Mix_FreeChunk( snd->blast );
	Mix_FreeChunk( snd->denied );
	Mix_FreeChunk( snd->alarm );
	Mix_FreeChunk( snd->blub );

	Mix_FreeChunk( snd->computer_autofire );
	Mix_FreeChunk( snd->computer_doubleshot );
	Mix_FreeChunk( snd->computer_roundshot );
	Mix_FreeChunk( snd->computer_danger );
	Mix_FreeChunk( snd->computer_weaponlost );

	Mix_FreeMusic( snd->music );

	SDL_Quit();   // Will (allegedly) also free  screen .

	return 0;
}
示例#8
0
文件: game.cpp 项目: jokoon/eio
void game :: init(){
    pause_drawing=false;
    glines = VertexArray(Lines);
    conf.init("conf.cfg");
    cfg=&conf;
    fps_coeff = 1.f/cfg->getfloat("timestep");

    //srand((unsigned)time(0));
    window.setKeyRepeatEnabled(false);
    wincenter.x=window.getSize().x/2;
    wincenter.y=window.getSize().y/2;
    winsize.x=window.getSize().x;
    winsize.y=window.getSize().y;
    window.setFramerateLimit(fps_coeff);

    if(cfg->getint("stick_left"))
    {
        Vec2i screen_resolution;
        cfg->SET(screen_resolution);
#ifdef __APPLE__
        screen_resolution=Vec2i(1280,800);
#endif
        Vec2i windowpos(screen_resolution.x - winsize.x-10,25);
        cout << strfy(screen_resolution) << endl;
        cout << strfy(windowpos) << endl;
        window.setPosition(windowpos);
    }
    else
        window.setPosition(Vec2i(5,25));


    {
        Vec2 cons_view_size;
        cfg->SET(cons_view_size);
        console_view.setSize(Vec2(cons_view_size.x*wsize.x,cons_view_size.y*wsize.y));
        fixedview = window.getDefaultView();
        mainview=fixedview;
    }
    wsize = winsize;
    wcenter = wincenter;
    float window_coeff = conf.getfloat("window_coeff");
    if(window_coeff!=1.0)
    {
        Vec2u resized(winsize.x*window_coeff,winsize.y*window_coeff);
        window.setSize(resized);
    }
    bg = cfg->getcolor("background");
    string path="yes/";
#ifdef __APPLE__
    path = resourcePath()+path;
#endif
    if(!cursor_tx.loadFromFile(path+"cursor4.png")) cout << "did not load cursor" << endl;
    cursor.setTexture(cursor_tx);
    cursor.setOrigin(3,3);
    window.setMouseCursorVisible(false);

    confpoint(c1,3,Color::Green);
    confpoint(c2,3,Color::Red);

    // fonts and f*****g globals
    init_font();
    font1 = &ft;
    font2 = &ft2;
    charsize=chsz;
    charsize2=chsz2;

    // console
    console = new sfconsole;
    console->numlines=conf.getint("numlines");
    console->init();
    cons=console;
    draw_console = true;

    labs=new labels;
    labs->pos=Vec2(15,winsize.y-30);
    lbs=&(labs->strings);


    win=&window;

    add_symbol_to_lambdas();

    if(cfg->getint("use_menu"))
    {
        menu_loop();
    }
    else
    {
        init_gameobj();
        loop();
    }
}
示例#9
0
void options(char ip[])
{
    int quit = 0;
    int menu_choice = 0;
    //fps
    struct timer_t2 fps;

    init_options();
    init_font();

    //wait for user to continue or exit
    while( quit != 1 )
    {
        //Start the frame timer
        timer_start(&fps);
        //While there are events to handle
        while( SDL_PollEvent( &event ) )
        {

            if( event.type == SDL_QUIT )
            {
                //exit
                clean_up();
                exit(0);
            }
            if( event.type == SDL_KEYDOWN )
            {
                switch(event.key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                        quit = 1; break;
                }
            }

            mouse_over_options(event.button.x, event.button.y);

            if( event.type == SDL_MOUSEBUTTONDOWN)
            {
                switch(event.button.button)
                {
                    case SDL_BUTTON_LEFT:
                        press_options(event.button.x, event.button.y);
                        break;
                }
            }


            if( event.type == SDL_MOUSEBUTTONUP)
            {
                switch(event.button.button)
                {
                    case SDL_BUTTON_LEFT:
                        menu_choice = press_options(event.button.x, event.button.y);
                        break;
                }
            }

            switch(menu_choice)
            {
                case 1:
                    handle_input(event,ip);
                    printf("String in graphics.c (%s)\n",ip);
                    break;
                case 2:
                    quit = 1;
                    printf("Försöker bryta ut ur options\n");
                    break;
                default:
                    break;
            }
        }
        apply_letter(ip);
        apply_texture();

        startDraw();
        //draw menu
        drawOptions(SCREEN_WIDTH, SCREEN_HEIGHT);
        drawBack();
        endDraw();

        if( timer_get_ticks(&fps) < 1000 / FRAMES_PER_SECOND )
        {
            //delay the as much time as we need to get desired frames per second
            SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - timer_get_ticks(&fps) );
        }
    }
}