Here's a small example using SDL2:
Code:
// sdl.c
//
// $ cc -O2 `pkg-config --cflags sdl2 SDL2_image` \
// -o sdl sdl.c \
// `pkg-config --libs sdl2 SDL2_image`
//
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
int main( int argc, char *argv[] )
{
SDL_Window *wnd;
SDL_Renderer *render;
SDL_Surface *img;
SDL_Texture *tex;
if ( argc != 2 )
{
fputs( "Usage: sdl <imagefile>\n", stderr );
return EXIT_FAILURE;
}
if ( access( argv[1], R_OK ) )
{
fprintf( stderr, "Error: Cannot open '%s'.\n", argv[1] );
return EXIT_FAILURE;
}
if ( SDL_Init( SDL_INIT_VIDEO ) )
{
fputs( "SDL_Init() error.\n", stderr );
return EXIT_FAILURE;
}
// Assuming your system supports 1920x1080!
wnd = SDL_CreateWindow( "Hello", 0, 0, 1920, 1080, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS );
if ( ! wnd )
{
fputs( "SDL_CreateWindow error.\n", stderr );
SDL_Quit();
return EXIT_FAILURE;
}
render = SDL_CreateRenderer( wnd, -1, SDL_RENDERER_ACCELERATED );
if ( ! render )
{
fputs( "SDL_CreateRenderer erro.\n", stderr );
SDL_DestroyWindow( wnd );
SDL_Quit();
return EXIT_FAILURE;
}
img = IMG_Load( argv[1] );
if ( ! img )
{
fputs( "SDL_Load() error.\n", stderr );
SDL_DestroyRenderer( render );
SDL_DestroyWindow( wnd );
SDL_Quit();
return EXIT_FAILURE;
}
tex = SDL_CreateTextureFromSurface( render, img );
SDL_FreeSurface( img );
if ( ! tex )
{
fputs( "SDL_CreateTextureFromSurface() error.\n", stderr );
SDL_DestroyRenderer( render );
SDL_DestroyWindow( wnd );
SDL_Quit();
return EXIT_FAILURE;
}
SDL_ShowCursor(0); // hide cursor.
SDL_RenderClear( render );
SDL_RenderCopy( render, tex, NULL, NULL );
SDL_RenderPresent( render );
while ( 1 )
{
SDL_Event ev;
if ( SDL_PollEvent( &ev ) )
{
if ( ev.type == SDL_KEYDOWN )
break;
}
}
SDL_DestroyTexture( tex );
SDL_DestroyRenderer( render );
SDL_DestroyWindow( wnd );
SDL_Quit();
return EXIT_SUCCESS;
}
This code will NOT calculate the correct aspect for the image... And you'll need to install libsdl2-dev and libsdl2-image-dev packages.