当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_Init函数代码示例

本文整理汇总了C++中SDL_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_Init函数的具体用法?C++ SDL_Init怎么用?C++ SDL_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assert

void sdl_osd_interface::init(running_machine &machine)
{
	// call our parent
	osd_interface::init(machine);

	sdl_options &options = downcast<sdl_options &>(machine.options());
	const char *stemp;

	// determine if we are benchmarking, and adjust options appropriately
	int bench = options.bench();
	astring error_string;
	if (bench > 0)
	{
		options.set_value(OPTION_THROTTLE, false, OPTION_PRIORITY_MAXIMUM, error_string);
		options.set_value(OPTION_SOUND, false, OPTION_PRIORITY_MAXIMUM, error_string);
		options.set_value(SDLOPTION_VIDEO, "none", OPTION_PRIORITY_MAXIMUM, error_string);
		options.set_value(OPTION_SECONDS_TO_RUN, bench, OPTION_PRIORITY_MAXIMUM, error_string);
		assert(!error_string);
	}

	// Some driver options - must be before audio init!
	stemp = options.audio_driver();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
	{
		mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp);
		osd_setenv(SDLENV_AUDIODRIVER, stemp, 1);
	}

	stemp = options.video_driver();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
	{
		mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp);
		osd_setenv(SDLENV_VIDEODRIVER, stemp, 1);
	}

#if (SDLMAME_SDL2)
		stemp = options.render_driver();
		if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
		{
			mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp);
			//osd_setenv(SDLENV_RENDERDRIVER, stemp, 1);
			SDL_SetHint(SDL_HINT_RENDER_DRIVER, stemp);
		}
#endif

	/* Set the SDL environment variable for drivers wanting to load the
	 * lib at startup.
	 */
#if USE_OPENGL
	/* FIXME: move lib loading code from drawogl.c here */

	stemp = options.gl_lib();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
	{
		osd_setenv("SDL_VIDEO_GL_DRIVER", stemp, 1);
		mame_printf_verbose("Setting SDL_VIDEO_GL_DRIVER = '%s' ...\n", stemp);
	}
#endif

	/* get number of processors */
	stemp = options.numprocessors();

	osd_num_processors = 0;

	if (strcmp(stemp, "auto") != 0)
	{
		osd_num_processors = atoi(stemp);
		if (osd_num_processors < 1)
		{
			mame_printf_warning("Warning: numprocessors < 1 doesn't make much sense. Assuming auto ...\n");
			osd_num_processors = 0;
		}
	}

	/* Initialize SDL */

	if (!SDLMAME_INIT_IN_WORKER_THREAD)
	{
#if (SDLMAME_SDL2)
		if (SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
#else
		if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
#endif
			mame_printf_error("Could not initialize SDL %s\n", SDL_GetError());
			exit(-1);
		}
		osd_sdl_info();
	}
	// must be before sdlvideo_init!
	machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(osd_exit), &machine));

	defines_verbose();

	if (!SDLMAME_HAS_DEBUGGER)
		if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)
		{
			mame_printf_error("sdlmame: -debug not supported on X11-less builds\n\n");
			osd_exit(machine);
			exit(-1);
		}
//.........这里部分代码省略.........
开发者ID:felipesanches,项目名称:ume,代码行数:101,代码来源:sdlmain.c

示例2: main

