Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_T…
…exture* for code simplicity and improved performance.
  • Loading branch information
slouken committed Jan 21, 2010
1 parent 563b371 commit c2dcb63
Show file tree
Hide file tree
Showing 73 changed files with 849 additions and 1,063 deletions.
8 changes: 4 additions & 4 deletions README.iphoneos
Expand Up @@ -67,13 +67,13 @@ Notes -- Keyboard

SDL for iPhone contains several additional functions related to keyboard visibility. These functions are not part of the SDL standard API, but are necessary for revealing and hiding the iPhone's virtual onscreen keyboard. You can use them in your own applications by including a copy of the SDL_uikitkeyboard.h header (located in src/video/uikit) in your project.

int SDL_iPhoneKeyboardShow(SDL_WindowID windowID)
int SDL_iPhoneKeyboardShow(SDL_Window * window)
-- reveals the onscreen keyboard. Returns 0 on success and -1 on error.
int SDL_iPhoneKeyboardHide(SDL_WindowID windowID)
int SDL_iPhoneKeyboardHide(SDL_Window * window)
-- hides the onscreen keyboard. Returns 0 on success and -1 on error.
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_WindowID windowID)
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
-- returns whether or not the onscreen keyboard is currently visible.
int SDL_iPhoneKeyboardToggle(SDL_WindowID windowID)
int SDL_iPhoneKeyboardToggle(SDL_Window * window)
-- toggles the visibility of the onscreen keyboard. Returns 0 on success and -1 on error.

==============================================================================
Expand Down
28 changes: 14 additions & 14 deletions Xcode-iPhoneOS/Demos/src/accelerometer.c
Expand Up @@ -27,8 +27,8 @@ static struct
SDL_Rect rect; /* (drawn) position and size of ship */
} ship;

static SDL_TextureID shipID = 0; /* texture for spaceship */
static SDL_TextureID spaceID = 0; /* texture for space (background */
static SDL_Texture *ship = 0; /* texture for spaceship */
static SDL_Texture *space = 0; /* texture for space (background */

void
render(void)
Expand Down Expand Up @@ -97,13 +97,13 @@ render(void)
}

/* draw the background */
SDL_RenderCopy(spaceID, NULL, NULL);
SDL_RenderCopy(space, NULL, NULL);

/* draw the ship */
ship.rect.x = ship.x;
ship.rect.y = ship.y;

SDL_RenderCopy(shipID, NULL, &ship.rect);
SDL_RenderCopy(ship, NULL, &ship.rect);

/* update screen */
SDL_RenderPresent();
Expand Down Expand Up @@ -141,11 +141,11 @@ initializeTextures()
SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);

/* create ship texture from surface */
shipID = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
if (shipID == 0) {
ship = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
if (ship == 0) {
fatalError("could not create ship texture");
}
SDL_SetTextureBlendMode(shipID, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);

/* set the width and height of the ship from the surface dimensions */
ship.rect.w = bmp_surface->w;
Expand All @@ -160,8 +160,8 @@ initializeTextures()
fatalError("could not load space.bmp");
}
/* create space texture from surface */
spaceID = SDL_CreateTextureFromSurface(format, bmp_surface);
if (spaceID == 0) {
space = SDL_CreateTextureFromSurface(format, bmp_surface);
if (space == 0) {
fatalError("could not create space texture");
}
SDL_FreeSurface(bmp_surface);
Expand All @@ -174,7 +174,7 @@ int
main(int argc, char *argv[])
{

SDL_WindowID windowID; /* ID of main window */
SDL_Window *window; /* main window */
Uint32 startFrame; /* time frame began to process */
Uint32 endFrame; /* time frame ended processing */
Uint32 delay; /* time to pause waiting to draw next frame */
Expand All @@ -186,10 +186,10 @@ main(int argc, char *argv[])
}

/* create main window and renderer */
windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
SDL_WINDOW_BORDERLESS);
SDL_CreateRenderer(windowID, 0, 0);
SDL_CreateRenderer(window, 0, 0);

