SDL mit C++ unter OSX
-
Hallo,
ich versuche gerade ein Dreieck und ein Quadrat mit dem SDL unter dem Mac OSX Leopard auf den Bildschirm zu zaubern. Mit C++ fange ich gerade erst an, habe aber mit OpenGL schon Erfahrungen in einer anderen Sprache. Ich verwende zwar Xcode und ein eher exotisches OS, glaube aber, dass das ein ganz primitiver Anfängerfehler ist. Den Code habe ich mir von NeHe und der SDL-Doku zusammengereimt.Xcode mag bei den beiden
return( TRUE );
das TRUE anscheinend nicht, und sagt "error: "TRUE" was not declared in this scope." Das sagt mir, dass er nicht weiß TRUE letztendlich heißt und ich es nicht deklariert habe. TRUE sollte doch eine Konstante sein? GLvoid ist auch entsprechend angegeben ...
Weiters beschwert Xcode sich bei
if ( isActive )
, und gibt denselben Fehler wie oben aus, also error: "isActive" was not declared in this scope."
Danke!
/* Simple program: Create a blank window, wait for keypress, quit. Please see the SDL documentation for details on using the SDL API: /Developer/Documentation/SDL/docs.html */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <GLUT/glut.h> #include "SDL.h" /* general OpenGL initialization function */ int initGL( GLvoid ) { /* Enable smooth shading */ glShadeModel( GL_SMOOTH ); /* Set the background black */ glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); /* Depth buffer setup */ glClearDepth( 1.0f ); /* Enables Depth Testing */ glEnable( GL_DEPTH_TEST ); /* The Type Of Depth Test To Do */ glDepthFunc( GL_LEQUAL ); /* Really Nice Perspective Calculations */ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); return( TRUE ); } /* Here goes our drawing code */ int drawGLScene( GLvoid ) { /* These are to calculate our fps */ static GLint T0 = 0; static GLint Frames = 0; /* Clear The Screen And The Depth Buffer */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); /* Move Left 1.5 Units And Into The Screen 6.0 */ glLoadIdentity(); glTranslatef( -1.5f, 0.0f, -6.0f ); glBegin( GL_TRIANGLES ); /* Drawing Using Triangles */ glVertex3f( 0.0f, 1.0f, 0.0f ); /* Top */ glVertex3f( -1.0f, -1.0f, 0.0f ); /* Bottom Left */ glVertex3f( 1.0f, -1.0f, 0.0f ); /* Bottom Right */ glEnd( ); /* Finished Drawing The Triangle */ /* Move Right 3 Units */ glTranslatef( 3.0f, 0.0f, 0.0f ); glBegin( GL_QUADS ); /* Draw A Quad */ glVertex3f( -1.0f, 1.0f, 0.0f ); /* Top Left */ glVertex3f( 1.0f, 1.0f, 0.0f ); /* Top Right */ glVertex3f( 1.0f, -1.0f, 0.0f ); /* Bottom Right */ glVertex3f( -1.0f, -1.0f, 0.0f ); /* Bottom Left */ glEnd( ); /* Done Drawing The Quad */ /* Draw it to the screen */ SDL_GL_SwapBuffers( ); /* Gather our frames per second */ Frames++; { GLint t = SDL_GetTicks(); if (t - T0 >= 5000) { GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); T0 = t; Frames = 0; } } return( TRUE ); } int main(int argc, char *argv[]) { Uint32 initflags = SDL_INIT_VIDEO; /* See documentation for details */ SDL_Surface *screen; Uint8 video_bpp = 0; Uint32 videoflags = SDL_SWSURFACE; int done; SDL_Event event; /* Initialize the SDL library */ if ( SDL_Init(initflags) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } /* Set 640x480 video mode */ screen=SDL_SetVideoMode(640,480, video_bpp, videoflags); if (screen == NULL) { fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n", video_bpp, SDL_GetError()); SDL_Quit(); exit(2); } initGL(); done = 0; while ( !done ) { /* Check for events */ while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_MOUSEMOTION: break; case SDL_MOUSEBUTTONDOWN: break; case SDL_KEYDOWN: /* Any keypress quits the app... */ case SDL_QUIT: done = 1; break; default: break; } } /* draw the scene */ if ( isActive ) drawGLScene( ); } /* Clean up the SDL library */ SDL_Quit(); return(0); }
-
Die Fehler sagen doch alles aus. "IsActive" ist nirgendswo deklariert worden.
Das gleiche gilt für "TRUE". Inkludier entweder eien Header wo dies drinnsteht, oder schreib:#ifndef BOOL #define BOOL int #endif #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif
Aber wenn du schon C++ benutzt, dann verwende am besten
bool true false