int main( int argc, char *argv[] )
{
	AVFormatContext *pFormatCtx;
	int				i, audioStream;
	AVCodecContext	*pCodecCtx;
	AVCodec			*pCodec;
	AVPacket		*packet;
	uint8_t			*out_buffer;
	AVFrame			*pFrame;
	SDL_AudioSpec	wanted_spec;
	int ret;
	uint32_t len = 0;
	int got_picture;
	int index = 0;
	int64_t in_channel_layout;
	struct SwrContext* au_conert_ctx;

	FILE* pFile = NULL;
	char url[] = "F:/video/6s_kapian.flv";

	av_register_all();
	pFormatCtx = avformat_alloc_context();

	//Open
	if( avformat_open_input(&pFormatCtx, url, NULL, NULL) != 0 )
	{
		printf("Couldn't open input stream.\n");
		return -1;
	}

	//Find Stream information
	if( avformat_find_stream_info(pFormatCtx, NULL) < 0 )
	{
		printf("Couldn't find stream information.\n");
		return -1;
	}
	//Dump valid information into standard error
	av_dump_format(pFormatCtx, 0, url, false);

	//Find the first audio stream
	audioStream = -1;
	for( i = 0; i < pFormatCtx->nb_streams; ++i	)
		if( pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO )
		{
			audioStream = i;
			break;
		}

	if( audioStream == -1 )
	{
		printf("Didn't find a audio stream.\n");
		return -1;
	}

	//Get a pointer to the codec contex for the audio stream
	pCodecCtx = pFormatCtx->streams[audioStream]->codec;

	//Find the decoder for the audio stream
	pCodec = avcodec_find_decoder( pCodecCtx->codec_id );

	if( pCodec == NULL )
	{
		printf("Codec not found.\n");
		return -1;
	}

	//Open codec
	if( avcodec_open2(pCodecCtx, pCodec, NULL) < 0 )
	{
		printf("Could not open codec.\n");
		return -1;
	}

#if OUTPUT_PCM
	pFile=fopen("output.pcm", "wb");
#endif

	packet = (AVPacket *)av_malloc( sizeof(packet) );
	av_init_packet(packet);

	//Out Audio Param
	uint64_t out_channel_layout = AV_CH_LAYOUT_STEREO;
	//nb_samples:
	int out_nb_samples = pCodecCtx->frame_size;
	AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_S16;
	int out_sample_rate = 44100;
	int out_channels = av_get_channel_layout_nb_channels(out_channel_layout);

	//Out buffer size
	int out_buffer_size = av_samples_get_buffer_size( NULL, out_channels, out_nb_samples, out_sample_fmt, 1 );

	out_buffer = (uint8_t *)av_malloc( MAX_AUDIO_FRAME_SIZE );
	pFrame = av_frame_alloc();

	//SDL------------------
#if USE_SDL
	//Init
	if(SDL_Init( SDL_INIT_AUDIO | SDL_INIT_TIMER)) {  
		printf( "Could not initialize SDL - %s\n", SDL_GetError()); 
		return -1;
//.........这里部分代码省略.........
开发者ID:jiemojiemo,项目名称:ffmpeg-,代码行数:101,代码来源:audioPlayerMain.cpp

示例3: main

int main(int argc, char *argv[])
{
	const SDL_VideoInfo *info;
	int i;
	SDL_Rect **modes;
	char driver[128];

	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr,
			"Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}
	if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
		printf("Video driver: %s\n", driver);
	}
	info = SDL_GetVideoInfo();
	printf(
"Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
	if ( info->vfmt->palette == NULL ) {
		printf("	Red Mask = 0x%.8x\n", info->vfmt->Rmask);
		printf("	Green Mask = 0x%.8x\n", info->vfmt->Gmask);
		printf("	Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
	}
	/* Print available fullscreen video modes */
	modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
	if ( modes == (SDL_Rect **)0 ) {
		printf("No available fullscreen video modes\n");
	} else
	if ( modes == (SDL_Rect **)-1 ) {
		printf("No special fullscreen video modes\n");
	} else {
		printf("Fullscreen video modes:\n");
		for ( i=0; modes[i]; ++i ) {
			printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
		}
	}
	if ( info->wm_available ) {
		printf("A window manager is available\n");
	}
	if ( info->hw_available ) {
		printf("Hardware surfaces are available (%dK video memory)\n",
			info->video_mem);
	}
	if ( info->blit_hw ) {
		printf(
"Copy blits between hardware surfaces are accelerated\n");
	}
	if ( info->blit_hw_CC ) {
		printf(
"Colorkey blits between hardware surfaces are accelerated\n");
	}
	if ( info->blit_hw_A ) {
		printf(
"Alpha blits between hardware surfaces are accelerated\n");
	}
	if ( info->blit_sw ) {
		printf(
"Copy blits from software surfaces to hardware surfaces are accelerated\n");
	}
	if ( info->blit_sw_CC ) {
		printf(
"Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
	}
	if ( info->blit_sw_A ) {
		printf(
"Alpha blits from software surfaces to hardware surfaces are accelerated\n");
	}
	if ( info->blit_fill ) {
		printf(
"Color fills on hardware surfaces are accelerated\n");
	}

	if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {
		RunVideoTests();
	}

	SDL_Quit();
	return(0);
}
开发者ID:Sgt-Nukem,项目名称:chocolate_duke3D,代码行数:79,代码来源:testvidinfo.c

示例4: main

int main(int argc, char** argv)
{
	if(argc != 2)
		usage(argv[0]);

	FILE* infile = fopen(argv[1], "r");
	if(infile == NULL)
	{
		perror("Error opening input file");
		return EXIT_FAILURE;
	}
	System* sys = load_system(infile);
	if(sys == NULL)
	{
		printf("Loading input file failed\n");
		return EXIT_FAILURE;
	}
	init_simulation(sys);
	state.sys = sys;
	state.views = malloc(sys->nplanets * sizeof(PlanetView));
	for(int i = 0; i < sys->nplanets; i++)
		state.views[i].radius = pow(sys->planets[i].mass / DENSITY_FACTOR, 1.0f/3.0f);
	state.scale = 1.0f;
	Vector* fst_pos = &sys->planets[0].position;
	vector_copy(state.pos, *fst_pos);
	state.pos[1] += 1.1f*get_planet_radius(0);
	state.pos[0] -= get_planet_radius(0);
	state.rot_x = 90.0f;
	state.locked_planet = -1;
	state.hours_per_sec = DEFAULT_SIMULATION_SPEED;
	state.time_step = sys->time_step;
	state.paused = true;
	state.trails_enabled = true;

	if(SDL_Init(SDL_INIT_VIDEO) < 0)
		die("SDL initialization failed");
	atexit(SDL_Quit);
	const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
	if(!videoInfo)
		die("Could not get video information");
	int videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE | SDL_HWSURFACE | SDL_HWACCEL;

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
	surface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
	if(!surface)
	{
		printf("Surface creation failed, trying to disable anti-aliasing...\n");
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
		surface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
	}
	if(!surface)
		die("Changing video mode failed");

	init_gl();
	init_viewport();
	SDL_ShowCursor(0);
	SDL_WM_GrabInput(SDL_GRAB_ON);

	SDL_Event event;
	while(SDL_PollEvent(&event))
		;  /* ignore spurious mouse events at startup */

	bool window_is_active = true;
	int step = 0;
	while (true)
	{
		Uint32 next_update = SDL_GetTicks() + FRAME_INTERVAL;
		while (SDL_PollEvent(&event))
		{
			switch(event.type)
			{
				case SDL_ACTIVEEVENT:
					window_is_active = event.active.gain;
					break;			    
				case SDL_VIDEORESIZE:
					surface = SDL_SetVideoMode(event.resize.w,
							event.resize.h,
							SCREEN_BPP, videoFlags);
					if(!surface)
						die("Lost video surface during resize");
					init_viewport();
					break;
				case SDL_KEYDOWN:
					handle_keypress(&event.key.keysym);
					break;
				case SDL_MOUSEMOTION:
					handle_mouse(&event.motion);
					break;
				case SDL_QUIT:
					goto out;
				default:
					break;
			}
		}
		update();
		if(window_is_active)
		{
//.........这里部分代码省略.........
开发者ID:dezgeg,项目名称:PlanetSim,代码行数:101,代码来源:guimain.c

示例5: main

int main(int, char**) {
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		printf("SDL_Init Error: %s\n", SDL_GetError());
		return 1;
	}

	SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 800, 400, SDL_WINDOW_SHOWN);
	if (win == nullptr) {
		printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
		SDL_Quit();
		return 1;
	}

	SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	assert(ren);

	SDL_Texture* texture = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, WIDTH, HEIGHT);
	assert(texture);

	OledSim oled(WIDTH, HEIGHT);
	Renderer display;
	display.Attach(WIDTH, HEIGHT, oled.Buffer());

	SDL_SetRenderDrawColor(ren, 128, 128, 128, 255);

	UIRenderData data;
	data.volume = 2;
	data.power = 3;
	data.mVolts = 3219;
	data.fontName = "Bespin";

	DotStarUI::Test();

	SDL_Event e;
	int scale = 4;
	int mode = 0;
	int count = 0;
	uint32_t lastUpdate = SDL_GetTicks();

	const char* FONT_NAMES[8] = {
		"Bespin", "Vader", "Vader", "ObiAni", "Bespin", "JainaSw", "Maul", "MAUL"
	};
	uint8_t COLORS[8] = { 0, 255, 100, 200, 255, 0, 20, 120 };
	data.color.set(COLORS[0], COLORS[1], COLORS[2]);

	int palette = 0;

	while (true) {
		SDL_PollEvent(&e);
		if (e.type == SDL_QUIT) {
			break;
		}
		else if (e.type == SDL_KEYDOWN) {
			if (e.key.keysym.sym >= SDLK_1 && e.key.keysym.sym <= SDLK_8) {
				scale = e.key.keysym.sym - SDLK_0;
			}
			else if (e.key.keysym.sym == SDLK_SPACE) {
				mode = (mode + 1) % Sketcher::NUM_MODES;
			}
			else if (e.key.keysym.sym == SDLK_p) {
				data.power = (data.power + 1) % 5;
				data.mVolts = 3000 + data.power * 111;
			}
			else if (e.key.keysym.sym == SDLK_v) {
				data.volume = (data.volume + 1) % 5;
			}
			else if (e.key.keysym.sym == SDLK_c) {
				palette = (palette + 1) % 8;
				data.color.set(COLORS[(palette * 3 + 0) % 8],
					COLORS[(palette * 2 + 1) % 8],
					COLORS[(palette * 5 + 2) % 8]);
				data.fontName = FONT_NAMES[palette];
				data.palette = palette;
			}
		}

		uint32_t t = SDL_GetTicks();
		if (t - lastUpdate > 100) {
			lastUpdate = t;
			uint8_t value = int(127.8 * (sin(count * 0.2) + 1.0));
			++count;
			sketcher.Push(value);
			sketcher.Draw(&display, 100, mode, &data);
		}

		oled.Commit();

		const SDL_Rect src = { 0, 0, WIDTH, HEIGHT };
		SDL_Rect winRect;
		SDL_GetWindowSize(win, &winRect.w, &winRect.h);
		const int w = WIDTH * scale;
		const int h = HEIGHT * scale;
		SDL_Rect dst = { (winRect.w - w) / 2, (winRect.h - h) / 2, w, h };

		SDL_UpdateTexture(texture, NULL, oled.Pixels(), WIDTH * 4);
		SDL_RenderClear(ren);
		SDL_RenderCopy(ren, texture, &src, &dst);
		SDL_RenderPresent(ren);
	}
	SDL_Quit();
//.........这里部分代码省略.........
开发者ID:leethomason,项目名称:OpenSaber,代码行数:101,代码来源:main.cpp

示例6: displayThread

void displayThread(void)
{
#ifdef LOCAL_DISPLAY
	SDL_Window *win = NULL;
	SDL_Renderer *renderer = NULL;
	SDL_Texture *texture = NULL;
	SDL_Event e;
	int kill = FALSE;
	char resolution[20] = {0};
#else
	FILE *fp = NULL;
#endif
	char *lineseeker = NULL;
	int linecnt = 0;
	int prevline = 0;
	int prevframe = 0;
	int flag = 0;
	VIDEO_DATA *popped = NULL;
	int frame_cnt = 0;

	popped = (VIDEO_DATA *)calloc(1, sizeof(VIDEO_DATA));
	popped->packetbuff = (char *)calloc(1, packetsize - VALID_DATA);
#ifdef LOCAL_DISPLAY
	SDL_Init(SDL_INIT_VIDEO);
	snprintf(resolution, 20, "Receiver : %dx%d", g_capture_width,
		 g_capture_height);
	win = SDL_CreateWindow(resolution,
			SDL_WINDOWPOS_CENTERED,
			SDL_WINDOWPOS_CENTERED,
			g_capture_width,
			g_capture_height,
			SDL_WINDOW_RESIZABLE);

	renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
	texture = SDL_CreateTexture(renderer,
			SDL_PIXELFORMAT_YUY2,
			SDL_TEXTUREACCESS_STREAMING,
			g_capture_width,
			g_capture_height);
#else
	fp = fopen(g_filename, "wb");
#endif
	while(!KillDisplayThread) {
		if((sizeofqueue() > 0) && (g_displaybuff)) {
			poppacket(popped);
		} else {
			continue;
		}

		if(flag == 0) {
			g_skipframe = popped->frame_num;
			prevframe = popped->frame_num;
			pr_dbg("Frame %d is going to skip\n",g_skipframe);
			flag = 1;
		}
#if 0
		/* check SDL event if any */
		if (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT) {
				break;
			} else if(e.key.type == SDL_KEYUP) {
				switch(e.key.keysym.sym) {
					case SDLK_ESCAPE:
						kill = TRUE;
						break;
					default:
						break;
				}
				if(kill) break;
			}
		}
#endif
		if(g_skipframe == popped->frame_num) {
			continue;
		}
		if(popped->line_num == FIRST_LINE) {
			lineseeker = g_displaybuff;
			memcpy(lineseeker, popped->packetbuff,
			       packetsize - VALID_DATA);
			lineseeker += (packetsize - VALID_DATA);
			linecnt ++;
			prevline = FIRST_LINE;
		} else if(popped->line_num == g_last_line) {
			memcpy(lineseeker, popped->packetbuff,
			       packetsize - VALID_DATA);
			linecnt++;
			if(linecnt == g_last_line) {
#ifdef LOCAL_DISPLAY
				/* display frame*/
				SDL_UpdateTexture(texture, 0,
						g_displaybuff,
						g_capture_width*BPP);
				SDL_RenderClear(renderer);
				SDL_RenderCopy(renderer, texture, NULL, NULL);
				SDL_RenderPresent(renderer);
#else
				/* save frame */
				fwrite(g_displaybuff, buffsize, 1, fp);
				if(frame_cnt++ > no_of_frames_to_save) {
					fclose(fp);
//.........这里部分代码省略.........
开发者ID:zhenyouluo,项目名称:simple_video_server,代码行数:101,代码来源:display.c

示例7: createSurface

bool createSurface() //unsigned int display_width, unsigned int display_height)
{
    if(!display_width || !display_height)
    {
        bool success = graphics_get_display_size(0, &display_width, &display_height); //0 = LCD

        if(success < 0)
        {
            std::cerr << "Error getting display size!\n";
            return false;
        }
    }
    std::cout << display_width << "x" << display_height << "...";

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0)
    {
        std::cerr << "Error initializing SDL!\n";
        std::cerr << SDL_GetError() << "\n";
        std::cerr << "Are you in the 'video' and 'input' groups? Is X closed? Is your firmware up to date? Are you using at least the 192/64 memory split?\n";
        return false;
    }

    sdlScreen = SDL_SetVideoMode(1, 1, 0, SDL_SWSURFACE);
    if(sdlScreen == NULL)
    {
        std::cerr << "Error creating SDL window for input!\n";
        return false;
    }

    //have to reload config to re-open SDL joysticks
    InputManager::loadConfig();



    std::cout << "Creating surface...";

    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;



    display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if(display == EGL_NO_DISPLAY)
    {
        std::cerr << "Error getting display!\n";
        return false;
    }

    bool result = eglInitialize(display, NULL, NULL);
    if(result == EGL_FALSE)
    {
        std::cerr << "Error initializing display!\n";
        return false;
    }

    result = eglBindAPI(EGL_OPENGL_ES_API);
    if(result == EGL_FALSE)
    {
        std::cerr << "Error binding API!\n";
        return false;
    }


    static const EGLint config_attributes[] =
    {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_ALPHA_SIZE, 8,
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_NONE
    };

    GLint numConfigs;
    result = eglChooseConfig(display, config_attributes, &config, 1, &numConfigs);

    if(result == EGL_FALSE)
    {
        std::cerr << "Error choosing config!\n";
        return false;
    }


    context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
    if(context == EGL_NO_CONTEXT)
    {
        std::cout << "Error: " << eglGetError() << "\n";

        std::cerr << "Error getting context!\n";
        return false;
    }

    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = display_width;
    dst_rect.height = display_height;

//.........这里部分代码省略.........
开发者ID:jefflunt,项目名称:glint-ui,代码行数:101,代码来源:Renderer_init_rpi.cpp

示例8: createWindow

void jfSDLWindow::createWindow( jfUint32 width, 
		jfUint32 height, 
		jfUint32 bpp, 
		bool fullscreen, 
		const jfString& title)
{

	if( SDL_Init( SDL_INIT_VIDEO ) != 0 )
	{
		std::stringstream out;
		out<<"Couldn't initialize SDL:"<< SDL_GetError();
        jfLog(JF_LOG_ERROR, out.str());
		assert(0 && "Couldn't initialize SDL");
	}

	//all values are "at least"!
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	// Set the title.
	SDL_WM_SetCaption(title.c_str(), title.c_str());

	// Flags tell SDL about the type of window we are creating.
	int flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWSURFACE | SDL_OPENGLBLIT | SDL_HWPALETTE;

	if(fullscreen)
	{
		flags |= SDL_FULLSCREEN;
	}

	m_Screen = SDL_SetVideoMode( width, height, bpp, flags );

    if ( m_Screen == NULL )
	{
		std::stringstream out;
		out<<"Couldn't set %dx%dx%d video mode:"<<width<<height<<bpp<< SDL_GetError();
        jfLog(JF_LOG_ERROR, out.str());
		assert(0 && "Couldn't set %dx%dx%d video mode:");
    }

    SDL_FillRect(m_Screen, NULL, SDL_MapRGBA(m_Screen->format,0,0,0,0));

	//SDL doesn't trigger off a ResizeEvent at startup, but as we need this for OpenGL, we do this ourself
	SDL_Event resizeEvent;
	resizeEvent.type = SDL_VIDEORESIZE;
	resizeEvent.resize.w = width;
	resizeEvent.resize.h = height;

	SDL_PushEvent(&resizeEvent);

	//Init glew
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		std::stringstream out;
		out<<"Couldn't initialize GLEW:"<< glewGetErrorString(err);
        jfLog(JF_LOG_ERROR, out.str());
		assert(0 && "Couldn't initialize GLEW");
	}
}
开发者ID:df3n5,项目名称:iet,代码行数:64,代码来源:jfSDLWindow.cpp

示例9: Init

bool Game::Init(const char* title, int xpos, int ypos, int width, int height,
		int flags) {

	// attempt to initialize SDL
	if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {
		Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 10000);

//		 init the window

		m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
		if (m_pWindow != 0) // window init success
				{
			m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
			if (m_pRenderer != 0) // renderer init success
					{
				SDL_SetRenderDrawColor(m_pRenderer, 255, 255, 255, 255);

			} else {
				return false; // renderer init fail
			}
		} else {
			return false; // window init fail
		}
	} else {
		return false; // SDL init fail
	}

	m_bRunning = true; // everything inited successfully,
//		start the main loop
			//initial game State
	SDL_Surface* temp = IMG_Load("images/GameBackground.png");

//Create texture from surface pixels
	m_BackGroundTexture = SDL_CreateTextureFromSurface(m_pRenderer, temp);
	SDL_FreeSurface(temp);

	SoundsBank::sound = new SoundsBank();
	SoundsBank::sound->initSoundEffect("sounds/hover.wav");
	SoundsBank::sound->initSoundEffect("sounds/connect.wav");
	SoundsBank::sound->initSoundEffect("sounds/button-24.wav");
	SoundsBank::sound->initSoundEffect("sounds/removeCards.wav");

	StateManager::stateMachine = new StateManager();
	StateManager::stateMachine->setCurrentGameStates(MENU);

	Timer::g_Timer = new Timer();

	StartMenu.InitSatistics(m_pRenderer);
	StartMenu.Init(m_pRenderer);
	StartMenu.InitRules(m_pRenderer);

	m_buttonsMenu.Init(m_pRenderer);
	for (int iter = 0; iter < 5; iter++) {
		m_buttonsMenu.setSource(iter * 232, 0, 232, 52);
		m_buttonsMenu.setDestination(100, (250 + 60 * iter), 260, 50);

		m_buttonSet.push_back(m_buttonsMenu);
	}
	PlayButton = m_buttonSet.at(0);
	PlayButton.setSource(0, 0, 232, 52);
	PlayButton.setDestination(410, 684, 240, 60);

	m_buttonSet.at(4).setDestination(25, 699, 150, 45);

	m_cardLogic.Init(m_pRenderer);

	txtTimer.Set(513, 50, 30, 40, " ");
	txtTimer.setTextColor(255, 255, 0, 255);

	gameOver.Set(512, 150, 30, 40, " ");
	gameOver.setTextColor(255, 255, 0, 255);

	level.Set(790, 50, 30, 40, " ");
	level.setTextColor(255, 255, 0, 255);

//	**************
	bet.Set(950, 702, 30, 40, " ");
	bet.setTextColor(255, 255, 0, 255);
	bet.IntToTextMessage(5);

	credit.Set(295, 704, 25, 35, " ");
	credit.setTextColor(255, 255, 0, 255);

	profit.Set(790, 702, 30, 40, " ");
	profit.setTextColor(255, 255, 0, 255);

//	***********************************

	m_statTxtClicks.Set(155, 60, 18, 22, " ");
	m_statTxtClicks.setTextColor(255, 255, 0, 255);

	m_statTxtLevelStatus.Set(240, 35, 18, 22, " ");
	m_statTxtLevelStatus.setTextColor(255, 255, 0, 255);

	m_statTxtSeconds.Set(155, 90, 18, 22, " ");
	m_statTxtSeconds.setTextColor(255, 255, 0, 255);

	m_statTxtLevelNumber.Set(155, 35, 18, 22, " ");
	m_statTxtLevelNumber.setTextColor(255, 255, 0, 255);

//.........这里部分代码省略.........
开发者ID:miroslavavramov,项目名称:Memory-Game,代码行数:101,代码来源:Game.cpp

示例10: I_InitGraphics

void I_InitGraphics(void)
{
    SDL_Event dummy;
    byte *doompal;
    char *env;

    // Pass through the XSCREENSAVER_WINDOW environment variable to 
    // SDL_WINDOWID, to embed the SDL window into the Xscreensaver
    // window.

    env = getenv("XSCREENSAVER_WINDOW");

    if (env != NULL)
    {
        char winenv[30];
        int winid;

        sscanf(env, "0x%x", &winid);
        M_snprintf(winenv, sizeof(winenv), "SDL_WINDOWID=%i", winid);

        putenv(winenv);
    }

    SetSDLVideoDriver();
    SetWindowPositionVars();

    if (SDL_Init(SDL_INIT_VIDEO) < 0) 
    {
        I_Error("Failed to initialize video: %s", SDL_GetError());
    }

    // Set up title and icon.  Windows cares about the ordering; this
    // has to be done before the call to SDL_SetVideoMode.

    I_InitWindowTitle();
    I_InitWindowIcon();

    // Warning to OS X users... though they might never see it :(
#ifdef __MACOSX__
    if (fullscreen)
    {
        printf("Some old versions of OS X might crash in fullscreen mode.\n"
               "If this happens to you, switch back to windowed mode.\n");
    }
#endif

    //
    // Enter into graphics mode.
    //
    // When in screensaver mode, run full screen and auto detect
    // screen dimensions (don't change video mode)
    //

    if (screensaver_mode)
    {
        SetVideoMode(NULL, 0, 0);
    }
    else
    {
        int w, h;

        if (autoadjust_video_settings)
        {
            I_AutoAdjustSettings();
        }

        w = screen_width;
        h = screen_height;

        screen_mode = I_FindScreenMode(w, h);

        if (screen_mode == NULL)
        {
            I_Error("I_InitGraphics: Unable to find a screen mode small "
                    "enough for %ix%i", w, h);
        }

        if (w != screen_mode->width || h != screen_mode->height)
        {
            printf("I_InitGraphics: %s (%ix%i within %ix%i)\n",
                   WindowBoxType(screen_mode, w, h),
                   screen_mode->width, screen_mode->height, w, h);
        }

        SetVideoMode(screen_mode, w, h);
    }

    // Start with a clear black screen
    // (screen will be flipped after we set the palette)

    SDL_FillRect(screenbuffer, NULL, 0);

    // Set the palette

    doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE);
    I_SetPalette(doompal);
    SDL_SetColors(screenbuffer, palette, 0, 256);

    CreateCursors();

//.........这里部分代码省略.........
开发者ID:OCForks,项目名称:chocolate-doom,代码行数:101,代码来源:i_video.c

示例11: hello_world_init

gboolean hello_world_init (HelloWorld* self) {
	gboolean result = FALSE;
	gint _tmp0_ = 0;
	gint _tmp3_ = 0;
	gboolean _tmp6_ = FALSE;
	SDL_Window* _tmp8_ = NULL;
	SDL_Window* _tmp9_ = NULL;
	SDL_Window* _tmp12_ = NULL;
	SDL_Renderer* _tmp13_ = NULL;
	SDL_Renderer* _tmp14_ = NULL;
	SDL_Renderer* _tmp17_ = NULL;
	gint imgInitFlags = 0;
	gint initResult = 0;
	gint _tmp18_ = 0;
	gint _tmp19_ = 0;
	gint _tmp20_ = 0;
	gint _tmp21_ = 0;
	gint _tmp22_ = 0;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = SDL_Init ((guint32) SDL_INIT_VIDEO);
	if (_tmp0_ < 0) {
		FILE* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		_tmp1_ = stdout;
		_tmp2_ = SDL_GetError ();
		fprintf (_tmp1_, "SDL could not initialize! SDL Error: %s\n", _tmp2_);
		result = FALSE;
		return result;
	}
	_tmp3_ = IMG_Init ((gint) IMG_INIT_PNG);
	if (_tmp3_ < 0) {
		FILE* _tmp4_ = NULL;
		const gchar* _tmp5_ = NULL;
		_tmp4_ = stdout;
		_tmp5_ = IMG_GetError ();
		fprintf (_tmp4_, "SDL_image could not initialize! SDL_image Error: %s\n", _tmp5_);
		result = FALSE;
		return result;
	}
	_tmp6_ = SDL_SetHint ("SDL_RENDER_SCALE_QUALITY", "1");
	if (!_tmp6_) {
		FILE* _tmp7_ = NULL;
		_tmp7_ = stdout;
		fputs ("Warining: Linear texture filtering not enabled!", _tmp7_);
	}
	_tmp8_ = SDL_CreateWindow ("SDL Tutorial", (gint) SDL_WINDOWPOS_CENTERED_MASK, (gint) SDL_WINDOWPOS_CENTERED_MASK, HELLO_WORLD_SCREEN_WIDTH, HELLO_WORLD_SCREEN_HEIGHT, (guint32) SDL_WINDOW_SHOWN);
	_SDL_DestroyWindow0 (self->priv->window);
	self->priv->window = _tmp8_;
	_tmp9_ = self->priv->window;
	if (_tmp9_ == NULL) {
		FILE* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
		_tmp10_ = stdout;
		_tmp11_ = SDL_GetError ();
		fprintf (_tmp10_, "Window could not be created! SDL Error: %s\n", _tmp11_);
		result = FALSE;
		return result;
	}
	_tmp12_ = self->priv->window;
	_tmp13_ = SDL_CreateRenderer (_tmp12_, -1, (guint32) SDL_RENDERER_ACCELERATED);
	_SDL_DestroyRenderer0 (self->priv->renderer);
	self->priv->renderer = _tmp13_;
	_tmp14_ = self->priv->renderer;
	if (_tmp14_ == NULL) {
		FILE* _tmp15_ = NULL;
		const gchar* _tmp16_ = NULL;
		_tmp15_ = stdout;
		_tmp16_ = SDL_GetError ();
		fprintf (_tmp15_, "Renderer could not be created! SDL Error: %s\n", _tmp16_);
		result = FALSE;
		return result;
	}
	_tmp17_ = self->priv->renderer;
	SDL_SetRenderDrawColor (_tmp17_, (guint8) 0xFF, (guint8) 0xFF, (guint8) 0xFF, (guint8) SDL_ALPHA_OPAQUE);
	imgInitFlags = (gint) IMG_INIT_PNG;
	_tmp18_ = imgInitFlags;
	_tmp19_ = IMG_Init (_tmp18_);
	initResult = _tmp19_;
	_tmp20_ = initResult;
	_tmp21_ = imgInitFlags;
	_tmp22_ = imgInitFlags;
	if ((_tmp20_ & _tmp21_) != _tmp22_) {
		FILE* _tmp23_ = NULL;
		const gchar* _tmp24_ = NULL;
		_tmp23_ = stdout;
		_tmp24_ = IMG_GetError ();
		fprintf (_tmp23_, "SDL_image could not initialize! SDL_image Error: %s\n", _tmp24_);
		result = FALSE;
		return result;
	}
	result = TRUE;
	return result;
}
开发者ID:darkoverlordofdata,项目名称:sdl2-vala-valama,代码行数:93,代码来源:test.c

示例12: createGemWindow

/////////////////////////////////////////////////////////
// createGemWindow
//
/////////////////////////////////////////////////////////
GEM_EXTERN int createGemWindow(WindowInfo &info, WindowHints &hints)
{
  static int firstTime = 1;
  if (firstTime) {
    SDL_Init(SDL_INIT_VIDEO);
    firstTime = 0;
  }

  if (! hints.actuallyDisplay) {
    return(1);
  }

  int w = hints.width;
  int h = hints.height;
  int x = hints.x_offset;
  int y = hints.y_offset;
  bool fullscreen = (hints.fullscreen != 0);
  bool border = (hints.border != 0);

  info.win = SDL_CreateWindow(hints.title, x, y, w, h
    , SDL_WINDOW_OPENGL
    | SDL_WINDOW_RESIZABLE
    | (fullscreen ? SDL_WINDOW_FULLSCREEN : 0)
    | (border ? 0 : SDL_WINDOW_BORDERLESS)
    );
  info.fs = fullscreen;

  if (! info.win)  {
    error("GEM: Unable to create window");
    return(0);
  }

// Emscripten doesn't support shared contexts yet
#if 0
  if (hints.shared) {
    if (SDL_GL_MakeCurrent(info.win, hints.shared)) {
      error("GEM: Unable to make shared OpenGL context current: %s", SDL_GetError());
      destroyGemWindow(info);
      return(0);
    }
    SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
  }
#endif
  info.context = SDL_GL_CreateContext(info.win);
#if 0
  if (! info.context) {
    error("GEM: Unable to create OpenGL context: %s", SDL_GetError());
    SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0);
    destroyGemWindow(info);
    return(0);
  }
  SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0);
#endif

  if (SDL_GL_MakeCurrent(info.win, info.context)) {
    error("GEM: Unable to make OpenGL context current: %s", SDL_GetError());
    destroyGemWindow(info);
    return(0);
  }

  if (fullscreen) {
    SDL_RaiseWindow(info.win);
  }

  return(1);
}
开发者ID:umlaeute,项目名称:Gem,代码行数:70,代码来源:GemWinCreateEM.cpp

示例13: main

/**
 *\fn int main(int argc, char *argv[])
 * Main
 *\param[in,out] argc argc
 *\param[in,out] argv argv
 */
int main(int argc, char *argv[])
{
    SDL_Surface *screen = NULL;

    int go = 1;
    int ret,ret1, ret2 = 0, ret3, ret4;

    char level_name[MAX_SIZE_FILE_NAME];
    char player_name[MAX_SIZE_FILE_NAME];
    int nb_lvl;
    /*sound*/
    Sound *sound_system;
    sound_system = createSound();

    /*keyboard config*/
    SDLKey kc[NB_KEY-1];

    /*input*/
    Input in;

    SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK);

    Player *current_player;

    current_player = (Player *)malloc(sizeof(Player));

    /*screen initialization*/
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);

    initInput(&in);

    /*configurations loading */
    loadSoundOptions("configuration/sound.conf",sound_system);


    SDL_WM_SetCaption("Super Martin", NULL); //window name

    SDL_ShowCursor(SDL_DISABLE); //delete the mouse

    while (go) //main loop
    {
        if(titleMenu(screen,&go,sound_system, &in))
        {

            while( (ret3 = menuPlayers(screen, player_name, &go, sound_system, &in)) != -1 && go)
            {
                switch(ret3)
                {
                    case -1:
                        break;
                    case 2  :
                        ret2 = newPlayer(screen, player_name, sound_system, &go);
                        if(ret2 == 1)
                        {
                            current_player->levelMax = 1;
                            current_player->nbCoins = 0;
                            current_player->nbLifes = 3;
                            current_player->nbProjectile = 5;
                            savePlayer("save/.save", player_name, current_player);
                            loadInputOptions("default",kc,&in);
                            saveInputOptions(player_name, kc, &in);
                        }
                        else
                            break;

                    case 1  :
                        loadPlayer("save/.save", player_name, current_player);
                        loadInputOptions(player_name,kc,&in);
                        while(go && (ret1 = mainMenu(screen,&go,sound_system, player_name, &in)) != -1)
                        {
                            switch(ret1)
                            {
                                case -1:
                                    break;
                                case 0:

                                    while( (ret4 = menuLevel(screen,level_name,sound_system, player_name, current_player, &go, &nb_lvl, &in)) != -1 && go)
                                    {
                                        while(play(screen,level_name,sound_system,&go,kc, &in, current_player, player_name, ret4+1, nb_lvl) && go);
                                    }
                                    break;

                                case 1 :
                                    save(screen, "save/.save", player_name, current_player, &go);
                                    loadPlayer("save/.save", player_name, current_player);
                                    break;

                                case 2 :
                                    while((ret = optionMenu(screen,&go,sound_system,kc, &in)) != -1 && go)
                                    {
                                        switch(ret)
                                        {
                                            case -1:
                                                break;
//.........这里部分代码省略.........
开发者ID:Dalan94,项目名称:Super_Martin,代码行数:101,代码来源:main.c

示例14: main

int main(int argc, char* argv[])
{
    SDL_Surface *screen = NULL;
    SDL_Surface *image = NULL;
    SDL_Surface *rot = NULL;
    const SDL_VideoInfo *videoInfo = NULL;
    FILE* file;
    double scale;
    int value;
    int prevValue = 0;
    int rc = 0;
    void *status[2];

    pthread_t thread[2]; 

    pthread_mutex_init(&mutexRW, NULL);

    pthread_create(&thread[0], NULL, run_thread, NULL);   

    /*-----------------------------------------------------------------*/

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        fprintf(stderr, "SDL_Init failed - %s\n", SDL_GetError());
        return 1;
    }

    /*-----------------------------------------------------------------*/

    videoInfo = SDL_GetVideoInfo();

    if (videoInfo == 0)
    {
        fprintf(stderr, "SDL_GetVideoInfo failed - %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    /*-----------------------------------------------------------------*/

    rc = pthread_join(thread[0], &status[0]);

    //image = IMG_LoadPNG_RW(getImage());

    image = IMG_LoadPNG_RW(rw);

    //scale = (image->h)/(videoInfo->current_h);
    scale = 0.5;

    /*-----------------------------------------------------------------*/
while(1){
    //pthread_mutex_init(&mutexRW, NULL);

    pthread_create(&thread[0], NULL, run_thread, NULL);

    value = getHeight();

    //drawScreen(image, value, prevValue, scale, videoInfo);

    if (value != image->h) {
        //scale = (image->w)/(videoInfo->current_w);
        scale = 0.5;
	if (prevValue != image->h) {
	    screen = SDL_SetVideoMode((image->h)*scale,
		                      (image->w)*scale,
		                      videoInfo->vfmt->BitsPerPixel,
		                      SDL_SWSURFACE|SDL_DOUBLEBUF);
	}
        rot = rotozoomSurface( image, 90, scale, SMOOTHING_ON );
    }

    if (value == image->h) {
	//scale = (image->h)/(videoInfo->current_h);
        scale = 0.5;
	if (prevValue != image->h) {
	    screen = SDL_SetVideoMode((image->w)*scale,
		                      (image->h)*scale,
		                      videoInfo->vfmt->BitsPerPixel,
		                      SDL_SWSURFACE|SDL_DOUBLEBUF);
	}
        rot = rotozoomSurface( image, 0, scale, SMOOTHING_ON );
    }

    SDL_FreeSurface(image);

    /*if (!image)
    {
        fprintf(stderr, "IMG_LoadBMP_RW failed - %s\n", IMG_GetError());
        SDL_Quit();
        //return 1;
    }*/

    SDL_BlitSurface(rot, NULL, screen, 0);

    SDL_Flip(screen);

    SDL_FreeSurface(rot);

    prevValue = value;

//.........这里部分代码省略.........
开发者ID:bass0324,项目名称:Senior_Design,代码行数:101,代码来源:sdl_test_thread_working.c

示例15: emulate

int emulate(smn8_rom *rom)
{
	SDL_Window *window;
	SDL_Surface *screen;
#ifdef HAVE_AUDIO
	SDL_AudioSpec audio_spec;
#endif
	smn8_vm vm;
	emulator_state state;

#ifdef HAVE_AUDIO
	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
#else
	if(SDL_Init(SDL_INIT_VIDEO) != 0)
#endif
	{
		fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
		return EXIT_FAILURE;
	}

#ifdef HAVE_AUDIO
	SDL_zero(audio_spec);

	audio_spec.freq = 22050;
	audio_spec.format = AUDIO_U16;
	audio_spec.channels = 2;
	audio_spec.samples = 4096;
	audio_spec.callback = audio;

	if(SDL_OpenAudio(&audio_spec, NULL) != 0)
	{
		fprintf(stderr, "Failed to initialize SDL audio: %s\n", SDL_GetError());
		SDL_Quit();
		return EXIT_FAILURE;
	}
#endif

	window = SDL_CreateWindow("SMN8", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
									  WIDTH, HEIGHT, 0);

	if(window == NULL)
	{
		fprintf(stderr, "Failed to create SDL Window: %s\n", SDL_GetError());
#ifdef HAVE_AUDIO
		SDL_CloseAudio();
#endif
		SDL_Quit();
		return EXIT_FAILURE;
	}

	SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1");

	screen = SDL_GetWindowSurface(window);
	if(screen == NULL)
	{
		fprintf(stderr, "Failed to get a valid SDL Surface: %s\n", SDL_GetError());
		SDL_DestroyWindow(window);
#ifdef HAVE_AUDIO
		SDL_CloseAudio();
#endif
		SDL_Quit();
		return EXIT_FAILURE;
	}

	state.colors[COLOR_BG] = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);

#ifdef HAVE_LIME
	state.colors[COLOR_FG] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00);
#else
	state.colors[COLOR_FG] = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF);
#endif

	SDL_FillRect(screen, NULL, state.colors[COLOR_BG]);

	state.vm = &vm;
	state.screen = screen;
	state.window = window;
#ifndef __EMSCRIPTEN__
	state.ticks = SDL_GetTicks();
#endif

	if(!smn8_vm_init(&vm, rom))
	{
		smn8_vm_clear(&vm);
		SDL_DestroyWindow(window);
#ifdef HAVE_AUDIO
		SDL_CloseAudio();
#endif
		SDL_Quit();
	}

#ifdef __EMSCRIPTEN__
	emscripten_set_main_loop_arg(tick, &state, 0, 1);
#else
	for(;;)
	{
		if(!tick(&state))
			break;
	}

//.........这里部分代码省略.........
开发者ID:icebreaker,项目名称:simon8,代码行数:101,代码来源:emulator.c


注:本文中的SDL_Init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。