Mercurial > sdl-ios-xcode
view test/testcdrom.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 | 9c6717a1c66f |
children | be9c9c8f6d53 |
line wrap: on
line source
/* Test the SDL CD-ROM audio functions */ #include <stdlib.h> #include <stdio.h> #include <ctype.h> #include "SDL.h" static void PrintStatus(int driveindex, SDL_CD *cdrom) { CDstatus status; char *status_str; status = SDL_CDStatus(cdrom); switch (status) { case CD_TRAYEMPTY: status_str = "tray empty"; break; case CD_STOPPED: status_str = "stopped"; break; case CD_PLAYING: status_str = "playing"; break; case CD_PAUSED: status_str = "paused"; break; case CD_ERROR: status_str = "error state"; break; } printf("Drive %d status: %s\n", driveindex, status_str); if ( status >= CD_PLAYING ) { int m, s, f; FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f); printf("Currently playing track %d, %d:%2.2d\n", cdrom->track[cdrom->cur_track].id, m, s); } } static void ListTracks(SDL_CD *cdrom) { int i; int m, s, f; char* trtype; SDL_CDStatus(cdrom); printf("Drive tracks: %d\n", cdrom->numtracks); for ( i=0; i<cdrom->numtracks; ++i ) { FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f); if ( f > 0 ) ++s; switch(cdrom->track[i].type) { case SDL_AUDIO_TRACK: trtype="audio"; break; case SDL_DATA_TRACK: trtype="data"; break; default: trtype="unknown"; break; } printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i, cdrom->track[i].id, m, s, cdrom->track[i].length, trtype); } } static void PrintUsage(char *argv0) { fprintf(stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0); fprintf(stderr, "Where 'command' is one of:\n"); fprintf(stderr, " -status\n"); fprintf(stderr, " -list\n"); fprintf(stderr, " -play [first_track] [first_frame] [num_tracks] [num_frames]\n"); fprintf(stderr, " -pause\n"); fprintf(stderr, " -resume\n"); fprintf(stderr, " -stop\n"); fprintf(stderr, " -eject\n"); fprintf(stderr, " -sleep <milliseconds>\n"); } int main(int argc, char *argv[]) { int drive; int i; SDL_CD *cdrom; /* Initialize SDL first */ if ( SDL_Init(SDL_INIT_CDROM) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); exit(1); } atexit(SDL_Quit); /* Find out how many CD-ROM drives are connected to the system */ if ( SDL_CDNumDrives() == 0 ) { printf("No CD-ROM devices detected\n"); exit(0); } printf("Drives available: %d\n", SDL_CDNumDrives()); for ( i=0; i<SDL_CDNumDrives(); ++i ) { printf("Drive %d: \"%s\"\n", i, SDL_CDName(i)); } /* Open the CD-ROM */ drive = 0; i=1; if ( argv[i] && isdigit(argv[i][0]) ) { drive = atoi(argv[i++]); } cdrom = SDL_CDOpen(drive); if ( cdrom == NULL ) { fprintf(stderr, "Couldn't open drive %d: %s\n", drive, SDL_GetError()); exit(2); } #ifdef TEST_NULLCD cdrom = NULL; #endif /* Find out which function to perform */ for ( ; argv[i]; ++i ) { if ( strcmp(argv[i], "-status") == 0 ) { /* PrintStatus(drive, cdrom); */ } else if ( strcmp(argv[i], "-list") == 0 ) { ListTracks(cdrom); } else if ( strcmp(argv[i], "-play") == 0 ) { int strack, sframe; int ntrack, nframe; strack = 0; if ( argv[i+1] && isdigit(argv[i+1][0]) ) { strack = atoi(argv[++i]); } sframe = 0; if ( argv[i+1] && isdigit(argv[i+1][0]) ) { sframe = atoi(argv[++i]); } ntrack = 0; if ( argv[i+1] && isdigit(argv[i+1][0]) ) { ntrack = atoi(argv[++i]); } nframe = 0; if ( argv[i+1] && isdigit(argv[i+1][0]) ) { nframe = atoi(argv[++i]); } if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) { if ( SDL_CDPlayTracks(cdrom, strack, sframe, ntrack, nframe) < 0 ) { fprintf(stderr, "Couldn't play tracks %d/%d for %d/%d: %s\n", strack, sframe, ntrack, nframe, SDL_GetError()); } } else { fprintf(stderr, "No CD in drive!\n"); } } else if ( strcmp(argv[i], "-pause") == 0 ) { if ( SDL_CDPause(cdrom) < 0 ) { fprintf(stderr, "Couldn't pause CD: %s\n", SDL_GetError()); } } else if ( strcmp(argv[i], "-resume") == 0 ) { if ( SDL_CDResume(cdrom) < 0 ) { fprintf(stderr, "Couldn't resume CD: %s\n", SDL_GetError()); } } else if ( strcmp(argv[i], "-stop") == 0 ) { if ( SDL_CDStop(cdrom) < 0 ) { fprintf(stderr, "Couldn't eject CD: %s\n", SDL_GetError()); } } else if ( strcmp(argv[i], "-eject") == 0 ) { if ( SDL_CDEject(cdrom) < 0 ) { fprintf(stderr, "Couldn't eject CD: %s\n", SDL_GetError()); } } else if ( (strcmp(argv[i], "-sleep") == 0) && (argv[i+1] && isdigit(argv[i+1][0])) ) { SDL_Delay(atoi(argv[++i])); printf("Delayed %d milliseconds\n", atoi(argv[i])); } else { PrintUsage(argv[0]); SDL_CDClose(cdrom); exit(1); } } PrintStatus(drive, cdrom); SDL_CDClose(cdrom); return(0); }