/* print out some info about joysticks and try to open accelerometer for use */
printf("There are %d joysticks available\n", SDL_NumJoysticks());
Expand Down Expand Up @@ -240,8 +240,8 @@ main(int argc, char *argv[])
}

/* delete textures */
SDL_DestroyTexture(shipID);
SDL_DestroyTexture(spaceID);
SDL_DestroyTexture(ship);
SDL_DestroyTexture(space);

/* shutdown SDL */
SDL_Quit();
Expand Down
7 changes: 3 additions & 4 deletions Xcode-iPhoneOS/Demos/src/fireworks.c
Expand Up @@ -363,8 +363,7 @@ initializeTexture()
int
main(int argc, char *argv[])
{

SDL_WindowID windowID; /* ID of main window */
SDL_Window *window; /* main window */
Uint32 startFrame; /* time frame began to process */
Uint32 endFrame; /* time frame ended processing */
Uint32 delay; /* time to pause waiting to draw next frame */
Expand All @@ -389,10 +388,10 @@ main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

/* create main window and renderer */
windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
SDL_WINDOW_BORDERLESS);
SDL_CreateRenderer(windowID, 0, 0);
SDL_CreateRenderer(window, 0, 0);

/* load the particle texture */
initializeTexture();
Expand Down
18 changes: 9 additions & 9 deletions Xcode-iPhoneOS/Demos/src/happy.c
Expand Up @@ -11,7 +11,7 @@
#define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
#define HAPPY_FACE_SIZE 32 /* width and height of happyface (pixels) */

static SDL_TextureID texture_id = 0; /* reference to texture holding happyface */
static SDL_Texture *texture = 0; /* reference to texture holding happyface */

static struct
{
Expand Down Expand Up @@ -86,7 +86,7 @@ render(void)
}
dstRect.x = faces[i].x;
dstRect.y = faces[i].y;
SDL_RenderCopy(texture_id, &srcRect, &dstRect);
SDL_RenderCopy(texture, &srcRect, &dstRect);
}
/* update screen */
SDL_RenderPresent();
Expand Down Expand Up @@ -124,11 +124,11 @@ initializeTexture()
SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);

/* convert RGBA surface to texture */
texture_id = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
if (texture_id == 0) {
texture = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
if (texture == 0) {
fatalError("could not create texture");
}
SDL_SetTextureBlendMode(texture_id, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);

/* free up allocated memory */
SDL_FreeSurface(bmp_surface_rgba);
Expand All @@ -139,7 +139,7 @@ int
main(int argc, char *argv[])
{

SDL_WindowID windowID;
SDL_Window *window;
Uint32 startFrame;
Uint32 endFrame;
Uint32 delay;
Expand All @@ -149,11 +149,11 @@ main(int argc, char *argv[])
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fatalError("Could not initialize SDL");
}
windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
SDL_WINDOW_BORDERLESS);

SDL_CreateRenderer(windowID, -1, 0);
SDL_CreateRenderer(window, -1, 0);

initializeTexture();
initializeHappyFaces();
Expand Down Expand Up @@ -182,7 +182,7 @@ main(int argc, char *argv[])
}

/* cleanup */
SDL_DestroyTexture(texture_id);
SDL_DestroyTexture(texture);
/* shutdown SDL */
SDL_Quit();

Expand Down
37 changes: 18 additions & 19 deletions Xcode-iPhoneOS/Demos/src/keyboard.c
Expand Up @@ -10,14 +10,14 @@
#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 */

static SDL_TextureID textureID; /* texture where we'll hold our font */
static SDL_Texture *texture; /* texture where we'll hold our font */

/* iPhone SDL addition keyboard related function definitions */
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_WindowID windowID);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_WindowID windowID);
extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_WindowID
windowID);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_WindowID windowID);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window);
extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window *
window);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window);

