summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/SDL2/Xcode-iOS/Demos/src
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-11-16 16:26:13 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2016-11-16 16:28:01 +0100
commit47a05778bff9388fc6c479461dd3804c79d7b539 (patch)
treebb3d4dc8df676b8aa478339b3fd0cd305dc4ac4d /3rdparty/SDL2/Xcode-iOS/Demos/src
parente61b392edfbfe5b9d70908c087632da915a3abd8 (diff)
Updated SDL2 to 2.0.5 (nw)
Diffstat (limited to '3rdparty/SDL2/Xcode-iOS/Demos/src')
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/accelerometer.c45
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/common.c20
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/common.h4
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/fireworks.c71
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/happy.c73
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/keyboard.c19
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/mixer.c47
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/rectangles.c91
-rw-r--r--3rdparty/SDL2/Xcode-iOS/Demos/src/touch.c16
9 files changed, 203 insertions, 183 deletions
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/accelerometer.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/accelerometer.c
index 3b7985faa09..e15de3ed4ec 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/accelerometer.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/accelerometer.c
@@ -8,7 +8,6 @@
#include "math.h"
#include "common.h"
-#define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
#define DAMPING 0.5f; /* after bouncing off a wall, damping coefficient determines final speed */
#define FRICTION 0.0008f /* coefficient of acceleration that opposes direction of motion */
#define GRAVITY_CONSTANT 0.004f /* how sensitive the ship is to the accelerometer */
@@ -31,9 +30,10 @@ static SDL_Texture *ship = 0; /* texture for spaceship */
static SDL_Texture *space = 0; /* texture for space (background */
void
-render(SDL_Renderer *renderer, int w, int h)
+render(SDL_Renderer *renderer, int w, int h, double deltaTime)
{
-
+ double deltaMilliseconds = deltaTime * 1000;
+ float speed;
/* get joystick (accelerometer) axis values and normalize them */
float ax = SDL_JoystickGetAxis(accelerometer, 0);
@@ -53,12 +53,12 @@ render(SDL_Renderer *renderer, int w, int h)
*/
shipData.vx +=
ax * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT *
- MILLESECONDS_PER_FRAME;
+ deltaMilliseconds;
shipData.vy +=
ay * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT *
- MILLESECONDS_PER_FRAME;
+ deltaMilliseconds;
- float speed = sqrt(shipData.vx * shipData.vx + shipData.vy * shipData.vy);
+ speed = sqrt(shipData.vx * shipData.vx + shipData.vy * shipData.vy);
if (speed > 0) {
/* compensate for friction */
@@ -66,10 +66,10 @@ render(SDL_Renderer *renderer, int w, int h)
float diry = shipData.vy / speed; /* normalized y velocity */
/* update velocity due to friction */
- if (speed - FRICTION * MILLESECONDS_PER_FRAME > 0) {
+ if (speed - FRICTION * deltaMilliseconds > 0) {
/* apply friction */
- shipData.vx -= dirx * FRICTION * MILLESECONDS_PER_FRAME;
- shipData.vy -= diry * FRICTION * MILLESECONDS_PER_FRAME;
+ shipData.vx -= dirx * FRICTION * deltaMilliseconds;
+ shipData.vy -= diry * FRICTION * deltaMilliseconds;
} else {
/* applying friction would MORE than stop the ship, so just stop the ship */
shipData.vx = 0.0f;
@@ -78,8 +78,8 @@ render(SDL_Renderer *renderer, int w, int h)
}
/* update ship location */
- shipData.x += shipData.vx * MILLESECONDS_PER_FRAME;
- shipData.y += shipData.vy * MILLESECONDS_PER_FRAME;
+ shipData.x += shipData.vx * deltaMilliseconds;
+ shipData.y += shipData.vy * deltaMilliseconds;
if (shipData.x > maxx) {
shipData.x = maxx;
@@ -160,9 +160,6 @@ main(int argc, char *argv[])
SDL_Window *window; /* main window */
SDL_Renderer *renderer;
- Uint32 startFrame; /* time frame began to process */
- Uint32 endFrame; /* time frame ended processing */
- Sint32 delay; /* time to pause waiting to draw next frame */
int done; /* should we clean up and exit? */
int w, h;
@@ -172,12 +169,11 @@ main(int argc, char *argv[])
}
/* create main window and renderer */
- window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
- SDL_WINDOW_OPENGL |
- SDL_WINDOW_FULLSCREEN);
+ window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_ALLOW_HIGHDPI);
renderer = SDL_CreateRenderer(window, 0, 0);
SDL_GetWindowSize(window, &w, &h);
+ SDL_RenderSetLogicalSize(renderer, w, h);
/* print out some info about joysticks and try to open accelerometer for use */
printf("There are %d joysticks available\n", SDL_NumJoysticks());
@@ -207,24 +203,15 @@ main(int argc, char *argv[])
done = 0;
/* enter main loop */
while (!done) {
- startFrame = SDL_GetTicks();
+ double deltaTime = updateDeltaTime();
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
}
- render(renderer, w, h);
- endFrame = SDL_GetTicks();
-
- /* figure out how much time we have left, and then sleep */
- delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
- if (delay < 0) {
- delay = 0;
- } else if (delay > MILLESECONDS_PER_FRAME) {
- delay = MILLESECONDS_PER_FRAME;
- }
- SDL_Delay(delay);
+ render(renderer, w, h, deltaTime);
+ SDL_Delay(1);
}
/* delete textures */
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/common.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/common.c
index b2d96345669..0a1485ae926 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/common.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/common.c
@@ -32,5 +32,25 @@ void
fatalError(const char *string)
{
printf("%s: %s\n", string, SDL_GetError());
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, string, SDL_GetError(), NULL);
exit(1);
}
+
+static Uint64 prevTime = 0;
+
+double
+updateDeltaTime()
+{
+ Uint64 curTime;
+ double deltaTime;
+
+ if (prevTime == 0) {
+ prevTime = SDL_GetPerformanceCounter();
+ }
+
+ curTime = SDL_GetPerformanceCounter();
+ deltaTime = (double) (curTime - prevTime) / (double) SDL_GetPerformanceFrequency();
+ prevTime = curTime;
+
+ return deltaTime;
+}
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/common.h b/3rdparty/SDL2/Xcode-iOS/Demos/src/common.h
index 3e0d94ecf20..96b2c964a0f 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/common.h
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/common.h
@@ -4,9 +4,7 @@
* use however you want
*/
-#define SCREEN_WIDTH 320
-#define SCREEN_HEIGHT 480
-
extern int randomInt(int min, int max);
extern float randomFloat(float min, float max);
extern void fatalError(const char *string);
+extern double updateDeltaTime();
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/fireworks.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/fireworks.c
index a5beada9136..dbbd738113c 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/fireworks.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/fireworks.c
@@ -10,13 +10,13 @@
#include <math.h>
#include <time.h>
-#define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
#define ACCEL 0.0001f /* acceleration due to gravity, units in pixels per millesecond squared */
#define WIND_RESISTANCE 0.00005f /* acceleration per unit velocity due to wind resistance */
#define MAX_PARTICLES 2000 /* maximum number of particles displayed at once */
static GLuint particleTextureID; /* OpenGL particle texture id */
static SDL_bool pointSizeExtensionSupported; /* is GL_OES_point_size_array supported ? */
+static float pointSizeScale;
/*
used to describe what type of particle a given struct particle is.
emitter - this particle flies up, shooting off trail particles, then finally explodes into dust particles.
@@ -55,7 +55,7 @@ void initializeParticles(void);
void initializeTexture();
int nextPowerOfTwo(int x);
void drawParticles();
-void stepParticles(void);
+void stepParticles(double deltaTime);
/* helper function (used in texture loading)
returns next power of two greater than or equal to x
@@ -71,11 +71,12 @@ nextPowerOfTwo(int x)
}
/*
- steps each active particle by timestep MILLESECONDS_PER_FRAME
+ steps each active particle by timestep deltaTime
*/
void
-stepParticles(void)
+stepParticles(double deltaTime)
{
+ float deltaMilliseconds = deltaTime * 1000;
int i;
struct particle *slot = particles;
struct particle *curr = particles;
@@ -93,10 +94,10 @@ stepParticles(void)
curr->isActive = 0;
/* step velocity, then step position */
- curr->yvel += ACCEL * MILLESECONDS_PER_FRAME;
+ curr->yvel += ACCEL * deltaMilliseconds;
curr->xvel += 0.0f;
- curr->y += curr->yvel * MILLESECONDS_PER_FRAME;
- curr->x += curr->xvel * MILLESECONDS_PER_FRAME;
+ curr->y += curr->yvel * deltaMilliseconds;
+ curr->x += curr->xvel * deltaMilliseconds;
/* particle behavior */
if (curr->type == emitter) {
@@ -111,29 +112,29 @@ stepParticles(void)
sqrt(curr->xvel * curr->xvel + curr->yvel * curr->yvel);
/* if wind resistance is not powerful enough to stop us completely,
then apply winde resistance, otherwise just stop us completely */
- if (WIND_RESISTANCE * MILLESECONDS_PER_FRAME < speed) {
+ if (WIND_RESISTANCE * deltaMilliseconds < speed) {
float normx = curr->xvel / speed;
float normy = curr->yvel / speed;
curr->xvel -=
- normx * WIND_RESISTANCE * MILLESECONDS_PER_FRAME;
+ normx * WIND_RESISTANCE * deltaMilliseconds;
curr->yvel -=
- normy * WIND_RESISTANCE * MILLESECONDS_PER_FRAME;
+ normy * WIND_RESISTANCE * deltaMilliseconds;
} else {
curr->xvel = curr->yvel = 0; /* stop particle */
}
- if (curr->color[3] <= MILLESECONDS_PER_FRAME * 0.1275f) {
+ if (curr->color[3] <= deltaMilliseconds * 0.1275f) {
/* if this next step will cause us to fade out completely
then just mark for deletion */
curr->isActive = 0;
} else {
/* otherwise, let's fade a bit more */
- curr->color[3] -= MILLESECONDS_PER_FRAME * 0.1275f;
+ curr->color[3] -= deltaMilliseconds * 0.1275f;
}
/* if we're a dust particle, shrink our size */
if (curr->type == dust)
- curr->size -= MILLESECONDS_PER_FRAME * 0.010f;
+ curr->size -= deltaMilliseconds * 0.010f;
}
@@ -147,7 +148,7 @@ stepParticles(void)
/* the number of active particles is computed as the difference between
old number of active particles, where slot points, and the
new size of the array, where particles points */
- num_active_particles = slot - particles;
+ num_active_particles = (int) (slot - particles);
}
/*
@@ -206,7 +207,7 @@ explodeEmitter(struct particle *emitter)
p->y = emitter->y + emitter->yvel;
p->isActive = 1;
p->type = dust;
- p->size = 15;
+ p->size = 15 * pointSizeScale;
/* inherit emitter's color */
p->color[0] = emitter->color[0];
p->color[1] = emitter->color[1];
@@ -244,7 +245,7 @@ spawnTrailFromEmitter(struct particle *emitter)
p->color[3] = (0.7f) * 255;
/* set other attributes */
- p->size = 10;
+ p->size = 10 * pointSizeScale;
p->type = trail;
p->isActive = 1;
@@ -298,7 +299,7 @@ spawnEmitterParticle(GLfloat x, GLfloat y)
p->xvel = 0;
p->yvel = -sqrt(2 * ACCEL * (screen_h - y));
/* set other attributes */
- p->size = 10;
+ p->size = 10 * pointSizeScale;
p->type = emitter;
p->isActive = 1;
/* our array has expanded at the end */
@@ -363,7 +364,7 @@ main(int argc, char *argv[])
{
SDL_Window *window; /* main window */
SDL_GLContext context;
- int w, h;
+ int drawableW, drawableH;
Uint32 startFrame; /* time frame began to process */
Uint32 endFrame; /* time frame ended processing */
Uint32 delay; /* time to pause waiting to draw next frame */
@@ -391,11 +392,19 @@ main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
/* create main window and renderer */
- window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
- SDL_WINDOW_OPENGL |
- SDL_WINDOW_BORDERLESS);
+ window = SDL_CreateWindow(NULL, 0, 0, 320, 480,
+ SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALLOW_HIGHDPI);
context = SDL_GL_CreateContext(window);
+ /* The window size and drawable size may be different when highdpi is enabled,
+ * due to the increased pixel density of the drawable. */
+ SDL_GetWindowSize(window, &screen_w, &screen_h);
+ SDL_GL_GetDrawableSize(window, &drawableW, &drawableH);
+
+ /* In OpenGL, point sizes are always in pixels. We don't want them looking
+ * tiny on a retina screen. */
+ pointSizeScale = (float) drawableH / (float) screen_h;
+
/* load the particle texture */
initializeTexture();
@@ -412,8 +421,7 @@ main(int argc, char *argv[])
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- SDL_GetWindowSize(window, &screen_w, &screen_h);
- glViewport(0, 0, screen_w, screen_h);
+ glViewport(0, 0, drawableW, drawableH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -436,14 +444,14 @@ main(int argc, char *argv[])
glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
} else {
/* if extension not available then all particles have size 10 */
- glPointSize(10);
+ glPointSize(10 * pointSizeScale);
}
done = 0;
/* enter main loop */
while (!done) {
- startFrame = SDL_GetTicks();
SDL_Event event;
+ double deltaTime = updateDeltaTime();
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
@@ -454,19 +462,10 @@ main(int argc, char *argv[])
spawnEmitterParticle(x, y);
}
}
- stepParticles();
+ stepParticles(deltaTime);
drawParticles();
SDL_GL_SwapWindow(window);
- endFrame = SDL_GetTicks();
-
- /* figure out how much time we have left, and then sleep */
- delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
- if (delay > MILLESECONDS_PER_FRAME) {
- delay = MILLESECONDS_PER_FRAME;
- }
- if (delay > 0) {
- SDL_Delay(delay);
- }
+ SDL_Delay(1);
}
/* delete textures */
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/happy.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/happy.c
index ce661d95875..658a65f01bd 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/happy.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/happy.c
@@ -8,8 +8,7 @@
#include "common.h"
#define NUM_HAPPY_FACES 100 /* number of faces to draw */
-#define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
-#define HAPPY_FACE_SIZE 32 /* width and height of happyface (pixels) */
+#define HAPPY_FACE_SIZE 32 /* width and height of happyface */
static SDL_Texture *texture = 0; /* reference to texture holding happyface */
@@ -24,30 +23,37 @@ static struct
units of velocity are pixels per millesecond
*/
void
-initializeHappyFaces()
+initializeHappyFaces(SDL_Renderer *renderer)
{
int i;
+ int w;
+ int h;
+ SDL_RenderGetLogicalSize(renderer, &w, &h);
+
for (i = 0; i < NUM_HAPPY_FACES; i++) {
- faces[i].x = randomFloat(0.0f, SCREEN_WIDTH - HAPPY_FACE_SIZE);
- faces[i].y = randomFloat(0.0f, SCREEN_HEIGHT - HAPPY_FACE_SIZE);
- faces[i].xvel = randomFloat(-0.1f, 0.1f);
- faces[i].yvel = randomFloat(-0.1f, 0.1f);
+ faces[i].x = randomFloat(0.0f, w - HAPPY_FACE_SIZE);
+ faces[i].y = randomFloat(0.0f, h - HAPPY_FACE_SIZE);
+ faces[i].xvel = randomFloat(-60.0f, 60.0f);
+ faces[i].yvel = randomFloat(-60.0f, 60.0f);
}
}
void
-render(SDL_Renderer *renderer)
+render(SDL_Renderer *renderer, double deltaTime)
{
-
int i;
SDL_Rect srcRect;
SDL_Rect dstRect;
+ int w;
+ int h;
+
+ SDL_RenderGetLogicalSize(renderer, &w, &h);
/* setup boundaries for happyface bouncing */
- Uint16 maxx = SCREEN_WIDTH - HAPPY_FACE_SIZE;
- Uint16 maxy = SCREEN_HEIGHT - HAPPY_FACE_SIZE;
- Uint16 minx = 0;
- Uint16 miny = 0;
+ int maxx = w - HAPPY_FACE_SIZE;
+ int maxy = h - HAPPY_FACE_SIZE;
+ int minx = 0;
+ int miny = 0;
/* setup rects for drawing */
srcRect.x = 0;
@@ -68,8 +74,8 @@ render(SDL_Renderer *renderer)
- draw
*/
for (i = 0; i < NUM_HAPPY_FACES; i++) {
- faces[i].x += faces[i].xvel * MILLESECONDS_PER_FRAME;
- faces[i].y += faces[i].yvel * MILLESECONDS_PER_FRAME;
+ faces[i].x += faces[i].xvel * deltaTime;
+ faces[i].y += faces[i].yvel * deltaTime;
if (faces[i].x > maxx) {
faces[i].x = maxx;
faces[i].xvel = -faces[i].xvel;
@@ -123,48 +129,45 @@ initializeTexture(SDL_Renderer *renderer)
int
main(int argc, char *argv[])
{
-
SDL_Window *window;
SDL_Renderer *renderer;
- Uint32 startFrame;
- Uint32 endFrame;
- Uint32 delay;
int done;
+ int width;
+ int height;
/* initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fatalError("Could not initialize SDL");
}
- window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
- SDL_WINDOW_OPENGL |
- SDL_WINDOW_BORDERLESS);
+
+ /* The specified window size doesn't matter - except for its aspect ratio,
+ * which determines whether the window is in portrait or landscape on iOS
+ * (if SDL_WINDOW_RESIZABLE isn't specified). */
+ window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_ALLOW_HIGHDPI);
renderer = SDL_CreateRenderer(window, -1, 0);
+ SDL_GetWindowSize(window, &width, &height);
+ SDL_RenderSetLogicalSize(renderer, width, height);
+
initializeTexture(renderer);
- initializeHappyFaces();
+ initializeHappyFaces(renderer);
+
/* main loop */
done = 0;
while (!done) {
- startFrame = SDL_GetTicks();
SDL_Event event;
+ double deltaTime = updateDeltaTime();
+
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
}
- render(renderer);
- endFrame = SDL_GetTicks();
-
- /* figure out how much time we have left, and then sleep */
- delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
- if (delay < 0) {
- delay = 0;
- } else if (delay > MILLESECONDS_PER_FRAME) {
- delay = MILLESECONDS_PER_FRAME;
- }
- SDL_Delay(delay);
+
+ render(renderer, deltaTime);
+ SDL_Delay(1);
}
/* cleanup */
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/keyboard.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/keyboard.c
index 4fb45b94ae1..1932ad4a96b 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/keyboard.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/keyboard.c
@@ -4,8 +4,8 @@
* use however you want
*/
-#import "SDL.h"
-#import "common.h"
+#include "SDL.h"
+#include "common.h"
#define GLYPH_SIZE_IMAGE 16 /* size of glyphs (characters) in the bitmap font file */
#define GLYPH_SIZE_SCREEN 32 /* size of glyphs (characters) as shown on the screen */
@@ -132,10 +132,13 @@ keyToIndex(SDL_Keysym key)
void
getPositionForCharNumber(int n, int *x, int *y)
{
+ int renderW, renderH;
+ SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
+
int x_padding = 16; /* padding space on left and right side of screen */
int y_padding = 32; /* padding space at top of screen */
/* figure out the number of characters that can fit horizontally across the screen */
- int max_x_chars = (SCREEN_WIDTH - 2 * x_padding) / GLYPH_SIZE_SCREEN;
+ int max_x_chars = (renderW - 2 * x_padding) / GLYPH_SIZE_SCREEN;
int line_separation = 5; /* pixels between each line */
*x = (n % max_x_chars) * GLYPH_SIZE_SCREEN + x_padding;
*y = (n / max_x_chars) * (GLYPH_SIZE_SCREEN + line_separation) +
@@ -228,21 +231,25 @@ loadFont(void)
int
main(int argc, char *argv[])
{
-
int index; /* index of last key we pushed in the bitmap font */
SDL_Window *window;
SDL_Event event; /* last event received */
SDL_Keymod mod; /* key modifiers of last key we pushed */
SDL_Scancode scancode; /* scancode of last key we pushed */
+ int width;
+ int height;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Error initializing SDL: %s", SDL_GetError());
}
/* create window */
- window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
+ window = SDL_CreateWindow("iPhone keyboard test", 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
/* create renderer */
renderer = SDL_CreateRenderer(window, -1, 0);
+ SDL_GetWindowSize(window, &width, &height);
+ SDL_RenderSetLogicalSize(renderer, width, height);
+
/* load up our font */
loadFont();
@@ -253,7 +260,7 @@ main(int argc, char *argv[])
int done = 0;
/* loop till we get SDL_Quit */
- while (SDL_WaitEvent(&event)) {
+ while (!done && SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
done = 1;
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/mixer.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/mixer.c
index bd0cfb1dffc..81f0166f85a 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/mixer.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/mixer.c
@@ -4,12 +4,11 @@
* use however you want
*/
-#import "SDL.h"
-#import "common.h"
+#include "SDL.h"
+#include "common.h"
#define NUM_CHANNELS 8 /* max number of sounds we can play at once */
#define NUM_DRUMS 4 /* number of drums in our set */
-#define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
static struct
{
@@ -33,7 +32,7 @@ static struct sound drums[NUM_DRUMS];
void handleMouseButtonDown(SDL_Event * event);
void handleMouseButtonUp(SDL_Event * event);
int playSound(struct sound *);
-void initializeButtons();
+void initializeButtons(SDL_Renderer *);
void audioCallback(void *userdata, Uint8 * stream, int len);
void loadSound(const char *file, struct sound *s);
@@ -52,19 +51,21 @@ struct
/* sets up the buttons (color, position, state) */
void
-initializeButtons()
+initializeButtons(SDL_Renderer *renderer)
{
-
int i;
int spacing = 10; /* gap between drum buttons */
SDL_Rect buttonRect; /* keeps track of where to position drum */
SDL_Color upColor = { 86, 86, 140, 255 }; /* color of drum when not pressed */
SDL_Color downColor = { 191, 191, 221, 255 }; /* color of drum when pressed */
+ int renderW, renderH;
+
+ SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
buttonRect.x = spacing;
buttonRect.y = spacing;
- buttonRect.w = SCREEN_WIDTH - 2 * spacing;
- buttonRect.h = (SCREEN_HEIGHT - (NUM_DRUMS + 1) * spacing) / NUM_DRUMS;
+ buttonRect.w = renderW - 2 * spacing;
+ buttonRect.h = (renderH - (NUM_DRUMS + 1) * spacing) / NUM_DRUMS;
/* setup each button */
for (i = 0; i < NUM_DRUMS; i++) {
@@ -270,23 +271,23 @@ audioCallback(void *userdata, Uint8 * stream, int len)
int
main(int argc, char *argv[])
{
-
int done; /* has user tried to quit ? */
SDL_Window *window; /* main window */
SDL_Renderer *renderer;
SDL_Event event;
- Uint32 startFrame; /* holds when frame started processing */
- Uint32 endFrame; /* holds when frame ended processing */
- Uint32 delay; /* calculated delay, how long should we wait before next frame? */
+ int i;
+ int width;
+ int height;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
fatalError("could not initialize SDL");
}
- window =
- SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
- SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
+ window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALLOW_HIGHDPI);
renderer = SDL_CreateRenderer(window, 0, 0);
+ SDL_GetWindowSize(window, &width, &height);
+ SDL_RenderSetLogicalSize(renderer, width, height);
+
/* initialize the mixer */
SDL_memset(&mixer, 0, sizeof(mixer));
/* setup output format */
@@ -309,12 +310,11 @@ main(int argc, char *argv[])
loadSound("ds_china.wav", &drums[0]);
/* setup positions, colors, and state of buttons */
- initializeButtons();
+ initializeButtons(renderer);
/* enter main loop */
done = 0;
while (!done) {
- startFrame = SDL_GetTicks();
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
@@ -329,20 +329,11 @@ main(int argc, char *argv[])
}
}
render(renderer); /* draw buttons */
- endFrame = SDL_GetTicks();
-
- /* figure out how much time we have left, and then sleep */
- delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
- if (delay < 0) {
- delay = 0;
- } else if (delay > MILLESECONDS_PER_FRAME) {
- delay = MILLESECONDS_PER_FRAME;
- }
- SDL_Delay(delay);
+
+ SDL_Delay(1);
}
/* cleanup code, let's free up those sound buffers */
- int i;
for (i = 0; i < NUM_DRUMS; i++) {
SDL_free(drums[i].buffer);
}
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/rectangles.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/rectangles.c
index 86fce49fe68..10f9f851b3f 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/rectangles.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/rectangles.c
@@ -11,14 +11,18 @@
void
render(SDL_Renderer *renderer)
{
-
Uint8 r, g, b;
+ int renderW;
+ int renderH;
+
+ SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
+
/* Come up with a random rectangle */
SDL_Rect rect;
rect.w = randomInt(64, 128);
rect.h = randomInt(64, 128);
- rect.x = randomInt(0, SCREEN_WIDTH);
- rect.y = randomInt(0, SCREEN_HEIGHT);
+ rect.x = randomInt(0, renderW);
+ rect.y = randomInt(0, renderH);
/* Come up with a random color */
r = randomInt(50, 255);
@@ -31,51 +35,58 @@ render(SDL_Renderer *renderer)
/* update screen */
SDL_RenderPresent(renderer);
-
}
int
main(int argc, char *argv[])
{
- if (SDL_Init(SDL_INIT_VIDEO/* | SDL_INIT_AUDIO */) < 0)
- {
- printf("Unable to initialize SDL");
+
+ SDL_Window *window;
+ SDL_Renderer *renderer;
+ int done;
+ SDL_Event event;
+ int windowW;
+ int windowH;
+
+ /* initialize SDL */
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ fatalError("Could not initialize SDL");
+ }
+
+ /* seed random number generator */
+ srand(time(NULL));
+
+ /* create window and renderer */
+ window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
+ if (window == 0) {
+ fatalError("Could not initialize Window");
}
-
- SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
- int landscape = 1;
- int modes = SDL_GetNumDisplayModes(0);
- int sx = 0, sy = 0;
- for (int i = 0; i < modes; i++)
- {
- SDL_DisplayMode mode;
- SDL_GetDisplayMode(0, i, &mode);
- if (landscape ? mode.w > sx : mode.h > sy)
- {
- sx = mode.w;
- sy = mode.h;
+ renderer = SDL_CreateRenderer(window, -1, 0);
+ if (!renderer) {
+ fatalError("Could not create renderer");
+ }
+
+ SDL_GetWindowSize(window, &windowW, &windowH);
+ SDL_RenderSetLogicalSize(renderer, windowW, windowH);
+
+ /* Fill screen with black */
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_RenderClear(renderer);
+
+ /* Enter render loop, waiting for user to quit */
+ done = 0;
+ while (!done) {
+ while (SDL_PollEvent(&event)) {
+ if (event.type == SDL_QUIT) {
+ done = 1;
+ }
}
+ render(renderer);
+ SDL_Delay(1);
}
-
- printf("picked: %d %d\n", sx, sy);
-
- SDL_Window *_sdl_window = NULL;
- SDL_GLContext _sdl_context = NULL;
-
- _sdl_window = SDL_CreateWindow("fred",
- 0, 0,
- sx, sy,
- SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
-
- SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeLeft LandscapeRight");
-
- int ax = 0, ay = 0;
- SDL_GetWindowSize(_sdl_window, &ax, &ay);
-
- printf("given: %d %d\n", ax, ay);
+
+ /* shutdown SDL */
+ SDL_Quit();
return 0;
}
diff --git a/3rdparty/SDL2/Xcode-iOS/Demos/src/touch.c b/3rdparty/SDL2/Xcode-iOS/Demos/src/touch.c
index c81dcbc223a..32e6cea1125 100644
--- a/3rdparty/SDL2/Xcode-iOS/Demos/src/touch.c
+++ b/3rdparty/SDL2/Xcode-iOS/Demos/src/touch.c
@@ -26,15 +26,17 @@ drawLine(SDL_Renderer *renderer, float startx, float starty, float dx, float dy)
float dx_prime = dx / iterations; /* x-shift per iteration */
float dy_prime = dy / iterations; /* y-shift per iteration */
SDL_Rect dstRect; /* rect to draw brush sprite into */
+ float x;
+ float y;
+ int i;
dstRect.w = BRUSH_SIZE;
dstRect.h = BRUSH_SIZE;
/* setup x and y for the location of the first sprite */
- float x = startx - BRUSH_SIZE / 2.0f;
- float y = starty - BRUSH_SIZE / 2.0f;
+ x = startx - BRUSH_SIZE / 2.0f;
+ y = starty - BRUSH_SIZE / 2.0f;
- int i;
/* draw a series of blots to form the line */
for (i = 0; i < iterations; i++) {
dstRect.x = x;
@@ -80,6 +82,7 @@ main(int argc, char *argv[])
SDL_Window *window; /* main window */
SDL_Renderer *renderer;
int done; /* does user want to quit? */
+ int w, h;
/* initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
@@ -87,11 +90,12 @@ main(int argc, char *argv[])
}
/* create main window and renderer */
- window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
- SDL_WINDOW_OPENGL |
- SDL_WINDOW_BORDERLESS);
+ window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALLOW_HIGHDPI);
renderer = SDL_CreateRenderer(window, 0, 0);
+ SDL_GetWindowSize(window, &w, &h);
+ SDL_RenderSetLogicalSize(renderer, w, h);
+
/* load brush texture */
initializeTexture(renderer);