-
Notifications
You must be signed in to change notification settings - Fork 6
/
texture.c
90 lines (74 loc) · 2.06 KB
/
texture.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <SDL.h>
int main(int argc, char* argv[]){
int quit = 1;
SDL_Event event;
SDL_Window *window = NULL;
SDL_Renderer *render = NULL;
SDL_Texture *texture = NULL;
SDL_Rect rect;
rect.w = 60;
rect.h = 60;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
SDL_Log("Hello world");
window = SDL_CreateWindow("hello world",
200,400,
640,
480,
SDL_WINDOW_SHOWN);
if(!window){
SDL_Log("Failed to Create Window!");
goto __EXIT;
}
render = SDL_CreateRenderer(window, -1 ,0);
if(!render){
SDL_Log("Failed to CreateRenderer!");
goto __DWINDOW;
}
/*
SDL_SetRenderDrawColor(render, 255, 0, 0, 255);
SDL_RenderClear(render);
SDL_RenderPresent(render);
*/
texture = SDL_CreateTexture(render,
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET,
640,
480);
if(!texture){
SDL_Log("Failed to CreateRenderer!");
//goto __RENDER;
}
do{
//SDL_Event event;
SDL_PollEvent(&event);
switch(event.type){
case SDL_QUIT:
quit = 0;
break;
default:
SDL_Log("event type is %d", event.type);
}
rect.x = rand() % 600;
rect.y = rand() % 450;
SDL_SetRenderTarget(render, texture);
SDL_SetRenderDrawColor(render, 0, 0, 0, 0);
SDL_RenderClear(render);
SDL_RenderDrawRect(render, &rect);
SDL_SetRenderDrawColor(render, 255, 0, 0, 0);
SDL_RenderFillRect(render, &rect);
SDL_SetRenderTarget(render, NULL);
SDL_RenderCopy(render, texture, NULL, NULL);
SDL_RenderPresent(render);
}while(quit);
SDL_DestroyTexture(texture);
//SDL_Delay(10000);
/*
__RENDER:
SDL_DestroyRender(render);
*/
__DWINDOW:
SDL_DestroyWindow(window);
__EXIT:
SDL_Quit();
return 0;
}