Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404438
This commit is contained in:
Sam Lantinga 2010-01-21 06:21:52 +00:00
parent d7496843fc
commit a0e019f786
73 changed files with 854 additions and 1068 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

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

View file

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

View file

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

View file

@ -11,7 +11,7 @@
#define BRUSH_SIZE 32 /* width and height of the brush */
#define PIXELS_PER_ITERATION 5 /* number of pixels between brush blots when forming a line */
static SDL_TextureID brushID = 0; /* texture for the brush */
static SDL_Texture *brush = 0; /* texture for the brush */
/*
draws a line from (startx, starty) to (startx + dx, starty + dy)
@ -43,7 +43,7 @@ drawLine(float startx, float starty, float dx, float dy)
x += dx_prime;
y += dy_prime;
/* draw brush blot */
SDL_RenderCopy(brushID, NULL, &dstRect);
SDL_RenderCopy(brush, NULL, &dstRect);
}
}
@ -58,16 +58,16 @@ initializeTexture()
if (bmp_surface == NULL) {
fatalError("could not load stroke.bmp");
}
brushID =
brush =
SDL_CreateTextureFromSurface(SDL_PIXELFORMAT_ABGR8888, bmp_surface);
SDL_FreeSurface(bmp_surface);
if (brushID == 0) {
if (brush == 0) {
fatalError("could not create brush texture");
}
/* additive blending -- laying strokes on top of eachother makes them brighter */
SDL_SetTextureBlendMode(brushID, SDL_BLENDMODE_ADD);
SDL_SetTextureBlendMode(brush, SDL_BLENDMODE_ADD);
/* set brush color (red) */
SDL_SetTextureColorMod(brushID, 255, 100, 100);
SDL_SetTextureColorMod(brush, 255, 100, 100);
}
int
@ -77,7 +77,7 @@ main(int argc, char *argv[])
int x, y, dx, dy; /* mouse location */
Uint8 state; /* mouse (touch) state */
SDL_Event event;
SDL_WindowID windowID; /* main window */
SDL_Window *window; /* main window */
int done; /* does user want to quit? */
/* initialize SDL */
@ -86,10 +86,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);
/*load brush texture */
initializeTexture();
@ -118,7 +118,7 @@ main(int argc, char *argv[])
}
/* cleanup */
SDL_DestroyTexture(brushID);
SDL_DestroyTexture(brush);
SDL_Quit();
return 0;