Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
7aadbd91
Commit
7aadbd91
authored
Feb 21, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the template code
parent
1c631c85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
44 deletions
+51
-44
main.c
Xcode-iPhoneOS/Template/SDL iOS Application/main.c
+20
-13
main.c
...emplatesForXcodeSnowLeopard/SDL OpenGL Application/main.c
+31
-31
No files found.
Xcode-iPhoneOS/Template/SDL iOS Application/main.c
View file @
7aadbd91
...
...
@@ -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
);
...
...
@@ -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
(
r
enderer
,
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 */
window
ID
=
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
)
{
...
...
@@ -80,7 +87,7 @@ main(int argc, char *argv[])
done
=
1
;
}
}
render
();
render
(
renderer
);
SDL_Delay
(
1
);
}
...
...
Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/main.c
View file @
7aadbd91
...
...
@@ -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
()
...
...
@@ -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
...
...
@@ -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
();
...
...
@@ -173,7 +173,7 @@ int main(int argc, char *argv[])
mainLoop
();
// Cleanup
SDL_Quit
();
SDL_Quit
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment