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


C++ SDL_CreateWindowAndRenderer函数代码示例

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


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

示例1: assert

	void SDLWindow::Initialize()
	{
		assert(((start_location.w > 0 && start_location.h > 0) || start_location.w == start_location.h),
			"If a special resolution modifier is to be used, then both length and width must be equal.");

		if (start_location == USE_CURRENT_RESOLUTION)
		{
			SDL_DisplayMode display_mode;

			assert((SDL_GetCurrentDisplayMode(DISPLAY_NUMBER, &display_mode) == 0), SDL_GetError());

			start_location.w = (double)display_mode.w;
			start_location.h = (double)display_mode.h;
		}

		if (fullscreen)
		{
			SDL_CreateWindowAndRenderer(0, 0,
				(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS),
				&window, &write_to);
			// Scale so the user's code doesn't know the difference.
			SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
			SDL_RenderSetLogicalSize(write_to, GfxRound(start_location.w), GfxRound(start_location.h));
		}
		else
		{
			SDL_CreateWindowAndRenderer(GfxRound(start_location.w), GfxRound(start_location.h), 0, &window, &write_to);
		}

		SDL_SetWindowTitle(this->window, this->title);

		SDL_SetRenderDrawColor(write_to, fill.r, fill.g, fill.b, fill.a);
		SDL_RenderClear(write_to);
		SDL_RenderPresent(write_to);
	}
开发者ID:JackMc,项目名称:CPlasmas,代码行数:35,代码来源:SDLWindow.cpp

示例2: SDL_GetError

int Game::initSystems()
{
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0) 
	{
		cerr << "Problem while initializing SDL" << endl;
		return -1;
	}
	
#ifndef WIN32 
	if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN, &m_pWindow, &m_pRenderer) < 0)
#else
	screen_w = 640;
	screen_h = 480;
	if (SDL_CreateWindowAndRenderer(screen_w, screen_h, 0, &m_pWindow, &m_pRenderer) < 0)
#endif
	{
		std::cout << "SDL_CreateWindowAndRenderer Error: " << SDL_GetError() << std::endl;
		return 0;
	}

	SDL_GetWindowSize(m_pWindow, &screen_w, &screen_h);

	screen = SDL_CreateRGBSurface(0, screen_w, screen_h, 32,
		0,
		0,
		0,
		0);

	if (screen == 0)
	{
		std::cout << "SDL_CreateRGBSurface Error: " << SDL_GetError() << std::endl;
		return false;
	}

	m_pScreenTexture = SDL_CreateTexture(m_pRenderer,
		SDL_PIXELFORMAT_ARGB8888,
		SDL_TEXTUREACCESS_STREAMING,
		screen_w, screen_h);

	if (m_pScreenTexture == 0)
	{
		std::cout << "SDL_CreateTexture Error: " << SDL_GetError() << std::endl;
		return -1;
	}
		
	if (TTF_Init() < 0) {
		cerr << "Problem initializing SDL_ttf" << endl;
		return -1;
	}
	if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 4096) < 0) {
		cerr << "Problem initializing SDL_mixer" << endl;
		return -1;
	}
    Mix_Init(MIX_INIT_MP3);
	return 0;
}
开发者ID:ZHANITEST,项目名称:SDLProgramming,代码行数:56,代码来源:Game.cpp

示例3: Init_Window

