Simplified the testshape example
This commit is contained in:
parent
bd2e2ee7aa
commit
59ca0c8b22
1 changed files with 3 additions and 18 deletions
|
@ -26,21 +26,14 @@ typedef struct LoadedPicture
|
||||||
const char *name;
|
const char *name;
|
||||||
} LoadedPicture;
|
} LoadedPicture;
|
||||||
|
|
||||||
void render(SDL_Renderer *renderer, SDL_Texture *texture, SDL_FRect texture_dimensions)
|
void render(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||||
{
|
{
|
||||||
SDL_FRect dst;
|
|
||||||
|
|
||||||
/* Clear render-target to blue. */
|
/* Clear render-target to blue. */
|
||||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xff, 0xff);
|
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xff, 0xff);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
/* Render the texture. */
|
/* Render the texture. */
|
||||||
dst.x = texture_dimensions.x;
|
SDL_RenderTexture(renderer, texture, NULL, NULL);
|
||||||
dst.y = texture_dimensions.y;
|
|
||||||
dst.w = texture_dimensions.w;
|
|
||||||
dst.h = texture_dimensions.h;
|
|
||||||
SDL_RenderTexture(renderer, texture, &texture_dimensions, &dst);
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +52,6 @@ int main(int argc, char **argv)
|
||||||
int button_down;
|
int button_down;
|
||||||
Uint32 pixelFormat = 0;
|
Uint32 pixelFormat = 0;
|
||||||
int w, h, access = 0;
|
int w, h, access = 0;
|
||||||
SDL_FRect texture_dimensions;
|
|
||||||
|
|
||||||
/* Enable standard application logging */
|
/* Enable standard application logging */
|
||||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||||
|
@ -110,7 +102,6 @@ int main(int argc, char **argv)
|
||||||
SHAPED_WINDOW_X, SHAPED_WINDOW_Y,
|
SHAPED_WINDOW_X, SHAPED_WINDOW_Y,
|
||||||
SHAPED_WINDOW_DIMENSION, SHAPED_WINDOW_DIMENSION,
|
SHAPED_WINDOW_DIMENSION, SHAPED_WINDOW_DIMENSION,
|
||||||
0);
|
0);
|
||||||
SDL_SetWindowPosition(window, SHAPED_WINDOW_X, SHAPED_WINDOW_Y);
|
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
for (i = 0; i < num_pictures; i++) {
|
for (i = 0; i < num_pictures; i++) {
|
||||||
SDL_DestroySurface(pictures[i].surface);
|
SDL_DestroySurface(pictures[i].surface);
|
||||||
|
@ -160,10 +151,6 @@ int main(int argc, char **argv)
|
||||||
button_down = 0;
|
button_down = 0;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
|
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
|
||||||
texture_dimensions.x = 0.0f;
|
|
||||||
texture_dimensions.y = 0.0f;
|
|
||||||
texture_dimensions.h = (float)w;
|
|
||||||
texture_dimensions.w = (float)h;
|
|
||||||
SDL_SetWindowSize(window, w, h);
|
SDL_SetWindowSize(window, w, h);
|
||||||
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
||||||
while (should_exit == 0) {
|
while (should_exit == 0) {
|
||||||
|
@ -183,8 +170,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
|
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
|
||||||
texture_dimensions.h = (float)w;
|
|
||||||
texture_dimensions.w = (float)h;
|
|
||||||
SDL_SetWindowSize(window, w, h);
|
SDL_SetWindowSize(window, w, h);
|
||||||
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +178,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(renderer, pictures[current_picture].texture, texture_dimensions);
|
render(renderer, pictures[current_picture].texture);
|
||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue