mirror of
https://github.com/love2d/megasource.git
synced 2026-08-20 12:40:06 +02:00
update SDL3 to latest commit
This commit is contained in:
@@ -18,9 +18,6 @@
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "icon.h"
|
||||
|
||||
#define WINDOW_WIDTH 640
|
||||
@@ -36,15 +33,16 @@ static int sprite_w, sprite_h;
|
||||
static SDL_Renderer *renderer;
|
||||
static int done;
|
||||
|
||||
static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned int len, int *w, int *h) {
|
||||
static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned int len, int *w, int *h)
|
||||
{
|
||||
SDL_Texture *texture = NULL;
|
||||
SDL_Surface *surface;
|
||||
SDL_IOStream *src = SDL_IOFromConstMem(data, len);
|
||||
if (src) {
|
||||
surface = SDL_LoadBMP_IO(src, SDL_TRUE);
|
||||
surface = SDL_LoadBMP_IO(src, true);
|
||||
if (surface) {
|
||||
/* Treat white as transparent */
|
||||
SDL_SetSurfaceColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 255, 255, 255));
|
||||
SDL_SetSurfaceColorKey(surface, true, SDL_MapSurfaceRGB(surface, 255, 255, 255));
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(r, surface);
|
||||
*w = surface->w;
|
||||
@@ -113,23 +111,18 @@ int main(int argc, char *argv[])
|
||||
int return_code = -1;
|
||||
int i;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (argc > 1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "USAGE: %s\n", argv[0]);
|
||||
return_code = 1;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) {
|
||||
if (!SDL_CreateWindowAndRenderer("testspriteminimal", WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
|
||||
return_code = 2;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (SDL_SetWindowTitle(window, argv[0]) < 0) {
|
||||
SDL_Log("SDL_SetWindowTitle: %s", SDL_GetError());
|
||||
}
|
||||
SDL_SetRenderLogicalPresentation(renderer, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
|
||||
sprite = CreateTexture(renderer, icon_bmp, icon_bmp_len, &sprite_w, &sprite_h);
|
||||
|
||||
@@ -140,17 +133,16 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Initialize the sprite positions */
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < NUM_SPRITES; ++i) {
|
||||
positions[i].x = (float)(rand() % (WINDOW_WIDTH - sprite_w));
|
||||
positions[i].y = (float)(rand() % (WINDOW_HEIGHT - sprite_h));
|
||||
positions[i].x = (float)SDL_rand(WINDOW_WIDTH - sprite_w);
|
||||
positions[i].y = (float)SDL_rand(WINDOW_HEIGHT - sprite_h);
|
||||
positions[i].w = (float)sprite_w;
|
||||
positions[i].h = (float)sprite_h;
|
||||
velocities[i].x = 0.0f;
|
||||
velocities[i].y = 0.0f;
|
||||
while (!velocities[i].x && !velocities[i].y) {
|
||||
velocities[i].x = (float)((rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
|
||||
velocities[i].y = (float)((rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
|
||||
while (velocities[i].x == 0.f && velocities[i].y == 0.f) {
|
||||
velocities[i].x = (float)(SDL_rand(MAX_SPEED * 2 + 1) - MAX_SPEED);
|
||||
velocities[i].y = (float)(SDL_rand(MAX_SPEED * 2 + 1) - MAX_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user