/* function declarations */
void cleanup(void);
Expand Down Expand Up @@ -157,7 +157,7 @@ drawIndex(int index)
{ GLYPH_SIZE_IMAGE * index, 0, GLYPH_SIZE_IMAGE, GLYPH_SIZE_IMAGE };
SDL_Rect dstRect = { x, y, GLYPH_SIZE_SCREEN, GLYPH_SIZE_SCREEN };
drawBlank(x, y);
SDL_RenderCopy(textureID, &srcRect, &dstRect);
SDL_RenderCopy(texture, &srcRect, &dstRect);
}

/* draws the cursor icon at the current end position of the text */
Expand Down Expand Up @@ -194,8 +194,8 @@ backspace(void)
}
}

/* this function loads our font into an SDL_Texture and returns the SDL_TextureID */
SDL_TextureID
/* this function loads our font into an SDL_Texture and returns the SDL_Texture */
SDL_Texture*
loadFont(void)
{

Expand All @@ -218,17 +218,17 @@ loadFont(void)
Bmask, Amask);
SDL_BlitSurface(surface, NULL, converted, NULL);
/* create our texture */
textureID =
texture =
SDL_CreateTextureFromSurface(SDL_PIXELFORMAT_ABGR8888, converted);
if (textureID == 0) {
if (texture == 0) {
printf("texture creation failed: %s\n", SDL_GetError());
} else {
/* set blend mode for our texture */
SDL_SetTextureBlendMode(textureID, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
}
SDL_FreeSurface(surface);
SDL_FreeSurface(converted);
return textureID;
return texture;
}
}

Expand All @@ -237,6 +237,7 @@ 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 */
SDLMod mod; /* key modifiers of last key we pushed */
SDL_scancode scancode; /* scancode of last key we pushed */
Expand All @@ -245,11 +246,9 @@ main(int argc, char *argv[])
printf("Error initializing SDL: %s", SDL_GetError());
}
/* create window */
SDL_WindowID windowID =
SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
/* create renderer */
SDL_CreateRenderer(windowID, 0, 0);
SDL_CreateRenderer(window, 0, 0);

/* load up our font */
loadFont();
Expand Down Expand Up @@ -301,7 +300,7 @@ main(int argc, char *argv[])
/* mouse up toggles onscreen keyboard visibility
this function is available ONLY on iPhone OS
*/
SDL_iPhoneKeyboardToggle(windowID);
SDL_iPhoneKeyboardToggle(window);
break;
#endif
}
Expand All @@ -314,6 +313,6 @@ main(int argc, char *argv[])
void
cleanup(void)
{
SDL_DestroyTexture(textureID);
SDL_DestroyTexture(texture);
SDL_Quit();
}
6 changes: 3 additions & 3 deletions Xcode-iPhoneOS/Demos/src/mixer.c
Expand Up @@ -274,7 +274,7 @@ main(int argc, char *argv[])
{

int done; /* has user tried to quit ? */
SDL_WindowID windowID; /* our main window */
SDL_Window *window; /* main window */
SDL_Event event;
Uint32 startFrame; /* holds when frame started processing */
Uint32 endFrame; /* holds when frame ended processing */
Expand All @@ -283,10 +283,10 @@ main(int argc, char *argv[])
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
fatalError("could not initialize SDL");
}
windowID =
window =
SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
SDL_CreateRenderer(windowID, 0, 0);
SDL_CreateRenderer(window, 0, 0);

/* initialize the mixer */
SDL_memset(&mixer, 0, sizeof(mixer));
Expand Down
8 changes: 4 additions & 4 deletions Xcode-iPhoneOS/Demos/src/rectangles.c
Expand Up @@ -38,7 +38,7 @@ int
main(int argc, char *argv[])
{

SDL_WindowID windowID;
SDL_Window *window;
int done;
SDL_Event event;

Expand All @@ -51,13 +51,13 @@ main(int argc, char *argv[])
srand(time(NULL));

/* create window and renderer */
windowID =
window =
SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);
if (windowID == 0) {
if (window == 0) {
fatalError("Could not initialize Window");
}
if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
if (SDL_CreateRenderer(window, -1, 0) != 0) {
fatalError("Could not create renderer");
}

Expand Down

0 comments on commit c2dcb63

Please sign in to comment.