Blacktiger
2006.06.15, 12:02 AM
I am trying to write some simple SDL code in preperation for a Carlosvision entry. I want to make the code cross-platform, but for some reason my conditional compilation stuff fails! Here is the code:
/* This file contains the main routine to start up the game.
* Routines used in this file should be initialization routines only.
* Author: Michael Martz
* Date: 14 June 2006
*/
//-- Set the OS we are building for --\\
#define MACOSX
#ifdef MACOSX
#include "SDL.h"
#include <OpenGL/gl.h>
#endif
#ifdef WINDOWS
#include "SDL.h"
#include <gl.h>
#endif
#ifdef LINUX
#include "SDL.h"
#include <GL/gl.h>
#endif
using namespace std;
/* Initialize OpenGL Attributes */
// Returns: true if successful, false otherwise
void initOpenGL();
/* Create an OpenGL Context */
// Returns: the OpenGL context
SDL_Surface* makeContext();
int main(int argc, char *argv[])
{
//-- Initialize SDL Subsystems --\\
// Assumption: SDL_INIT returns a non-zero value only if an error occurs.
if(SDL_Init(SDL_INIT_EVERYTHING))
{
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(1);
}
//-- Initialize OpenGL --\\
initOpenGL();
// Create a surface to draw on.
SDL_Surface* oglContext = makeContext();
// Cleanup SDL
SDL_Quit();
return 0;
}
/* Initialize OpenGL Attributes */
// Returns: true if successful, false otherwise
void initOpenGL()
{
// Since we need 3D to handle our 'rotated' view, setup the depth buffer.
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
// Make OpenGL depth buffered.
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);
// On Mac OS X you don’t need to set the size of the frame buffer’s red, green, blue, and alpha
// components. If you create a draw context with 32 bit color, Mac OS X uses 8 bits for each
// of the four components. On other operating systems it may be necessesary to do so. A little
// preprocessor work will help here.
#ifndef MACOSX
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
#endif
}
/* Create an OpenGL Context */
// Returns: the OpenGL context
SDL_Surface* makeContext()
{
return SDL_SetVideoMode(800, 600, 32, SDL_OPENGL | SDL_FULLSCREEN);
}
But #include "SDL.h" never executes apparently so none of the SDL calls work! What am I doing wrong?
/* This file contains the main routine to start up the game.
* Routines used in this file should be initialization routines only.
* Author: Michael Martz
* Date: 14 June 2006
*/
//-- Set the OS we are building for --\\
#define MACOSX
#ifdef MACOSX
#include "SDL.h"
#include <OpenGL/gl.h>
#endif
#ifdef WINDOWS
#include "SDL.h"
#include <gl.h>
#endif
#ifdef LINUX
#include "SDL.h"
#include <GL/gl.h>
#endif
using namespace std;
/* Initialize OpenGL Attributes */
// Returns: true if successful, false otherwise
void initOpenGL();
/* Create an OpenGL Context */
// Returns: the OpenGL context
SDL_Surface* makeContext();
int main(int argc, char *argv[])
{
//-- Initialize SDL Subsystems --\\
// Assumption: SDL_INIT returns a non-zero value only if an error occurs.
if(SDL_Init(SDL_INIT_EVERYTHING))
{
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(1);
}
//-- Initialize OpenGL --\\
initOpenGL();
// Create a surface to draw on.
SDL_Surface* oglContext = makeContext();
// Cleanup SDL
SDL_Quit();
return 0;
}
/* Initialize OpenGL Attributes */
// Returns: true if successful, false otherwise
void initOpenGL()
{
// Since we need 3D to handle our 'rotated' view, setup the depth buffer.
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
// Make OpenGL depth buffered.
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);
// On Mac OS X you don’t need to set the size of the frame buffer’s red, green, blue, and alpha
// components. If you create a draw context with 32 bit color, Mac OS X uses 8 bits for each
// of the four components. On other operating systems it may be necessesary to do so. A little
// preprocessor work will help here.
#ifndef MACOSX
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
#endif
}
/* Create an OpenGL Context */
// Returns: the OpenGL context
SDL_Surface* makeContext()
{
return SDL_SetVideoMode(800, 600, 32, SDL_OPENGL | SDL_FULLSCREEN);
}
But #include "SDL.h" never executes apparently so none of the SDL calls work! What am I doing wrong?