annotate Xcode/TemplatesForProjectBuilder/SDL OpenGL Application/main.c @ 2986:bb773ff79106

Updated the snapshot script for use on the website
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2009 06:32:01 +0000
parents 4d2d0548f5b2
children
rev   line source
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /* Simple program: Create a blank window, wait for keypress, quit.
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 Please see the SDL documentation for details on using the SDL API:
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 /Developer/Documentation/SDL/docs.html
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 */
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
7
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include <stdio.h>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 #include <stdlib.h>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #include <string.h>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #include <math.h>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 #include "SDL.h"
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
15 extern void Atlantis_Init ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
16 extern void Atlantis_Reshape (int w, int h);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
17 extern void Atlantis_Animate ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
18 extern void Atlantis_Display ();
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 static SDL_Surface *gScreen;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
22 static void initAttributes ()
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 // Setup attributes we want for the OpenGL context
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
25
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 int value;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
27
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 // Don't set color bit sizes (SDL_GL_RED_SIZE, etc)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 // Mac OS X will always use 8-8-8-8 ARGB for 32-bit screens and
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 // 5-5-5 RGB for 16-bit screens
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
31
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 // Request a 16-bit depth buffer (without this, there is no depth buffer)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 value = 16;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
34 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, value);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
35
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
36
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 // Request double-buffered OpenGL
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 // The fact that windows are double-buffered on Mac OS X has no effect
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 // on OpenGL double buffering.
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 value = 1;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
41 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, value);
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
44 static void printAttributes ()
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 // Print out attributes of the context we created
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 int nAttr;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 int i;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
49
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
50 int attr[] = { SDL_GL_RED_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_GREEN_SIZE,
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
51 SDL_GL_ALPHA_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_DEPTH_SIZE };
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
52
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
53 char *desc[] = { "Red size: %d bits\n", "Blue size: %d bits\n", "Green size: %d bits\n",
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
54 "Alpha size: %d bits\n", "Color buffer size: %d bits\n",
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
55 "Depth bufer size: %d bits\n" };
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 nAttr = sizeof(attr) / sizeof(int);
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
58
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 for (i = 0; i < nAttr; i++) {
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
60
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 int value;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
62 SDL_GL_GetAttribute (attr[i], &value);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
63 printf (desc[i], value);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
64 }
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
67 static void createSurface (int fullscreen)
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 Uint32 flags = 0;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
70
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 flags = SDL_OPENGL;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 if (fullscreen)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 flags |= SDL_FULLSCREEN;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
74
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 // Create window
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
76 gScreen = SDL_SetVideoMode (640, 480, 0, flags);
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 if (gScreen == NULL) {
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
78
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
79 fprintf (stderr, "Couldn't set 640x480 OpenGL video mode: %s\n",
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
80 SDL_GetError());
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
81 SDL_Quit();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
82 exit(2);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
83 }
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
86 static void initGL ()
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 {
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
88 Atlantis_Init ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
89 Atlantis_Reshape (gScreen->w, gScreen->h);
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
92 static void drawGL ()
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 {
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
94 Atlantis_Animate ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
95 Atlantis_Display ();
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
98 static void mainLoop ()
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 SDL_Event event;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 int done = 0;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 int fps = 24;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
103 int delay = 1000/fps;
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 int thenTicks = -1;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 int nowTicks;
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
106
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
107 while ( !done ) {
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
109 /* Check for events */
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
110 while ( SDL_PollEvent (&event) ) {
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
111 switch (event.type) {
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
113 case SDL_MOUSEMOTION:
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
114 break;
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
115 case SDL_MOUSEBUTTONDOWN:
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
116 break;
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
117 case SDL_KEYDOWN:
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
118 /* Any keypress quits the app... */
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
119 case SDL_QUIT:
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
120 done = 1;
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
121 break;
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
122 default:
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
123 break;
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
124 }
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
125 }
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
126
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 // Draw at 24 hz
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 // This approach is not normally recommended - it is better to
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 // use time-based animation and run as fast as possible
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
130 drawGL ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
131 SDL_GL_SwapBuffers ();
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 // Time how long each draw-swap-delay cycle takes
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 // and adjust delay to get closer to target framerate
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 if (thenTicks > 0) {
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
136 nowTicks = SDL_GetTicks ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
137 delay += (1000/fps - (nowTicks-thenTicks));
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 thenTicks = nowTicks;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 if (delay < 0)
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
140 delay = 1000/fps;
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
141 }
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
142 else {
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
143 thenTicks = SDL_GetTicks ();
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
146 SDL_Delay (delay);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
147 }
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
150 int main(int argc, char *argv[])
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 {
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
152 // Init SDL video subsystem
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
153 if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
154
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
155 fprintf(stderr, "Couldn't initialize SDL: %s\n",
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
156 SDL_GetError());
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
157 exit(1);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
158 }
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 // Set GL context attributes
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
161 initAttributes ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
162
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 // Create GL context
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
164 createSurface (0);
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
165
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 // Get GL context attributes
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
167 printAttributes ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
168
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 // Init GL state
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
170 initGL ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
171
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 // Draw, get events...
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
173 mainLoop ();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
174
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 // Cleanup
2220
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
176 SDL_Quit();
4d2d0548f5b2 Don't run indent on the Xcode templates
Sam Lantinga <slouken@libsdl.org>
parents: 2215
diff changeset
177
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 return 0;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 }