本文整理汇总了C++中IMG_GetError函数的典型用法代码示例。如果您正苦于以下问题:C++ IMG_GetError函数的具体用法?C++ IMG_GetError怎么用?C++ IMG_GetError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IMG_GetError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main(int argc, char* args[]) {
if ( is_window_created() )
{
// for "libpng warning: iCCP: known incorrect sRGB profile"
// http://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-incorrect-srgb-profile
// load sdl2_image
int image_flags = IMG_INIT_PNG;
if ( !(IMG_Init(image_flags) & image_flags) )
{
printf("main: sdl2_image err: %s\n", IMG_GetError());
return 1;
}
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_11.html
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "main: SDL_mixer Error: %s\n", Mix_GetError() );
return 1;
}
// load sdl ttf: https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_8.html
// if ( TTF_Init() == -1 ) {
// printf("sdl2_ttf err: %s\n", TTF_GetError());
// return 1;
// }
if ( !load_media() )
{
user_quit = true;
}
// the LOOP
while ( !user_quit ) {
process_events(&g_event);
game_update();
}
}
/** closing **/
// Deallocate textures
texture_free(&g_current_texture);
// joystick
// SDL_JoystickClose(g_gamepad);
// g_gamepad = 0;
// sfx
Mix_FreeChunk( g_scratch );
Mix_FreeChunk( g_hig );
Mix_FreeChunk( g_med );
Mix_FreeChunk( g_low );
g_scratch = 0;
g_hig = 0;
g_med = 0;
g_low = 0;
// music
Mix_FreeMusic( g_music );
g_music = 0;
SDL_DestroyRenderer(g_render);
SDL_DestroyWindow(g_window);
g_window = 0;
g_render = 0;
// https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_10.html
// TTF_Quit();
Mix_Quit();
IMG_Quit();
SDL_Quit();
return 0;
}
示例2: init
bool init()
{
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create window
gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create vsynced renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
// gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
success = false;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
}
}
}
return success;
}
示例3: SDL_GetError
//====================
// Methods
//====================
////////////////////////////////////////////////////////////
bool Window::create(const std::string& title, const Vector2i& position, const Vector2i& size, const ContextSettings_t& settings)
{
m_title = title;
m_position = position;
m_size = size;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO))
{
log.error(log.function(__FUNCTION__, title, position, size), "SDL failed to initialize:", SDL_GetError());
return false;
}
if (IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) == 0)
{
log.error(log.function(__FUNCTION__, title, position, size), "SDL image failed to initialize:", IMG_GetError());
return false;
}
m_pWindow = SDL_CreateWindow(m_title.c_str(),
m_position.x,
m_position.y,
m_size.x,
m_size.y,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!m_pWindow)
{
log.error(log.function(title, position, size), "Failed to create window:", SDL_GetError());
return false;
}
m_context = SDL_GL_CreateContext(m_pWindow);
SDL_GL_SetSwapInterval(1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_settings.depthBits);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_settings.stencilBits);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, m_settings.majorVersion);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, m_settings.minorVersion);
m_running = true;
if (!m_pMain)
{
glewExperimental = GL_TRUE;
GLenum error = glewInit();
if (error != GLEW_OK)
{
log.error(log.function(__FUNCTION__, title, position, size), "GLEW failed to initialize:", glewGetErrorString(error));
return false;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
log.debug(log.function(__FUNCTION__, title, position, size), "Main window set.");
m_pMain = this;
}
glEnable(GL_DEPTH_TEST);
log.debug(log.function(__FUNCTION__, title, position, size), "Created successfully.");
return true;
}
示例4: tacAssert
void TextureResource::Load()
{
tacAssert( GetFileName() != "" );
// load an image
LogInfo( std::string("Loading image: ") + GetFileName() );
mSurface = IMG_Load( (IMG_DIR + GetFileName()).c_str() );
tacAssert( mSurface );
if ( !mSurface )
{
LogError( std::string("Unable to load bitmap: ") + GetFileName() + std::string(" SDL_image error: ") + std::string( IMG_GetError() ) );
}
}
示例5: initialize
//! initialize sdl window
bool initialize()
{
// Initialization flag
bool success = true;
// Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
std::cerr << "SDL could not initialize. SDL_Error: "
<< SDL_GetError()
<< std::endl;
success = false;
}
else
{
// Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
std::cerr << "Warning: Linear texture filtering not enabled!"
<< std::endl;
}
// Create window
g_window = SDL_CreateWindow( "SDL Tutorial",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
screen_width_height[0],
screen_width_height[1],
SDL_WINDOW_SHOWN );
if( g_window == NULL )
{
std::cerr << "Window could not be created. SDL_Error: "
<< SDL_GetError()
<< std::endl;
success = false;
}
else
{
// Create the renderer for the window
g_renderer = SDL_CreateRenderer( g_window, -1, SDL_RENDERER_ACCELERATED);
if( g_renderer == NULL )
{
std::cerr << "Renderer could not be created! SDL_Error: "
<< SDL_GetError()
<< std::endl;
success = false;
}
else
{
// Initialize renderer color
SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
// Initialize PNG loading
int img_flags = IMG_INIT_PNG;
if( !( IMG_Init( img_flags ) & img_flags ) )
{
std::cerr << "SDL_image extension could not initialize! "
<< "SDL_image Error: " << IMG_GetError()
<< std::endl;
success = false;
}
}
}
}
return success;
}
示例6: cacheLookup
Image *SDLHardwareRenderDevice::loadImage(const std::string& filename, int error_type) {
// lookup image in cache
Image *img;
img = cacheLookup(filename);
if (img != NULL) return img;
// load image
SDLHardwareImage *image = new SDLHardwareImage(this, renderer);
if (!image) return NULL;
image->surface = IMG_LoadTexture(renderer, mods->locate(filename).c_str());
if(image->surface == NULL) {
delete image;
if (error_type != ERROR_NONE)
Utils::logError("SDLHardwareRenderDevice: Couldn't load image: '%s'. %s", filename.c_str(), IMG_GetError());
if (error_type == ERROR_EXIT) {
Utils::logErrorDialog("SDLHardwareRenderDevice: Couldn't load image: '%s'.\n%s", filename.c_str(), IMG_GetError());
mods->resetModConfig();
Utils::Exit(1);
}
return NULL;
}
// store image to cache
cacheStore(filename, image);
return image;
}
示例7: cacheLookup
Image *SDLHardwareRenderDevice::loadImage(std::string filename, std::string errormessage, bool IfNotFoundExit) {
// lookup image in cache
Image *img;
img = cacheLookup(filename);
if (img != NULL) return img;
// load image
SDLHardwareImage *image = new SDLHardwareImage(this, renderer);
if (!image) return NULL;
image->surface = IMG_LoadTexture(renderer, mods->locate(filename).c_str());
if(image->surface == NULL) {
delete image;
if (!errormessage.empty())
logError("SDLHardwareRenderDevice: [%s] %s: %s", filename.c_str(), errormessage.c_str(), IMG_GetError());
if (IfNotFoundExit) {
Exit(1);
}
return NULL;
}
// store image to cache
cacheStore(filename, image);
return image;
}
示例8: SDL_GetError
bool ColorKeyingApp::initApp()
{
// flag to return
bool success = true;
/*****
* Use this function to initialize the SDL library. This must be called before using any other SDL function.
* INFO: http://wiki.libsdl.org/SDL_Init?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
*****/
// Initialize SDL
// see following for remarks on flag http://wiki.libsdl.org/SDL_Init#Remarks
if (SDL_Init( SDL_INIT_VIDEO) < 0)
{
std::cout << "SDL ould not initalize! SDLError: " << SDL_GetError() << std::endl;
success = false;
}
else
{
//Set texture filtering to linear
// INFO ON SDL_SetHint: see https://wiki.libsdl.org/SDL_SetHint
// INFO ON SDL_HINT_RENDER_SCALE_QUALITY: see https://wiki.libsdl.org/SDL_HINT_RENDER_SCALE_QUALITY?highlight=%28\bCategoryDefine\b%29|%28CategoryHints%29
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
std::cout << "Warning: Linear texture filtering not enabled!" << std::endl;
}
/*****
* Returns the window that was created or NULL on failure
* INFO: http://wiki.libsdl.org/SDL_CreateWindow?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
******/
// Create Window
// INFO: see following for remarks on flags http://wiki.libsdl.org/SDL_CreateWindow#flags
gWindow = SDL_CreateWindow("SDL Tutorial 10", // the title of the window in UTF-8 encoding
SDL_WINDOWPOS_UNDEFINED, // the x position of the window
SDL_WINDOWPOS_UNDEFINED, // the y position of the window
SCREEN_WIDTH, // the width of the window
SCREEN_HEIGHT, // the height of the window
SDL_WINDOW_SHOWN // 0 or more SDL_WindowFlags OR'd together
);
if (gWindow == nullptr)
{
std::cout << "Window could not be created! SDL_Error:" << SDL_GetError() << std::endl;
success = false;
}
else
{
// Get window surface
// INFO: http://wiki.libsdl.org/SDL_GetWindowSurface?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
// gScreenSurface = SDL_GetWindowSurface(gWindow);
gCurrentRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if (gCurrentRenderer == nullptr)
{
std::cout << "Renderer could not be created! SDL Error: " << SDL_GetError() << std::endl;
}
else
{
// Initalize renderer color
SDL_SetRenderDrawColor(gCurrentRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
// initialize the SDL image
auto imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) && imgFlags))
{
std::cout << "SDL Image could not be initialized! SDL Img Error: " << IMG_GetError() << std::endl;
}
}
}
}
return success;
}
示例9: SDL_main
int SDL_main (int argc,char* argv[]) {
#elif __APPLE__
int SDL_main (int argc,char* argv[]) {
#else
#ifdef main
#undef main
#endif
int main(int argc,char* argv[]) {
#endif
printf("[INFO] Entering main\n");
uint32_t flags=SDL_INIT_VIDEO;
#ifndef WIN32
flags|=SDL_INIT_EVENTTHREAD;
#endif
#ifdef __MACH__
flags = SDL_INIT_EVERYTHING;
#endif
if (SDL_Init(flags)==-1) {
printf("SDL_Init: %s\n", SDL_GetError ());
return -1;
}
screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT, 32, SDL_SWSURFACE);
if(screen == NULL) {
printf("SDL_SetVideoMode failed!\n");
return -2;
}
SDL_WM_SetCaption ("Pebble Local Simulator - 24H Style",0);
pebbleScreen = createScreen;
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
return -3;
}
if (IMG_Init (IMG_INIT_PNG)==-1) {
printf("IMG_Init: %s\n", IMG_GetError());
return -4;
}
if (!loadSimulatorImages())
return -5;
bodyImg=getSimulatorImage(SIM_IMG_BODY);
shadowImg=getSimulatorImage(SIM_IMG_SCREEN_SHADOW);
vibeImg=getSimulatorImage(SIM_IMG_VIBE);
lightImg=getSimulatorImage(SIM_IMG_BACKLIGHT);
logFile=fopen (LOG_FILE,"a");
if (!initRender(pebbleScreen))
return -9;
persistent_storage_load();
initHardwareOutput ();
initButtons();
pbl_main();
unloadSystemFonts ();
quitRender();
persistent_storage_free();
if (logFile!=0)
fclose(logFile);
freeSimulatorImages();
IMG_Quit ();
TTF_Quit ();
SDL_Quit ();
return 0;
}
示例10: SDL_CreateWindow
/******************************************************************************
* Display Initialization
******************************************************************************/
bool display::init(const math::vec2i inResolution, bool isFullScreen) {
Uint32 windowFlags =
SDL_WINDOW_OPENGL |
SDL_WINDOW_SHOWN |
SDL_WINDOW_INPUT_FOCUS |
SDL_WINDOW_MOUSE_FOCUS |
//SDL_WINDOW_INPUT_GRABBED|
0;
if (isFullScreen) {
windowFlags |= SDL_WINDOW_FULLSCREEN;
}
/*
* Create the window
*/
pWindow = SDL_CreateWindow(
_GAME_NAME,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
inResolution[0], inResolution[1], windowFlags
);
if (!pWindow) {
std::cerr << SDL_GetError() << std::endl;
return false;
}
/*
* Create a renderer that will be used for the window
*/
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);
if (!pRenderer) {
std::cerr << SDL_GetError() << std::endl;
SDL_DestroyWindow(pWindow);
return false;
}
/*
* Attempt to initialize additional image format support
*/
const int imgFlags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
if ((IMG_Init(imgFlags)&imgFlags) != imgFlags) {
std::cerr
<< "Warning: Unable to initialize JPG, PNG, and TIF image loaders.\n"
<< IMG_GetError()
<< std::endl;
}
/*
* Initialize the TTF addon
*/
if (TTF_Init() < 0) {
std::cerr
<< "Warning: Unable to initialize the TTF add-on.\n"
<< TTF_GetError()
<< std::endl;
}
/*
* Misc
*/
SDL_SetRenderDrawBlendMode(pRenderer, SDL_BLENDMODE_BLEND);
SDL_GL_SetSwapInterval(1);
return true;
}
示例11: main
int main(int argc, char **argv)
{
// the character returned from the getopt function
char c;
// now loop and parse the command line options
while( (c=getopt(argc,argv,ARGUMENTS)) !=EOF)
{
switch(c) // which option has been chosen
{
case 'h' :
std::cout<<"TextureCompressor [filename(s)] for default DXT1 compression\n";
std::cout<<"-e [name] to change extension from default .cmp\n";
std::cout<<"-c [1][3][5] for DxT1 DxT3 or Dxt5 compression \n";
std::cout<<"-v verbose \n";
std::cout<<"it will process all files on command line\n";
exit(EXIT_SUCCESS);
case 'e' :
g_ext=optarg;
break;
case 'v' :
g_verbose=true;
break;
case '?' : // unknown option report this and exit
// where optopt is the current option
std::cout<<"Unknown argument "<<optopt<<std::endl;
exit(EXIT_FAILURE);
break;
case 'o' :
g_output=optarg;
break;
case 'c' :
if(optarg[0]=='1')
{
// this is the default but set it anyway
g_comp=DXT1;
g_scomp=squish::kDxt1;
}
else if(optarg[0]=='3')
{
g_comp=DXT3;
g_scomp=squish::kDxt3;
}
else if(optarg[0]=='5')
{
g_comp=DXT5;
g_scomp=squish::kDxt5;
}
break;
}
}
// Initialize SDL's Video subsystem
if (SDL_Init(SDL_INIT_VIDEO) < 0 )
{
// Or die on error
std::cerr<<"Problem with SDL\n";
std::exit(EXIT_FAILURE);
}
// image data to load
SDL_Surface *image;
std::ofstream fileOut;
fileOut.open(g_output.c_str(),std::ios::out | std::ios::binary);
const std::string header("ngl::packtexture");
fileOut.write(header.c_str(),header.length());
int numFiles=0;
// need to store this position for later so we can write out
// the actual number of files packed.
int numFileLocation=fileOut.tellp();
// now write out dummy size;
fileOut.write(reinterpret_cast<char *>(&numFiles),sizeof(int));
for(int file=optind; file<argc; ++file)
{
// load current file and see if it is ok
image=IMG_Load(argv[file]);
if(!image)
{
std::cerr<<"Problem loading "<<argv[file]<<" " <<IMG_GetError()<<"\n";
continue;
}
// now compress.
createCompressedTexture(fileOut,image,argv[file]);
// and free the image
SDL_free(image);
++numFiles;
}
fileOut.seekp(numFileLocation,std::ios_base::beg );
fileOut.write(reinterpret_cast<char *>(&numFiles),sizeof(int));
// close file
fileOut.close();
//.........这里部分代码省略.........
示例12: init
void ReinforcementPictures<T>::displayLoop()
{
#if 0
// initialization
logging.info("Starting SDL init (0)..");
SDL_Init(0);
logging.info("Starting SDL subsystem init (events, video, audio)..");
if(SDL_InitSubSystem(SDL_INIT_EVENTS) != 0){
logging.error("SDL_Init(EVENTS) failed.");
SDL_Quit();
running = false;
return;
}
if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0){
logging.error("SDL_Init(VIDEO) failed.");
SDL_Quit();
running = false;
return;
}
if(SDL_InitSubSystem(SDL_INIT_AUDIO) != 0){
logging.error("SDL_Init(AUDIO) failed.");
SDL_Quit();
running = false;
return;
}
logging.info("SDL_Init() events, video, audio successful.");
#endif
// opens SDL display
SDL_Window* window = NULL;
int W = 640;
int H = 480;
SDL_DisplayMode mode;
if(SDL_GetCurrentDisplayMode(0, &mode) == 0){
W = (3*mode.w)/4;
H = (3*mode.h)/4;
}
else{
whiteice::logging.error("SDL_GetCurrentDisplayMode() failed");
running = false;
SDL_Quit();
return;
}
#if 0
if(TTF_Init() != 0){
char buffer[80];
snprintf(buffer, 80, "TTF_Init failed: %s\n", TTF_GetError());
logging.error(buffer);
TTF_Quit();
SDL_Quit();
running = false;
return;
}
else
logging.info("Starting TTF_Init() done..");
int flags = IMG_INIT_JPG | IMG_INIT_PNG;
if(IMG_Init(flags) != flags){
char buffer[80];
snprintf(buffer, 80, "IMG_Init failed: %s\n", IMG_GetError());
logging.error(buffer);
IMG_Quit();
TTF_Quit();
SDL_Quit();
running = false;
return;
}
#endif
window = SDL_CreateWindow("Tranquility",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
W, H,
SDL_WINDOW_ALWAYS_ON_TOP |
SDL_WINDOW_INPUT_FOCUS);
if(window == NULL){
whiteice::logging.error("SDL_CreateWindow() failed\n");
running = false;
return;
}
SDL_RaiseWindow(window);
SDL_UpdateWindowSurface(window);
SDL_RaiseWindow(window);
// loads font
TTF_Font* font = NULL;
//.........这里部分代码省略.........
示例13: printf
bool World::InitScreen()
{
bool run = true;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("Fail initialize : %s\n",SDL_GetError());
run = false;
}
else
{
printf("Initialization Success!\n");
if(!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"))
{
printf("Warning: VSync not enabled!\n");
run = false;
}
m_window = SDL_CreateWindow(TITLE,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,g_WINDOW_WIDTH,g_WINDOW_HEIGHT,SDL_WINDOW_SHOWN);
if(m_window == NULL)
{
printf("ERROR creting Window : %s\n",SDL_GetError());
run = false;
}
else
{
printf("Created Window .\n");
m_render = SDL_CreateRenderer(m_window,-1,SDL_RENDERER_ACCELERATED);
if(m_render == NULL)
{
printf("Failed creating Render : %s\n",SDL_GetError());
run = false;
}
else
{
printf("Creted Render.\n");
SDL_SetRenderDrawColor( m_render, 0xFF, 0xFF, 0xFF, 0xFF );
int picFlag = IMG_INIT_PNG;
if(!(IMG_Init(picFlag))& picFlag)
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
run = false;
}
else
{
if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
{
printf("Warning: Scale Quality not enabled!\n");
run = false;
}
else
{
m_Stick1 = SDL_JoystickOpen(0);
if(m_Stick1 == NULL)
{
printf("Warning: 1st Joystick FAIL\n");
}
m_Stick2 = SDL_JoystickOpen(1);
if(m_Stick2 == NULL)
{
printf("Warning: 2nd Joystick FAIL\n");
}
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 4, 4048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
}
}
}
}
}
}
m_main_music= new Sound();
m_main_music->Init("data/music.txt");
m_main_music->Play(true);
SDL_JoystickEventState(SDL_ENABLE);
return run;
}
示例14: SDL_GetError
/*
* Initializes the window and set it's corresponding Surface
*/
bool Graphics::init()
{
bool success;
int imgFlags;
success = true;
imgFlags = IMG_INIT_JPG | IMG_INIT_PNG;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
success = false;
std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl;
}
else
{
this->_window = SDL_CreateWindow("SDL Tutorial",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);
if (this->_window == NULL)
{
success = false;
std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << std::endl;
}
else
{
this->_renderer = SDL_CreateRenderer(this->_window, -1, SDL_RENDERER_ACCELERATED);
if (this->_renderer == NULL)
{
success = false;
std::cerr << "Renderer could not be created! SDL Error: " << SDL_GetError() << std::endl;
}
else
{
SDL_SetRenderDrawColor(this->_renderer, 255, 0, 0, 255);
if (!(IMG_Init(imgFlags) & imgFlags))
{
std::cerr << "SDL_Image could not initialize! SDL_Image error: " << IMG_GetError() << std::endl;
success = false;
}
}
}
}
return success;
}
示例15: init
bool init(int screen)//0 = windowed (default), 1 = 1.5x screen, 2 = fullscreen, 3 = 1.5x fullscreen mode
{
//Initialization flag
bool success = true;
//Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
//Use OpenGL 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
//Create window
switch (screen) {
case 1:
gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH*1.5, SCREEN_HEIGHT*1.5, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
break;
case 2:
gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
break;
case 3:
gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH*1.5, SCREEN_HEIGHT*1.5, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
break;
default:
gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
}
SDLNet_Init();
if (gWindow == NULL)
{
printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
//Create context
gContext = SDL_GL_CreateContext(gWindow);
if (gContext == NULL)
{
printf("OpenGL context could not be created! SDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
//Use Vsync
if (SDL_GL_SetSwapInterval(0) < 0)
{
printf("Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError());
}
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags))
{
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
success = false;
}
//Initialize OpenGL
if (!initGL())
{
printf("Unable to initialize OpenGL!\n");
success = false;
}
}
}
}
return success;
}