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

Commit

Permalink
Updated the template code
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 21, 2011
1 parent e6342c2 commit 5e5bac6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
33 changes: 20 additions & 13 deletions Xcode-iPhoneOS/Template/SDL iOS Application/main.c
Expand Up @@ -17,10 +17,15 @@ randomInt(int min, int max)
}

void
render(void)
render(SDL_Renderer *renderer)
{

Uint8 r, g, b;

/* Clear the screen */
SDL_SetRenderDrawColor(0, 0, 0, 255);
SDL_SetRenderClear(renderer);

/* Come up with a random rectangle */
SDL_Rect rect;
rect.w = randomInt(64, 128);
Expand All @@ -32,46 +37,48 @@ render(void)
r = randomInt(50, 255);
g = randomInt(50, 255);
b = randomInt(50, 255);
SDL_SetRenderDrawColor(r, g, b, 255);
SDL_SetRenderDrawColor(renderer, r, g, b, 255);

/* Fill the rectangle in the color */
SDL_RenderFillRect(&rect);
SDL_RenderFillRect(renderer, &rect);

/* update screen */
SDL_RenderPresent();

SDL_RenderPresent(renderer);
}

int
main(int argc, char *argv[])
{

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

/* initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Could not initialize SDL\n");
return 1;
}

/* seed random number generator */
srand(time(NULL));

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

renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer) {
printf("Could not create renderer\n");
return 1;
}

/* Fill screen with black */
SDL_RenderClear();

/* Enter render loop, waiting for user to quit */
done = 0;
while (!done) {
Expand All @@ -80,7 +87,7 @@ main(int argc, char *argv[])
done = 1;
}
}
render();
render(renderer);
SDL_Delay(1);
}

Expand Down
62 changes: 31 additions & 31 deletions Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/main.c
Expand Up @@ -75,12 +75,12 @@ static void createSurface (int fullscreen)
// Create window
gScreen = SDL_SetVideoMode (640, 480, 0, flags);
if (gScreen == NULL) {
fprintf (stderr, "Couldn't set 640x480 OpenGL video mode: %s\n",
SDL_GetError());
SDL_Quit();
exit(2);
}
SDL_Quit();
exit(2);
}
}

static void initGL ()
Expand All @@ -100,29 +100,29 @@ static void mainLoop ()
SDL_Event event;
int done = 0;
int fps = 24;
int delay = 1000/fps;
int delay = 1000/fps;
int thenTicks = -1;
int nowTicks;

while ( !done ) {

/* Check for events */
while ( SDL_PollEvent (&event) ) {
switch (event.type) {

case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_KEYDOWN:
/* Any keypress quits the app... */
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
/* Check for events */
while ( SDL_PollEvent (&event) ) {
switch (event.type) {

case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_KEYDOWN:
/* Any keypress quits the app... */
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}

// Draw at 24 hz
// This approach is not normally recommended - it is better to
Expand All @@ -144,18 +144,18 @@ static void mainLoop ()
}

SDL_Delay (delay);
}
}
}

int main(int argc, char *argv[])
{
// Init SDL video subsystem
if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
// Init SDL video subsystem
if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(1);
}
SDL_GetError());
exit(1);
}

// Set GL context attributes
initAttributes ();
Expand All @@ -173,7 +173,7 @@ int main(int argc, char *argv[])
mainLoop ();

// Cleanup
SDL_Quit();
SDL_Quit();

return 0;
}

0 comments on commit 5e5bac6

Please sign in to comment.