1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 640; // Window Parameter X
const int SCREEN_HEIGHT = 480; // Window Parameter Y
//_______________________________________________________________________________________________________
int main ( int argc, char* args[] )
{
SDL_Window* window = NULL; // The Window rendering
SDL_Surface* screensurface = NULL; // The screen in the Window
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf("SDL coiuld not be initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
window = SDL_CreateWindow("A Resume Game : Astroman",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_SHOWN);
if (window == NULL)
{
printf("Window could not be created ! SDL_Error: %s\n",SDL_GetError() );
}
else
{
screensurface = SDL_GetWindowSurface( window ); // Get Window Surface
SDL_FillRect(screensurface, NULL, SDL_MapRGB(screensurface->format, 0xB30, 0xB30, 0xB30)); // Background interface
SDL_UpdateWindowSurface( window );
}
}
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(window == nullptr)
{
printf("SDL_CreateRenderer Error! SDL_Error %s\n") ,SDL_GetError();
return 1;
}
SDL_Surface *image = SDL_LoadBMP("tux.bmp");
if(image == nullptr)
{
printf("SDL_LoadBMP Error! SDL_Error %s\n") ,SDL_GetError();
return 1;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,image);
SDL_FreeSurface(image);
if(texture == nullptr)
{
printf("SDL_Texture Error! SDL_Error %s\n") ,SDL_GetError();
return 1;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer,texture,NULL,NULL);
SDL_RenderPresent(renderer);
// SDL_BlitSurface(image , NULL, screensurface, NULL);
SDL_DestroyTexture( texture );
SDL_DestroyRenderer( renderer );
SDL_DestroyWindow( window );
SDL_Delay(2000);
SDL_Quit();
return 0;
}
|