Mercurial > sdl-ios-xcode
annotate src/endian/SDL_endian.c @ 876:9e84d106ec19
(Said Max Horn on the SDL mailing list...)
Hi folks,
based on Eric Wing's patch, I created the attached patch which fixes
the OpenGL coordinate inversion bug in SDL. It works fine over here on
10.3 with Ryan's test program (which I also attached).
There is another change in it: I removed the "- 1" in the two lines
using CGDisplayPixelsHigh()... while I understand from a logical point
of view why they *should* be correct, I checked the actual values
computed that way, and they were off-by-one. After removing the " - 1",
the returned mouse coordinates are correct. I checked this by moving
the mouse to the screen top/bottom in fullscreen mode, BTW. With the
change, the proper values 0 and 479 are returned (in 640x480 mode).
Sam, you may still want to test on 10.1, it's very simple using Ryan's
minimal test code :-)
Cheers,
Max
(Here is the reproduction case for revision history's sake...)
/*
* To compile:
* gcc -o test test.c `sdl-config --cflags` `sdl-config --libs` -framework OpenGL
*
* --ryan.
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_opengl.h"
int main(int argc, char **argv)
{
Uint32 flags = SDL_OPENGL /* | SDL_FULLSCREEN */;
SDL_Surface *screen;
SDL_Event event;
int done = 0;
GLfloat ratio;
SDL_Init(SDL_INIT_VIDEO);
SDL_ShowCursor(0);
if ((argv[1]) && (strcmp(argv[1], "--grab") == 0))
SDL_WM_GrabInput(SDL_GRAB_ON);
screen = SDL_SetVideoMode(640, 480, 0, flags);
if (!screen)
return(42);
ratio = ((GLfloat) screen->w) / ((GLfloat) screen->h);
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClearDepth( 1.0f );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
glViewport( 0, 0, screen->w, screen->h);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, ratio, 0.1f, 100.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapBuffers();
// eh, close enough.
#define MAX_X 6.12
#define MAX_Y 4.50
while (!done)
{
int x, y;
GLfloat glx, gly;
if (!SDL_WaitEvent(&event))
break;
switch (event.type)
{
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE)
done = 1;
break;
}
SDL_GetMouseState(&x, &y);
glx = ((((GLfloat) x) / ((GLfloat) screen->w)) - 0.5f) * MAX_X;
gly = ((((GLfloat) y) / ((GLfloat) screen->h)) - 0.5f) * MAX_Y;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(glx,-gly,-6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0); glVertex3f( 0.00f, 0.25f, 0.00f);
glColor3f(0,1,0); glVertex3f(-0.25f, -0.25f, 0.00f);
glColor3f(0,0,1); glVertex3f( 0.25f, -0.25f, 0.00f);
glEnd();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return(0);
}
/* end of test.c ... */
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 22 Mar 2004 09:38:20 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Functions for dynamically reading and writing endian-specific values */ | |
29 | |
30 #include "SDL_endian.h" | |
31 | |
32 Uint16 SDL_ReadLE16 (SDL_RWops *src) | |
33 { | |
34 Uint16 value; | |
35 | |
36 SDL_RWread(src, &value, (sizeof value), 1); | |
37 return(SDL_SwapLE16(value)); | |
38 } | |
39 Uint16 SDL_ReadBE16 (SDL_RWops *src) | |
40 { | |
41 Uint16 value; | |
42 | |
43 SDL_RWread(src, &value, (sizeof value), 1); | |
44 return(SDL_SwapBE16(value)); | |
45 } | |
46 Uint32 SDL_ReadLE32 (SDL_RWops *src) | |
47 { | |
48 Uint32 value; | |
49 | |
50 SDL_RWread(src, &value, (sizeof value), 1); | |
51 return(SDL_SwapLE32(value)); | |
52 } | |
53 Uint32 SDL_ReadBE32 (SDL_RWops *src) | |
54 { | |
55 Uint32 value; | |
56 | |
57 SDL_RWread(src, &value, (sizeof value), 1); | |
58 return(SDL_SwapBE32(value)); | |
59 } | |
60 Uint64 SDL_ReadLE64 (SDL_RWops *src) | |
61 { | |
62 Uint64 value; | |
63 | |
64 SDL_RWread(src, &value, (sizeof value), 1); | |
65 return(SDL_SwapLE64(value)); | |
66 } | |
67 Uint64 SDL_ReadBE64 (SDL_RWops *src) | |
68 { | |
69 Uint64 value; | |
70 | |
71 SDL_RWread(src, &value, (sizeof value), 1); | |
72 return(SDL_SwapBE64(value)); | |
73 } | |
74 | |
75 int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value) | |
76 { | |
77 value = SDL_SwapLE16(value); | |
78 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); | |
79 } | |
80 int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value) | |
81 { | |
82 value = SDL_SwapBE16(value); | |
83 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); | |
84 } | |
85 int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value) | |
86 { | |
87 value = SDL_SwapLE32(value); | |
88 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); | |
89 } | |
90 int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value) | |
91 { | |
92 value = SDL_SwapBE32(value); | |
93 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); | |
94 } | |
95 int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value) | |
96 { | |
97 value = SDL_SwapLE64(value); | |
98 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); | |
99 } | |
100 int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value) | |
101 { | |
102 value = SDL_SwapBE64(value); | |
103 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); | |
104 } |