src/video.c
/* Initializes the video subsystem and creates all resources necessary for
   rendering to occur. */
Initializes the video subsystem and creates all resources necessary for
rendering to occur.
Initializes the video subsystem and creates all resources necessary for rendering to occur .
int video_init(const char *title, int render_width, int render_height,
               int window_width, int window_height) {
	tex_width = render_width;
	tex_height = render_height;
	wnd_width = window_width;
	wnd_height = window_height;
	SDL_Init(SDL_INIT_VIDEO);
	lprint(INFO, "Initializing video (%ix%i surface, %ix%i window)...",
		tex_width, tex_height, wnd_width, wnd_height);
	lprint(DEBUG, "Creating window");
	window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED, window_width, window_height, 0);
	if(window == NULL) {
		lprint(ERROR, "Error creating window: %s", SDL_GetError());
		return 1;
	}
	lprint(DEBUG, "Creating hardware accelerated renderer");
	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if(renderer == NULL) {
		lprint(WARN, "Failed to create hardware accelerated renderer: %s", SDL_GetError());
		lprint(WARN, "Attempting to create a software renderer");
		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC);
		if(renderer == NULL) {
			lprint(ERROR, "Error creating renderer: %s", SDL_GetError());
			return 1;
		}
	}
	lprint(DEBUG, "Creating texture");
	texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
		SDL_TEXTUREACCESS_STREAMING, tex_width, tex_height);
	if(texture == NULL) {
		lprint(ERROR, "Error creating texture: %s", SDL_GetError());
		return 1;
	}
	pixels = malloc(sizeof(Uint32) * tex_width * tex_height);
	lprint(INFO, "Video subsystem initialized successfully");
	return 0;
}
int video_init ( const char * title , int render_width , int render_height , int window_width , int window_height ) { tex_width = render_width ; tex_height = render_height ; wnd_width = window_width ; wnd_height = window_height ; SDL_Init ( SDL_INIT_VIDEO ) ; lprint ( INFO , " " , tex_width , tex_height , wnd_width , wnd_height ) ; lprint ( DEBUG , " " ) ; window = SDL_CreateWindow ( title , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , window_width , window_height , 0 ) ; if ( window == NULL ) { lprint ( ERROR , " " , SDL_GetError ( ) ) ; return 1 ; } lprint ( DEBUG , " " ) ; renderer = SDL_CreateRenderer ( window , -1 , SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ) ; if ( renderer == NULL ) { lprint ( WARN , " " , SDL_GetError ( ) ) ; lprint ( WARN , " " ) ; renderer = SDL_CreateRenderer ( window , -1 , SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC ) ; if ( renderer == NULL ) { lprint ( ERROR , " " , SDL_GetError ( ) ) ; return 1 ; } } lprint ( DEBUG , " " ) ; texture = SDL_CreateTexture ( renderer , SDL_PIXELFORMAT_ARGB8888 , SDL_TEXTUREACCESS_STREAMING , tex_width , tex_height ) ; if ( texture == NULL ) { lprint ( ERROR , " " , SDL_GetError ( ) ) ; return 1 ; } pixels = malloc ( sizeof ( Uint32 ) * tex_width * tex_height ) ; lprint ( INFO , " " ) ; return 0 ; }
Initializes the video subsystem and creates all resources necessary for
rendering to occur.
Initializes the video subsystem and creates all resources necessary for rendering to occur .
/* Copies all of the passed variables into local variables. */ /* Initializes SDL's video subsystem. This should be called before the
	   video subsystem is used. */ /* Creates the SDL window. This is the physical window that is displayed
	   on the user's screen. */ /* If the window variable is null, the window has not been created
		   successfully. Log the error that SDL gave us and return with an
		   error status. */ /* Creates an SDL renderer. This takes an SDL texture and plots it into the
	   SDL window. First, we try to create a hardware accelerated renderer. */ /* If we make it inside of this block, we were unable to create an
		   accelerated renderer. First we log the error, then we try to create
		   a software renderer as a fallback. */ /* If we made it here, we were unable to create a software
			   renderer. Log the error and return with an error status. */ /* Creates an SDL texture with a 32-bit ARGB (alpha, red, green, blue)
	   pixel format. This contains the raw pixel data that the renderer
	   processes and sends to the video card.

	   We use a streaming texture for this, as we're going to be updating it
	   on every frame. */ /* If we made it here, we were unable to create a texture. Log the
		   error and return with an error status. */ /* Initializes the pixel array. This will allow the pixel array to be used
	   to update the resulting video output. */ /* Log our success and return a normal status. */