void Init_Window(unsigned int Height, unsigned Width, std::string Title)
{
	Window_Info.Height = Height;
	Window_Info.Width = Width;
	Window_Info.Title = Title;
	Window_Info.Ren = nullptr;
	Window_Info.Win = nullptr;
	Window_Info.Sur = nullptr;

	if (SDL_Init(SDL_INIT_VIDEO) < 0)
		throw std::runtime_error("SDL Init Failed!!");
#ifdef SDL_EX_TTF
	if (TTF_Init() < 0)
		throw std::runtime_error("TTF Init Failed!!");
#endif
	if (SDL_CreateWindowAndRenderer(Window_Info.Width, Window_Info.Height, SDL_WINDOW_SHOWN, &Window_Info.Win, &Window_Info.Ren) < 0)
	{
		std::cout << "Fuck!!" << SDL_GetError() << std::endl;
	}
	

	std::cout << "Fuck!!" << SDL_GetError() << std::endl;

	SDL_SetWindowTitle(Window_Info.Win, Title.c_str());
	Window_Info.Sur = SDL_GetWindowSurface(Window_Info.Win);

	SetSDLWindowIcon(Window_Info.Win);
	if (Window_Info.Sur == nullptr)
		throw std::runtime_error("Failed to Get Window Surface!!");
}
开发者ID:Alicepro,项目名称:Invitation_of_Crimson_Moon,代码行数:30,代码来源:SDL_EX.cpp

示例4: main

int main(int argc, char *argv[])
{
#pragma unused(argc, argv)
  SDL_Window *window;
  SDL_Renderer *renderer;
  int done = 0;
  SDL_Event event;
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    SDL_ERROR(SDL_Init);
    return 1;
  }
  if (SDL_CreateWindowAndRenderer(200, 200, 0, &window, &renderer) == -1) {
    SDL_ERROR(SDL_SetVideoMode);
    SDL_Quit();
    return 1;
  }
  while (!done) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT ||
	  (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_LGUI || event.key.keysym.mod == KMOD_RGUI))) {
	done = !0;
      }
    }
    SDL_Delay(0);
  }
  SDL_Delay(500);
  SDL_Quit();
  return 0;
}
开发者ID:iwadon,项目名称:junk,代码行数:29,代码来源:sdl_event_sample.c

示例5: srand

void mGraphics::initSDL(){
	srand((int)time(0));
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_CreateWindowAndRenderer(W, H, SDL_WINDOW_OPENGL, &(window), &(renderer));
	SDL_GetRendererInfo(renderer, &info);
	/*TODO: Check that we have OpenGL */
	if ((info.flags & SDL_RENDERER_ACCELERATED) == 0 ||
		(info.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
		/*TODO: Handle this. We have no render surface and not accelerated. */
	}
	
	/* Enable smooth shading */
	glShadeModel( GL_SMOOTH );
 
	/* Set the background black */
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
 
	/* Depth buffer setup */
	glClearDepth( 1.0f );
 
	/* Enables Depth Testing */
	glEnable( GL_DEPTH_TEST );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
 
	/* The Type Of Depth Test To Do */
	glDepthFunc( GL_LEQUAL );
 
	/* Really Nice Perspective Calculations */
	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
	SDL_GL_SetSwapInterval(1);
}
开发者ID:olehermanse,项目名称:SGP,代码行数:32,代码来源:mGraphics.cpp

示例6: lua_SDL_CreateWindowAndRenderer

	static int lua_SDL_CreateWindowAndRenderer(State & state){
		Stack * stack = state.stack;
		SDL_Window * window = NULL;
		SDL_Renderer * renderer = NULL;

		int retval = SDL_CreateWindowAndRenderer(
			stack->to<int>(1),
			stack->to<int>(2),
			(Uint32)stack->to<int>(3),
			&window,
			&renderer
			);
		Window * interfaceWindow = state.getInterface<Window>("LuaSDL_Window");
		Renderer * interfaceRenderer = state.getInterface<Renderer>("LuaSDL_Renderer");
		if (retval == 0){
			if (window){
				interfaceWindow->push(window);
			}
			else{
				stack->pushNil();
			}
			if (renderer){
				interfaceRenderer->push(renderer);
			}
			else{
				stack->pushNil();
			}
			return 2;
		}
		else{
			stack->push<bool>(false);
			return 1;
		}
	}
开发者ID:soulik,项目名称:LuaSDL-2.0,代码行数:34,代码来源:window.cpp

示例7: setupSDL

// makes sure sdl sets up correctly
// if not then it prints out an error
void setupSDL()
  {
  if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_VIDEO) != 0)
    {
    printf("SDL failed to init: %s\n", SDL_GetError());
    exit(1);
    }
      //Initialize SDL_mixer
               /* if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
                {
                    printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
                    exit(1);
                }*/
  // Create window and renderer
  // creates window for graphics
  // if it fails to set up correctly an error is given
  SDL_CreateWindowAndRenderer(600,400, SDL_WINDOW_SHOWN,&window, &renderer);

  if ((window == NULL) || (renderer == NULL))
    {
    printf("SDL_CreateWindowAndRenderer Error: %s\n", SDL_GetError() );
    exit(1);
    }
    
  }
