annotate src/video/photon/SDL_ph_modes.c @ 597:5e738444b658

*** empty log message ***
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Feb 2003 00:39:33 +0000
parents 8e3ce997621c
children 8bedd6d61642
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
297
f6ffac90895c Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 204
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 #ifdef SAVE_RCSID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 static char rcsid =
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 "@(#) $Id$";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include "SDL_ph_modes_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 static unsigned long key1, key2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 static PgVideoModeInfo_t mode_info;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 static PgVideoModes_t mode_list;
266
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
33
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
34 /* The current list of available video modes */
266
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
35 SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES];
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
36 SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 static int compare_modes_by_res(const void* mode1, const void* mode2)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 {
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
40 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
41 {
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
42 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
43 *(unsigned short*)mode1);
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
44 return 0;
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
45 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
47 key1 = mode_info.width * mode_info.height;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
49 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
50 {
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
51 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
52 *(unsigned short*)mode2);
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
53 return 0;
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
54 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
56 key2 = mode_info.width * mode_info.height;
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
57
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
58 if (key1 > key2)
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
59 return 1;
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
60 else if (key1 == key2)
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
61 return 0;
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
62 else
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
63 return -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65
266
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
66 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 {
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
68 int i = 0;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
69 int j = 0;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
70 SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
72 for (i=0; i<PH_MAX_VIDEOMODES; i++)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
73 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
74 SDL_modearray[i]=&SDL_modelist[i];
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
75 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
77 if (PgGetVideoModeList( &mode_list ) < 0)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
78 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
79 fprintf(stderr,"error: PgGetVideoModeList failed\n");
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
80 return NULL;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
81 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
83 mode_info.bits_per_pixel = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
85 for (i=0; i < mode_list.num_modes; i++)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
86 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
87 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
88 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
89 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", mode_list.modes[i]);
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
90 return NULL;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
91 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
92 if(mode_info.bits_per_pixel == format->BitsPerPixel)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
93 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
94 Amodelist[j].w = mode_info.width;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
95 Amodelist[j].h = mode_info.height;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
96 Amodelist[j].x = 0;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
97 Amodelist[j].y = 0;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
98 j++;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
99 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
100 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
101
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
102 /* reorder biggest for smallest, assume width dominates */
266
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
103
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
104 for(i=0; i<j; i++)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
105 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
106 SDL_modelist[i].w = Amodelist[j - i -1].w;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
107 SDL_modelist[i].h = Amodelist[j - i -1].h;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
108 SDL_modelist[i].x = Amodelist[j - i -1].x;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
109 SDL_modelist[i].y = Amodelist[j - i -1].y;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
110 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
111 SDL_modearray[j]=NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
113 return SDL_modearray;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 void ph_FreeVideoModes(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 {
266
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
118 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
121 /* return the mode associated with width, height and bpp */
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
122 /* if there is no mode then zero is returned */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 int get_mode(int width, int height, int bpp)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 {
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
125 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
127 if(width<640)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
128 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
129 width=640;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
130 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
131 if(height<480)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
132 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
133 height=480;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
134 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
136 if (PgGetVideoModeList(&mode_list) < 0)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
137 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
138 fprintf(stderr,"error: PgGetVideoModeList failed\n");
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
139 return -1;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
140 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
141
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
142 /* search list for exact match */
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
143 for (i=0;i<mode_list.num_modes;i++)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
144 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
145 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
146 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
147 fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
148 return 0;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
149 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
150
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
151 if ((mode_info.width == width) &&
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
152 (mode_info.height == height) &&
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
153 (mode_info.bits_per_pixel == bpp))
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
154 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
155 return mode_list.modes[i];
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
156 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
157 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
158
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
159 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 int get_mode_any_format(int width, int height, int bpp)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 /* return the mode associated with width, height and bpp */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 /* if requested bpp is not found the mode with closest bpp is returned */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 int i, closest, delta, min_delta;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 if (PgGetVideoModeList( &mode_list ) < 0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 fprintf(stderr,"error: PgGetVideoModeList failed\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 for(i=0;i<mode_list.num_modes;i++)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 if ((mode_info.width == width) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 (mode_info.height == height))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 if (i<mode_list.num_modes)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 {
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
188 /* get closest bpp */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 closest = i++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 if (mode_info.bits_per_pixel == bpp)
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
191 return mode_list.modes[closest];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 min_delta = abs(mode_info.bits_per_pixel - bpp);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 while(1)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 if ((mode_info.width != width) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 (mode_info.height != height))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 else if (mode_info.bits_per_pixel == bpp)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 closest = i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 delta = abs(mode_info.bits_per_pixel - bpp);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 if (delta < min_delta)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 closest = i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 min_delta = delta;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 i++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 }
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
221 return mode_list.modes[closest];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 else
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
224 return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 int ph_ToggleFullScreen(_THIS, int on)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 {
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
229 if (currently_fullscreen)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
230 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
231 return ph_LeaveFullScreen(this);
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
232 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
233 else
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
234 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
235 return ph_EnterFullScreen(this);
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
236 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
238 return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 int ph_EnterFullScreen(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 {
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
243 if (!currently_fullscreen)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
244 {
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
245 if (this->screen)
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
246 {
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
247 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
248 {
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
249 #ifdef HAVE_OPENGL
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
250 #endif /* HAVE_OPENGL */
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
251 return 0;
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
252 }
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
253 }
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
254
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
255 if (OCImage.direct_context==NULL)
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
256 {
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
257 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
258 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
260 if (!OCImage.direct_context)
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
261 {
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
262 fprintf(stderr, "ph_EnterFullScreen(): Can't create direct context !\n");
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
263 return 0;
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
264 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
266 OCImage.oldDC=PdDirectStart(OCImage.direct_context);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
268 currently_fullscreen = 1;
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
269 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
271 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
274 int ph_LeaveFullScreen(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 {
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
276 PgDisplaySettings_t mymode_settings;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
278 if (currently_fullscreen)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
279 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
280 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
281 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
282 #ifdef HAVE_OPENGL
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
283 #endif /* HAVE_OPENGL */
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
284 return 0;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
285 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
286 else
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
287 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
288 PdDirectStop(OCImage.direct_context);
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
289 PdReleaseDirectContext(OCImage.direct_context);
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
290 PhDCSetCurrent(OCImage.oldDC);
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
291
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
292 currently_fullscreen=0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
294 /* Restore old video mode */
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
295 if (old_video_mode != -1)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
296 {
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
297 mymode_settings.mode= (unsigned short) old_video_mode;
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
298 mymode_settings.refresh= (unsigned short) old_refresh_rate;
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
299 mymode_settings.flags= 0;
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
300
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
301 if (PgSetVideoMode(&mymode_settings) < 0)
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
302 {
571
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
303 fprintf(stderr, "Ph_LeaveFullScreen(): PgSetVideoMode failed !\n");
8e3ce997621c Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 315
diff changeset
304 return 0;
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
305 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
306 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
307
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
308 old_video_mode=-1;
315
3333b6e68289 Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 309
diff changeset
309 old_refresh_rate=-1;
309
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
310 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
311
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
312 }
2de77f7b7a28 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
313 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 }