annotate SDL 1.2 Mac OpenGL Application.xctemplate/main.c @ 0:b0b91cadc484

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