annotate Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/atlantis/atlantis.h @ 3485:e77a69aae239

Mason Wheeler to sdl I updated SDL, and suddenly my SDL frames stopped working. They'd "initialize" full of gibberish, and I couldn't render anything to them. After a bit of digging, I found a problem: the renderer initialization routine in my SDL frame code wasn't getting called anymore. procedure TSdlFrame.Paint; begin if SDL_SelectRenderer(FWindowID) = -1 then CreateRenderer; SDL_RenderPresent; end; function TSdlFrame.CreateRenderer: boolean; const pf: tagPIXELFORMATDESCRIPTOR = (nSize: sizeof(pf); nVersion: 1; dwFlags: PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER; iPixelType: PFD_TYPE_RGBA; cColorBits: 24; cAlphaBits: 8; iLayerType: PFD_MAIN_PLANE); RENDERERS: array[TRendererType] of AnsiString = ('software', 'gdi', 'opengl', 'd3d'); var pFormat: integer; begin if (SDL_SelectRenderer(FWindowID) = 0) then begin result := true; Exit; end; if FRendererType = rtOpenGL then begin pFormat := ChoosePixelFormat(canvas.Handle, @pf); if not SetPixelFormat(canvas.Handle, pFormat, @pf) then outputDebugString(PChar(SysErrorMessage(GetLastError))); if wglCreateContext(canvas.Handle) = 0 then outputDebugString(PChar(SysErrorMessage(GetLastError))); end; if (SDL_CreateRenderer(FWindowID, SDL_RendererIndex(RENDERERS[FRendererType]), [sdlrPresentFlip3, sdlrAccelerated]) = 0) then begin SDL_ShowWindow(FWindowID); assert(SDL_SetRenderDrawColor(0, 0, 0, 255) = 0); FFlags := SDL_GetWindowFlags(FWindowID); if assigned(FOnAvailable) then FOnAvailable(self); end else outputDebugString(pChar(format('SDL_CreateRenderer failed: %s', [sdl_GetError]))); result := SDL_SelectRenderer(FWindowID) = 0; end; This is a critical issue. The Paint method gets called when the control receives a WM_PAINT message from Windows. I can't create the renderer before then, or it will fail and cause trouble. And when I do create it, it needs to be created with certain parameters. So imagine my surprise when I started debugging into the DLL and found that SDL_SelectRenderer was trying to be "helpful" by creating the renderer for me if it didn't already exist! Now not only does my initialization code not get called, I end up with the wrong renderer and so things don't render as expected when I try to use the window.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 24 Nov 2009 04:48:12 +0000
parents 232e5e00e398
children
rev   line source
3329
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /**
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * ALL RIGHTS RESERVED
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Permission to use, copy, modify, and distribute this software for
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 * any purpose and without fee is hereby granted, provided that the above
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * copyright notice appear in all copies and that both the copyright notice
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * and this permission notice appear in supporting documentation, and that
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * the name of Silicon Graphics, Inc. not be used in advertising
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 * or publicity pertaining to distribution of the software without specific,
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 * written prior permission.
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 *
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 *
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * US Government Users Restricted Rights
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 * Use, duplication, or disclosure by the Government is subject to
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * clause at DFARS 252.227-7013 and/or in similar or successor
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * clauses in the FAR or the DOD or NASA FAR Supplement.
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 * Unpublished-- rights reserved under the copyright laws of the
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 * United States. Contractor/manufacturer is Silicon Graphics,
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 *
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 */
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #define RAD 57.295
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #define RRAD 0.01745
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #define NUM_SHARKS 4
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #define SHARKSIZE 6000
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #define SHARKSPEED 100.0
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #define WHALESPEED 250.0
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 typedef struct _fishRec {
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 float x, y, z, phi, theta, psi, v;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 float xt, yt, zt;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 float htail, vtail;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 float dtheta;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 int spurt, attack;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 } fishRec;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 extern fishRec sharks[NUM_SHARKS];
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 extern fishRec momWhale;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 extern fishRec babyWhale;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 extern fishRec dolph;
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 extern void FishTransform(fishRec *);
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 extern void WhalePilot(fishRec *);
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 extern void SharkPilot(fishRec *);
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 extern void SharkMiss(int);
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 extern void DrawWhale(fishRec *);
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 extern void DrawShark(fishRec *);
232e5e00e398 Added missing templates
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 extern void DrawDolphin(fishRec *);