开发者ID:deborahrempala,项目名称:ComputerGraphics,代码行数:27,代码来源:game2.cpp

示例8: main

int main() {
  SDL_Init(SDL_INIT_VIDEO);

  SDL_Window *window;
  SDL_Renderer *renderer;

  SDL_CreateWindowAndRenderer(600, 450, 0, &window, &renderer);

  int result = 0;

  result |= testImage(renderer, SCREENSHOT_DIRNAME "/" SCREENSHOT_BASENAME); // absolute path
  assert(result != 0);

  chdir(SCREENSHOT_DIRNAME);
  result = testImage(renderer, "./" SCREENSHOT_BASENAME); // relative path
  assert(result != 0);

  SDL_RenderPresent(renderer);

  printf("you should see an image.\n");

  SDL_Quit();

  REPORT_RESULT();

  return 0;
}
开发者ID:4ian,项目名称:emscripten,代码行数:27,代码来源:sdl2_image.c

示例9: main

int main()
{
	SDL_Window* win;

	// initialize SDL
	if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
		fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
	}

	// initialize window and renderer
	if(SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &win, 
				&ren) != 0) {
		fprintf(stderr, "\nUnable to intialize window: %s\n", SDL_GetError());
	}

	init_physics();

	// main lopp
	for(;;) {
		Uint32 t = SDL_GetTicks() + 1000/60;

		// physics step
		update_friction(0);
		update_drive();
		update_turn();
		cpSpaceStep(space, 1.0/60.0);
		debug_physics();

		// events
		SDL_Event e;
		while(SDL_PollEvent(&e)) {
			switch(e.type) {
			case SDL_QUIT:
				exit(0);
				break;
			}
		}
		const Uint8* k = SDL_GetKeyboardState(NULL);
		controls.forward = k[SDL_SCANCODE_UP];
		controls.back = k[SDL_SCANCODE_DOWN];
		controls.left = k[SDL_SCANCODE_LEFT];
		controls.right = k[SDL_SCANCODE_RIGHT];

		// render
		SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
		SDL_RenderClear(ren);

		SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
		render_objects();

		SDL_RenderPresent(ren);

		// time
		if(SDL_GetTicks() < t) {
			SDL_Delay(t - SDL_GetTicks());
		}
	}

	return 0;
}
开发者ID:andrenho,项目名称:newhope,代码行数:60,代码来源:testwheel.c

示例10: Window

SDLWindow::SDLWindow(uint32_t width, uint32_t height, uint8_t colorDepth, float pixelSize, float gamma, bool fullscreen)
    : Window(width, height, colorDepth, pixelSize, gamma),
    mFullscreen(fullscreen)
{
    // Initialize SDL's subsystems - in this case, only video.
    if(SDL_Init(SDL_INIT_VIDEO) < 0) 
    {
        //throw std::runtime_error("Unable to init SDL: " + SDL_GetError());
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        throw 0;
    }

    // Attempt to create a window with pixels under specific mode.
    SDL_CreateWindowAndRenderer(width, height, 0, &mWindow, &mRenderer);

    // If we fail, return error.
    if(mWindow == nullptr || mRenderer == nullptr) 
    {
        //throw std::runtime_error()
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
        exit(1);
    }

    SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255);
    SDL_RenderClear(mRenderer);

    mDrawCanvas = SDL_CreateTexture(
        mRenderer,
        SDL_PIXELFORMAT_ARGB8888,
        SDL_TEXTUREACCESS_STREAMING,
        width, height
    );

    mPixels.reset(new uint32_t[width * height]);
}
开发者ID:RyokoAkizuki,项目名称:backtrace,代码行数:35,代码来源:sdlwindow.cpp

