本文整理汇总了C++中IMG_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ IMG_Init函数的具体用法?C++ IMG_Init怎么用?C++ IMG_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IMG_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool init() {
bool success = true;
if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0) {
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
gWindow = SDL_CreateWindow( "Mahjong", 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
{
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
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;
}
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
}
}
}
return success;
}
示例2: printf
// Create window and renderer.
//Return -1 if it fails.
int Renderer::SDLinit(){
sdlwindow = NULL;
screensurface = NULL;
int window_width = 1280;
int window_height = 720;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
return -1;
} else {
//Create window
sdlwindow = SDL_CreateWindow( "SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, SDL_WINDOW_SHOWN );
if( sdlwindow == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
return -1;
} else {
//Get window surface
screensurface = SDL_GetWindowSurface( sdlwindow );
//Create renderer for window
gRenderer = SDL_CreateRenderer( sdlwindow, -1, SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
return -1;
} 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() );
return -1;
}
}
}
}
return 0;
}
示例3: init_sdl
int
init_sdl(void)
{
int flags;
/* initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
fprintf(stderr, "SDL could not initialize! SDL Error: %s\n",
SDL_GetError());
return -1;
}
/* set texture filtering to linear */
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
fprintf(stderr,
"Warning: Linear texture filtering not enabled!\n");
/* create window */
gWindow = SDL_CreateWindow("SDL Tutorial",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (gWindow == NULL) {
fprintf(stderr, "window could not be created! SDL Error: %s\n",
SDL_GetError());
return -1;
}
/* create renderer for window */
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if (gRenderer == NULL) {
fprintf(stderr, "Renderer could not be created! "
"SDL Error: %s\n", SDL_GetError());
return -1;
} else {
/* initialize renderer color */
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
/* initialize PNG loading */
flags = IMG_INIT_PNG;
if ((IMG_Init(flags) & flags) == 0) {
fprintf(stderr, "SDL_image could not initialize! "
"SDL_image Error: %s\n", IMG_GetError());
return -1;
}
}
return 0;
}
示例4: init
void init(){
SDL_Init(SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
gWindow = SDL_CreateWindow("batman 1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
batman = new Batman(gRenderer);
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
IMG_Init(IMG_INIT_PNG);
}
示例5: init_sdl_img
void GraphicsSDL::init_sdl_img()
{
// init SDL_image
int img_flags = IMG_INIT_JPG | IMG_INIT_PNG;
if ((IMG_Init(img_flags) & img_flags) != img_flags) {
printf("[gfx] SDL_image error: %s\n", IMG_GetError());
throw E_INIT_SDL_IMG;
}
// TODO: Remove guards when IMG gets properly supported by Emscripten
#ifndef __EMSCRIPTEN__
atexit(IMG_Quit);
print_sdl_img_version();
#endif
}
示例6: LOG
bool ModuleTextures::init() {
LOG("init Image library");
bool ret = true;
// load support for the PNG image format
int flags = IMG_INIT_PNG;
int init = IMG_Init(flags);
if ((init & flags) != flags) {
LOG("Could not initialize Image lib. IMG_init: %s", IMG_GetError());
ret = false;
}
return ret;
}
示例7: assert
//create SDL window and allow for png loading
void Game::Start()
{
assert( SDL_Init( SDL_INIT_EVERYTHING ) >= 0 );
mWindow = SDL_CreateWindow( "Shmup", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
assert( mWindow );
mRenderer = SDL_CreateRenderer( mWindow, -1, SDL_RENDERER_ACCELERATED );
assert( mRenderer );
int imgFlags = IMG_INIT_PNG;
assert( IMG_Init( imgFlags ) & imgFlags );
SDL_SetRenderDrawColor( mRenderer, 0x00, 0x00, 0x00, 0xFF );
}
示例8: Init
void Init() {
bool success = true;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("Tamagochi", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
//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;
}
}
示例9: SDL_CreateWindow
GraphicsSystem::GraphicsSystem(EntityManager *em, int window_width, int window_height)
{
_window = SDL_CreateWindow("Objectless", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, window_width, window_height, SDL_WINDOW_SHOWN);
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC);
_entitymanager = em;
// Initialize the flags for image lib
if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) {
assert2(false, "IMG_Init failed!! %s", SDL_GetError());
exit(0);
}
}
示例10: StartUp
void CResourceManager::StartUp(void)
{
//SDL_Image
if ( !IMG_Init(IMG_INIT_PNG) )
{
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_RESOURCES,"Starting Up! (FAILED LOADING SDL_Image)");
}
else
{
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_RESOURCES,"Starting Up! SDL_Image Loaded!");
}
LoadTextures();
LoadAudio();
}
示例11: logSDLError
int Saloon::init(const char* title, int width, int height, bool windowed, int x, int y) {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
logSDLError(std::cout, "SDL_Init");
return 1;
}
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);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// Slight optimization to prepare the PNG loader prior to loading any images
if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){
logSDLError(std::cout, "IMG_Init");
return 1;
}
if (TTF_Init() != 0){
logSDLError(std::cout, "TTF_Init");
return 1;
}
if(windowed) {
_window = SDL_CreateWindow(title, x, y, width, height,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
}
else {
_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height,
SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
}
if (_window == nullptr){
logSDLError(std::cout, "CreateWindow");
return 2;
}
_displayWidth = width;
_displayHeight = height;
_halfDisplayWidth = width/2.0f;
_halfDisplayHeight = height/2.0f;
return 0;
}
示例12: LogSDLError
bool
BackBuffer::Initialise(int width, int height)
{
m_width = width;
m_height = height;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{
LogSDLError();
return (false);
}
else
{
m_pWindow = SDL_CreateWindow("717130 Game Framework", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
if (m_pWindow == 0)
{
LogSDLError();
return (false);
}
else
{
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED);
if (m_pRenderer == 0)
{
LogSDLError();
return (false);
}
else
{
int imageResult = IMG_Init(IMG_INIT_PNG);
if (imageResult == 0)
{
LogSDLError();
return (false);
}
}
}
}
m_pTextureManager = new TextureManager();
assert(m_pTextureManager);
m_pTextureManager->Initialise(m_pRenderer);
return (true);
}
示例13: init
bool init() {
bool l_success = true;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
printf("SDL could not initialize! SDL Error: %s\n",
SDL_GetError());
l_success = false;
} else {
if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
printf("Warning: Linear texture filtering not enabled");
}
//Create window
g_window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(g_window == NULL) {
printf("Window could not be created! SDL Error: %s\n",
SDL_GetError());
l_success = false;
} else {
//Creates vsynced renderer for window
g_renderer = SDL_CreateRenderer(g_window, -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(g_renderer == NULL) {
printf("Renderer could not be created! SDL Error:%s\n",
SDL_GetError());
l_success = false;
} else {
SDL_SetRenderDrawColor(g_renderer, 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());
l_success = false;
}
//Initialize SDL_mixer
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
}
}
}
}
return l_success;
}
示例14: LOG
// Called before render is available
bool Textures::awake(pugi::xml_node &node)
{
LOG("Init Image library");
bool ret = true;
// load support for the PNG image format
int flags = IMG_INIT_PNG;
int init = IMG_Init(flags);
if((init & flags) != flags)
{
LOG("Could not initialize Image lib. IMG_Init: %s", IMG_GetError());
ret = false;
}
return ret;
}
示例15: sdl_init
void sdl_init(uint32_t sdl_flags, int img_flags)
{
sp_logger = common::logging_get_logger("sdlwrap");
sp_logger->info("Initializing SDL");
auto result = SDL_Init(sdl_flags);
if (result){
sdl_throw_error("SDL_Init");
}
sp_logger->info("Initializing SDL image");
result = IMG_Init(img_flags);
if (result != img_flags){
sdl_img_throw_error("IMG_Init");
}
}