Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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 c2dcb634911140bf681827b06afd93bdb488d6eb
Showing with 849 additions and 1,063 deletions.
  1. +4 −4 README.iphoneos
  2. +14 −14 Xcode-iPhoneOS/Demos/src/accelerometer.c
  3. +3 −4 Xcode-iPhoneOS/Demos/src/fireworks.c
  4. +9 −9 Xcode-iPhoneOS/Demos/src/happy.c
  5. +18 −19 Xcode-iPhoneOS/Demos/src/keyboard.c
  6. +3 −3 Xcode-iPhoneOS/Demos/src/mixer.c
  7. +4 −4 Xcode-iPhoneOS/Demos/src/rectangles.c
  8. +10 −10 Xcode-iPhoneOS/Demos/src/touch.c
  9. +2 −0 include/SDL_compat.h
  10. +8 −8 include/SDL_events.h
  11. +3 −3 include/SDL_mouse.h
  12. +1 −1 include/SDL_syswm.h
  13. +84 −72 include/SDL_video.h
  14. +1 −1 src/SDL_assert.c
  15. +18 −18 src/SDL_compat.c
  16. +5 −5 src/events/SDL_keyboard.c
  17. +2 −2 src/events/SDL_keyboard_c.h
  18. +12 −11 src/events/SDL_mouse.c
  19. +3 −3 src/events/SDL_mouse_c.h
  20. +2 −4 src/events/SDL_windowevents.c
  21. +1 −1 src/events/SDL_windowevents_c.h
  22. +2 −2 src/video/SDL_gamma.c
  23. +8 −8 src/video/SDL_renderer_gl.c
  24. +2 −2 src/video/SDL_renderer_gles.c
  25. +6 −6 src/video/SDL_renderer_sw.c
  26. +16 −19 src/video/SDL_sysvideo.h
  27. +233 −427 src/video/SDL_video.c
  28. +3 −3 src/video/cocoa/SDL_cocoamouse.m
  29. +1 −1 src/video/cocoa/SDL_cocoaopengl.m
  30. +2 −2 src/video/cocoa/SDL_cocoawindow.h
  31. +18 −18 src/video/cocoa/SDL_cocoawindow.m
  32. +1 −1 src/video/directfb/SDL_DirectFB_WM.c
  33. +21 −21 src/video/directfb/SDL_DirectFB_events.c
  34. +7 −9 src/video/directfb/SDL_DirectFB_mouse.c
  35. +4 −4 src/video/directfb/SDL_DirectFB_render.c
  36. +1 −1 src/video/directfb/SDL_DirectFB_window.c
  37. +1 −1 src/video/directfb/SDL_DirectFB_window.h
  38. +9 −9 src/video/dummy/SDL_nullrender.c
  39. +6 −8 src/video/nds/SDL_ndsrender.c
  40. +2 −2 src/video/pandora/SDL_pandora.c
  41. +22 −22 src/video/photon/SDL_photon.c
  42. +12 −20 src/video/photon/SDL_photon_input.c
  43. +5 −5 src/video/photon/SDL_photon_render.c
  44. +4 −4 src/video/ps3/SDL_ps3render.c
  45. +6 −8 src/video/qnxgf/SDL_gf_input.c
  46. +4 −4 src/video/qnxgf/SDL_gf_render.c
  47. +5 −5 src/video/qnxgf/SDL_qnxgf.c
  48. +4 −4 src/video/uikit/SDL_uikitappdelegate.h
  49. +6 −6 src/video/uikit/SDL_uikitappdelegate.m
  50. +4 −5 src/video/uikit/SDL_uikitkeyboard.h
  51. +11 −15 src/video/uikit/SDL_uikitview.m
  52. +1 −1 src/video/uikit/SDL_uikitwindow.h
  53. +53 −54 src/video/uikit/SDL_uikitwindow.m
  54. +7 −7 src/video/win32/SDL_ceddrawrender.c
  55. +8 −8 src/video/win32/SDL_d3drender.c
  56. +2 −2 src/video/win32/SDL_gapirender.c
  57. +12 −12 src/video/win32/SDL_gdirender.c
  58. +19 −22 src/video/win32/SDL_win32events.c
  59. +5 −5 src/video/win32/SDL_win32window.c
  60. +1 −1 src/video/win32/SDL_win32window.h
  61. +11 −15 src/video/x11/SDL_x11events.c
  62. +5 −6 src/video/x11/SDL_x11opengl.c
  63. +22 −22 src/video/x11/SDL_x11render.c
  64. +25 −25 src/video/x11/SDL_x11window.c
  65. +2 −2 src/video/x11/SDL_x11window.h
  66. +18 −18 test/automated/render/render.c
  67. +1 −1 test/common.c
  68. +1 −1 test/common.h
  69. +4 −4 test/testdraw2.c
  70. +6 −6 test/testintersections.c
  71. +6 −6 test/testnative.c
  72. +4 −4 test/testsprite2.c
  73. +3 −3 test/testspriteminimal.c
@@ -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.

==============================================================================
@@ -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)
@@ -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();
@@ -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;
@@ -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);
@@ -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 */
@@ -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());
@@ -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();
@@ -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 */
@@ -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();
@@ -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
{
@@ -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();
@@ -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);
@@ -139,7 +139,7 @@ int
main(int argc, char *argv[])
{

SDL_WindowID windowID;
SDL_Window *window;
Uint32 startFrame;
Uint32 endFrame;
Uint32 delay;
@@ -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();
@@ -182,7 +182,7 @@ main(int argc, char *argv[])
}

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

@@ -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);
@@ -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 */
@@ -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)
{

@@ -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;
}
}

@@ -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 */
@@ -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();
@@ -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
}
@@ -314,6 +313,6 @@ main(int argc, char *argv[])
void
cleanup(void)
{
SDL_DestroyTexture(textureID);
SDL_DestroyTexture(texture);
SDL_Quit();
}
@@ -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 */
@@ -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));
@@ -38,7 +38,7 @@ int
main(int argc, char *argv[])
{

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

@@ -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");
}

0 comments on commit c2dcb63

Please sign in to comment.