示例11: SDL_CreateWindowAndRenderer

void RSScreen::Init(int32_t zoomFactor){
    this->scale =zoomFactor;
    
    int32_t width  = 320 * scale;
    int32_t height = 200 * scale;
    
    
    this->width = width;
    this->height = height;
    
    SDL_CreateWindowAndRenderer(width, height, SDL_WINDOW_HIDDEN, &sdlWindow, &sdlRenderer);
    
    
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
        printf("Unable to initialize SDL:  %s\n",SDL_GetError());
        return ;
    }
    
    sdlWindow = SDL_CreateWindow("RealSpace OBJ Viewer",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,this->width,this->height,SDL_WINDOW_OPENGL);
    
    // Create an OpenGL context associated with the window.
    SDL_GL_CreateContext(sdlWindow);
    
    
    glViewport(0,0,this->width,this->height);			// Reset The Current Viewport
    
    
    
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);				// Black Background

    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    
    SDL_ShowWindow(sdlWindow);
}
开发者ID:UIKit0,项目名称:libRealSpace,代码行数:34,代码来源:RSScreen.cpp

示例12: main

int main(int argc, char **argv)
{
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

    SDL_CreateWindowAndRenderer(SCREEN_WIDTH+232, SCREEN_HEIGHT+16, 0, &displayWindow, &displayRenderer);
    SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
    SDL_SetRenderDrawBlendMode(displayRenderer, SDL_BLENDMODE_BLEND);

    SCREEN_SHIFT_X = 8;
    SCREEN_SHIFT_Y = 8;

#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(null_loop_iter, 60, 1);
#endif

    srand(time(NULL));
    sound_init();
    resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
    load_resources();

    last_time = clock();

#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop_iter, 60, 1);
#else
    while (!done)
    {
        loop_iter();
    }
#endif

    sound_exit();
    Quit(0);
    return (0);
}
开发者ID:shinyquagsire23,项目名称:DesktopAdventures,代码行数:35,代码来源:main.c

示例13: SDL_CreateWindowAndRenderer

Gfx::Gfx() {

	SDL_CreateWindowAndRenderer(640, 480, 0, &this->_window, &this->_renderer);
	SDL_SetWindowTitle(this->_window, "Cavestory");
	
	std::cout << "Hello";
}
开发者ID:LMCGOW200,项目名称:cavestory-new,代码行数:7,代码来源:gfx.cpp

示例14: widthPx

ViewScreen::ViewScreen(unsigned int aWidth, unsigned int aHeight, unsigned int aBpp)
		: widthPx(aWidth), heightPx(aHeight), bpp(aBpp), lastTick(SDL_GetTicks()) {
	SDL_CreateWindowAndRenderer(widthPx, heightPx, SDL_WINDOW_SHOWN,
			&window, &renderer);
	if (window == NULL || renderer == NULL) {
		throw Exception("Failed to initialize window or renderer");
	}
}
开发者ID:sequoiahead,项目名称:tetpack,代码行数:8,代码来源:ViewScreen.cpp

示例15: graphics_init

graphics
graphics_init(int w, int h, const char* t) {
  struct graphics_t *g = malloc(sizeof(struct graphics_t));
  SDL_CreateWindowAndRenderer(w, h, 0, &g->window, &g->renderer);
  SDL_SetWindowTitle(g->window, t);
  g->sprite_sheets = map_init();
  return g;
}
开发者ID:bbergen,项目名称:dungeon,代码行数:8,代码来源:graphics.c


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