this repo has no description
1#include "SDL.h"
2#include "SDL_gpu.h"
3#include <math.h>
4#include "compat.h"
5#include "common.h"
6#include "demo-font.h"
7
8
9int main(int argc, char* argv[])
10{
11 GPU_Target* screen;
12
13 screen = initialize_demo(argc, argv, 800, 600);
14 if(screen == NULL)
15 return -1;
16
17 {
18 GPU_Image* image2;
19 GPU_Image* image3;
20 SDL_Surface* font_surface;
21 DemoFont* font;
22 GPU_Image* mode1image;
23 GPU_Image* mode2image;
24 SDL_Color circleColor = { 255, 0, 0, 128 };
25 SDL_Color circleColor2 = { 0, 0, 255, 128 };
26 Uint32 startTime;
27 long frameCount;
28 const Uint8* keystates;
29 int mode;
30 int x;
31 int y;
32 Uint8 done;
33 SDL_Event event;
34
35 image2 = GPU_LoadImage("data/test2.bmp");
36 if (image2 == NULL)
37 return -1;
38
39 image3 = GPU_LoadImage("data/test.bmp");
40 if (image3 == NULL)
41 return -1;
42
43 font_surface = GPU_LoadSurface("data/comic14.png");
44 font = FONT_Alloc(font_surface);
45 GPU_SetRGB(font->image, 255, 0, 0);
46 SDL_FreeSurface(font_surface);
47
48 mode1image = GPU_CreateImage(300, 300, GPU_FORMAT_RGBA);
49 if (mode1image == NULL)
50 return -1;
51
52 mode2image = GPU_CreateImage(400, 400, GPU_FORMAT_RGBA);
53 if (mode2image == NULL)
54 return -1;
55
56 GPU_LoadTarget(mode1image);
57 GPU_LoadTarget(mode2image);
58
59
60 startTime = SDL_GetTicks();
61 frameCount = 0;
62
63 keystates = SDL_GetKeyState(NULL);
64
65 mode = 0;
66 x = 0;
67 y = 0;
68
69 done = 0;
70 while (!done)
71 {
72 while (SDL_PollEvent(&event))
73 {
74 if (event.type == SDL_QUIT)
75 done = 1;
76 else if (event.type == SDL_KEYDOWN)
77 {
78 if (event.key.keysym.sym == SDLK_ESCAPE)
79 done = 1;
80 else if (event.key.keysym.sym == SDLK_SPACE)
81 {
82 mode++;
83 if (mode > 1)
84 mode = 0;
85 }
86 else if (event.key.keysym.sym == SDLK_f)
87 GPU_SetFullscreen(!GPU_GetFullscreen(), 0);
88 else if (event.key.keysym.sym == SDLK_g)
89 GPU_SetFullscreen(!GPU_GetFullscreen(), 1);
90 else if (event.key.keysym.sym == SDLK_1)
91 GPU_UnsetVirtualResolution(screen);
92 else if (event.key.keysym.sym == SDLK_2)
93 GPU_SetVirtualResolution(screen, 1200, 800);
94 }
95 }
96
97 if (keystates[KEY_UP])
98 y -= 1;
99 else if (keystates[KEY_DOWN])
100 y += 1;
101 if (keystates[KEY_LEFT])
102 x -= 1;
103 else if (keystates[KEY_RIGHT])
104 x += 1;
105
106 GPU_Clear(screen);
107
108 if (mode == 0)
109 {
110 GPU_Target* mode1target = mode1image->target;
111 SDL_Color red = { 255, 0, 0, 255 };
112
113 GPU_ClearRGBA(mode1target, 0, 255, 0, 255);
114 GPU_Blit(image3, NULL, mode1target, image3->w / 2, image3->h / 2);
115
116
117 //GPU_BlitScale(image2, NULL, mode1target, mode1target->w/2, mode1target->h/2, 0.7f, 0.7f);
118 //GPU_BlitScale(image2, NULL, mode1target, x, y, 0.7f, 0.7f);
119
120 GPU_BlitTransform(image2, NULL, mode1target, x, y, 360 * sin(SDL_GetTicks() / 1000.0f), 0.7f*sin(SDL_GetTicks() / 2000.0f), 0.7f*sin(SDL_GetTicks() / 2000.0f));
121
122 GPU_Line(mode1target, 0, 0, mode1target->w, mode1target->h, red);
123 GPU_CircleFilled(mode1target, 70, 70, 20, circleColor);
124
125 GPU_Blit(mode1image, NULL, screen, mode1image->w / 2 + 50, mode1image->h / 2 + 50);
126 GPU_BlitScale(mode1image, NULL, screen, mode1image->w * 2 + 50, mode1image->h / 2 + 50, 0.7f, 0.7f);
127
128 GPU_CircleFilled(screen, 50 + 70, 50 + 70, 20, circleColor2);
129
130 GPU_Blit(image2, NULL, screen, screen->w - image3->w - image2->w / 2, screen->h - image2->h / 2);
131 GPU_Blit(image3, NULL, screen, screen->w - image3->w / 2, screen->h - image3->h / 2);
132 }
133 else if (mode == 1)
134 {
135 GPU_Target* mode2target = mode2image->target;
136 SDL_Color red = { 255, 0, 0, 255 };
137 SDL_Color blue = { 0, 0, 255, 255 };
138
139 GPU_ClearRGBA(mode2target, 255, 255, 255, 255);
140
141
142 GPU_Line(mode2target, 0, 0, mode2target->w, mode2target->h, red);
143 GPU_Line(mode2target, 0, mode2target->h, mode2target->w, 0, red);
144 GPU_TriFilled(mode2target, mode2target->w / 2, mode2target->h / 2 + 10, mode2target->w / 2 - 10, mode2target->h / 2 + 20, mode2target->w / 2 + 10, mode2target->h / 2 + 20, red);
145
146 GPU_Blit(image2, NULL, mode2target, x, y);
147
148
149
150 GPU_Line(screen, 0, 0, screen->w, screen->h, blue);
151 GPU_Line(screen, 0, screen->h, screen->w, 0, blue);
152
153 GPU_Blit(mode2image, NULL, screen, mode2image->w / 2, mode2image->h / 2);
154 }
155
156 FONT_Draw(font, screen, 20, 20, "Testing");
157
158 GPU_Flip(screen);
159
160 frameCount++;
161 if (frameCount % 500 == 0)
162 {
163 printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime));
164 printf("x,y: (%d, %d)\n", x, y);
165 }
166 }
167
168 printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime));
169
170 FONT_Free(font);
171 GPU_FreeImage(mode2image);
172 GPU_FreeImage(mode1image);
173 }
174
175 GPU_Quit();
176
177 return 0;
178}
179
180