本文整理汇总了C++中SDL_PixelFormatEnumToMasks函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_PixelFormatEnumToMasks函数的具体用法?C++ SDL_PixelFormatEnumToMasks怎么用?C++ SDL_PixelFormatEnumToMasks使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_PixelFormatEnumToMasks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SW_CreateTexture
static int
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return SDL_SetError("Unknown texture format");
}
texture->driverdata =
SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
Bmask, Amask);
SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
texture->b);
SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
/* Only RLE encode textures without an alpha channel since the RLE coder
* discards the color values of pixels with an alpha value of zero.
*/
if (texture->access == SDL_TEXTUREACCESS_STATIC && !Amask) {
SDL_SetSurfaceRLE(texture->driverdata, 1);
}
if (!texture->driverdata) {
return -1;
}
return 0;
}
示例2: DDRAW_IsTextureFormatAvailable
static SDL_bool
DDRAW_IsTextureFormatAvailable(IDirectDraw * ddraw, Uint32 display_format,
Uint32 texture_format)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (SDL_ISPIXELFORMAT_FOURCC(texture_format)) {
//TODO I don't expect DDRAW to support all 4CC formats, but I don't know which ones
return SDL_TRUE;
}
//These are only basic checks
if (SDL_ISPIXELFORMAT_INDEXED(texture_format)) {
return SDL_FALSE;
}
if (!SDL_PixelFormatEnumToMasks
(texture_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return SDL_FALSE;
}
switch (bpp) {
case 4:
case 8:
case 16:
case 24:
case 32:
break;
default:
return SDL_FALSE;
}
return SDL_TRUE;
}
示例3: SDL_DUMMY_CreateWindowFramebuffer
int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
int w, h;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
/* Free the old framebuffer surface */
surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
SDL_FreeSurface(surface);
/* Create a new one */
SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
SDL_GetWindowSize(window, &w, &h);
surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
if (!surface) {
return -1;
}
/* Save the info and return! */
SDL_SetWindowData(window, DUMMY_SURFACE, surface);
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
return 0;
}
示例4: CreateVideoSurface
static SDL_Surface *
CreateVideoSurface(SDL_TextureID textureID)
{
SDL_Surface *surface;
Uint32 format;
int w, h;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
void *pixels;
int pitch;
if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) {
return NULL;
}
if (!SDL_PixelFormatEnumToMasks
(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown texture format");
return NULL;
}
if (SDL_QueryTexturePixels(textureID, &pixels, &pitch) == 0) {
surface =
SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask,
Bmask, Amask);
} else {
surface =
SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
}
return surface;
}
示例5: SW_CreateTexture
static int
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return SDL_SetError("Unknown texture format");
}
texture->driverdata =
SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
Bmask, Amask);
SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
texture->b);
SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
if (texture->access == SDL_TEXTUREACCESS_STATIC) {
SDL_SetSurfaceRLE(texture->driverdata, 1);
}
if (!texture->driverdata) {
return -1;
}
return 0;
}
示例6: NDS_CreateRenderer
static SDL_Renderer *
NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayMode *displayMode = &display->current_mode;
SDL_Renderer *renderer;
NDS_RenderData *data;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) {
SDL_SetError("Unsupported pixel format (%x)", displayMode->format);
return NULL;
}
if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
&Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown display format");
return NULL;
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
SDL_free(renderer);
SDL_OutOfMemory();
return NULL;
}
renderer->info.name = NDS_RenderDriver.info.name;
renderer->info.flags = 0;
renderer->info.num_texture_formats = NDS_RenderDriver.info.num_texture_formats;
SDL_memcpy(renderer->info.texture_formats,
NDS_RenderDriver.info.texture_formats,
sizeof(renderer->info.texture_formats));
renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
renderer->info.max_texture_height = NDS_RenderDriver.info.max_texture_height;
renderer->UpdateViewport = NDS_UpdateViewport;
renderer->CreateTexture = NDS_CreateTexture;
renderer->DestroyTexture = NDS_DestroyTexture;
renderer->RenderCopy = NDS_RenderCopy;
renderer->UpdateTexture = NDS_UpdateTexture;
renderer->LockTexture = NDS_LockTexture;
renderer->UnlockTexture = NDS_UnlockTexture;
renderer->RenderClear = NDS_RenderClear;
renderer->RenderPresent = NDS_RenderPresent;
renderer->RenderDrawPoints = NDS_RenderDrawPoints;
renderer->RenderDrawLines = NDS_RenderDrawLines;
renderer->RenderFillRects = NDS_RenderFillRects;
return renderer;
}
示例7: ANDROID_VideoInit
int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
int i;
static SDL_PixelFormat alphaFormat;
/* Determine the screen depth (use default 16-bit depth) */
/* we change this during the SDL_SetVideoMode implementation... */
if( vformat ) {
vformat->BitsPerPixel = ANDROID_BITSPERPIXEL;
vformat->BytesPerPixel = ANDROID_BYTESPERPIXEL;
}
int bpp;
SDL_memset(&alphaFormat, 0, sizeof(alphaFormat));
SDL_PixelFormatEnumToMasks( SDL_PIXELFORMAT_RGBA4444, &bpp,
&alphaFormat.Rmask, &alphaFormat.Gmask,
&alphaFormat.Bmask, &alphaFormat.Amask );
alphaFormat.BitsPerPixel = ANDROID_BITSPERPIXEL;
alphaFormat.BytesPerPixel = ANDROID_BYTESPERPIXEL;
this->displayformatalphapixel = &alphaFormat;
this->info.hw_available = 1;
this->info.blit_hw = 1;
this->info.blit_hw_CC = 1;
this->info.blit_hw_A = 1;
this->info.blit_fill = 1;
this->info.video_mem = 128 * 1024; // Random value
this->info.current_w = SDL_ANDROID_sWindowWidth;
this->info.current_h = SDL_ANDROID_sWindowHeight;
SDL_VideoThreadID = SDL_ThreadID();
for ( i=0; i<SDL_NUMMODES; ++i ) {
SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
}
/* Modes sorted largest to smallest */
SDL_modelist[0]->w = SDL_ANDROID_sWindowWidth;
SDL_modelist[0]->h = SDL_ANDROID_sWindowHeight;
SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600; // Will likely be shrinked
SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480; // Will likely be shrinked
SDL_modelist[3]->w = 640; SDL_modelist[3]->h = 400; // Will likely be shrinked
SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240; // Always available on any screen and any orientation
SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200; // Always available on any screen and any orientation
SDL_modelist[6]->w = 256; SDL_modelist[6]->h = 224; // For REminiscence
SDL_modelist[7]->w = SDL_ANDROID_sWindowWidth * 2 / 3;
SDL_modelist[7]->h = SDL_ANDROID_sWindowHeight * 2 / 3;
SDL_modelist[8]->w = SDL_ANDROID_sWindowWidth / 2;
SDL_modelist[8]->h = SDL_ANDROID_sWindowHeight / 2;
SDL_modelist[9]->w = 480; SDL_modelist[9]->h = 320; // Virtual wide-screen mode
SDL_modelist[10]->w = 800; SDL_modelist[10]->h = 480; // Virtual wide-screen mode
SDL_modelist[11]->w = 544; SDL_modelist[11]->h = 332; // I have no idea where this videomode is used
SDL_modelist[12] = NULL;
SDL_VideoInit_1_3(NULL, 0);
/* We're done! */
return(0);
}
示例8: sdl_init
int
sdl_init()
{
/* Initialize defaults and Video subsystem */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
LOGE("sdl-video", "Unable to initialize SDL: %s.", SDL_GetError());
return -1;
}
/* Display program name and version in caption */
char caption[64];
snprintf(caption, 64, "freeserf %s", FREESERF_VERSION);
/* Create window and renderer */
window = SDL_CreateWindow(caption,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800, 600, SDL_WINDOW_RESIZABLE);
if (window == NULL) {
LOGE("sdl-video", "Unable to create SDL window: %s.", SDL_GetError());
return -1;
}
/* Create renderer for window */
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
LOGE("sdl-video", "Unable to create SDL renderer: %s.", SDL_GetError());
return -1;
}
/* Determine optimal pixel format for current window */
SDL_RendererInfo render_info = {0};
SDL_GetRendererInfo(renderer, &render_info);
for (int i = 0; i < render_info.num_texture_formats; i++) {
Uint32 format = render_info.texture_formats[i];
int bpp = SDL_BITSPERPIXEL(format);
if (32 == bpp) {
pixel_format = format;
break;
}
}
SDL_PixelFormatEnumToMasks(pixel_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
/* Set scaling mode */
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
/* Exit on signals */
signal(SIGINT, exit);
signal(SIGTERM, exit);
/* Init sprite cache */
surface_ht_init(&transp_sprite_cache, 4096);
surface_ht_init(&overlay_sprite_cache, 512);
surface_ht_init(&masked_sprite_cache, 1024);
return 0;
}
示例9: initializeTextures
void
initializeTextures()
{
SDL_Surface *bmp_surface;
SDL_Surface *bmp_surface_rgba;
int format = SDL_PIXELFORMAT_ABGR8888; /* desired texture format */
Uint32 Rmask, Gmask, Bmask, Amask; /* masks for desired format */
int bpp; /* bits per pixel for desired format */
/* load the ship */
bmp_surface = SDL_LoadBMP("ship.bmp");
if (bmp_surface == NULL) {
fatalError("could not ship.bmp");
}
/* set blue to transparent on the ship */
SDL_SetColorKey(bmp_surface, 1,
SDL_MapRGB(bmp_surface->format, 0, 0, 255));
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
/*
create a new RGBA surface and blit the bmp to it
this is an extra step, but it seems to be necessary for the color key to work
does the fact that this is necessary indicate a bug in SDL?
*/
bmp_surface_rgba =
SDL_CreateRGBSurface(0, bmp_surface->w, bmp_surface->h, bpp, Rmask,
Gmask, Bmask, Amask);
SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);
/* create ship texture from surface */
ship = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
if (ship == 0) {
fatalError("could not create ship texture");
}
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
/* set the width and height of the ship from the surface dimensions */
shipData.rect.w = bmp_surface->w;
shipData.rect.h = bmp_surface->h;
SDL_FreeSurface(bmp_surface_rgba);
SDL_FreeSurface(bmp_surface);
/* load the space background */
bmp_surface = SDL_LoadBMP("space.bmp");
if (bmp_surface == NULL) {
fatalError("could not load space.bmp");
}
/* create space texture from surface */
space = SDL_CreateTextureFromSurface(format, bmp_surface);
if (space == 0) {
fatalError("could not create space texture");
}
SDL_FreeSurface(bmp_surface);
}
示例10: SDL_PixelFormatEnumToMasks
SDL_Surface *createSurface(int w, int h)
{
int bpp;
Uint32 rMask, gMask, bMask, aMask;
SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888,
&bpp, &rMask, &gMask, &bMask, &aMask);
return SDL_CreateRGBSurface(0, w, h, bpp, rMask, gMask, bMask, 0);
}
示例11: createShadowSet
static SDL_Surface*
createShadowSet()
{
int bpp;
Uint32 rm, gm, bm, am;
SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, &bpp, &rm, &gm, &bm, &am);
SDL_Surface *surf = SDL_CreateRGBSurface(0, 1*32, 16*32, bpp, rm, gm, bm, am);
std::vector<SDL_Rect> rects;
SDL_Rect rect = { 0, 0, 16, 16 };
for (int val = 0; val < 16; ++val)
{
int origY = val*32;
/* Top left */
if (val & (1 << 0))
{
rect.x = 0;
rect.y = origY;
rects.push_back(rect);
}
/* Top Right */
if (val & (1 << 1))
{
rect.x = 16;
rect.y = origY;
rects.push_back(rect);
}
/* Bottom left */
if (val & (1 << 2))
{
rect.x = 0;
rect.y = origY+16;
rects.push_back(rect);
}
/* Bottom right */
if (val & (1 << 3))
{
rect.x = 16;
rect.y = origY+16;
rects.push_back(rect);
}
}
/* Fill rects with half opacity black */
uint32_t color = (0x80808080 & am);
SDL_FillRects(surf, dataPtr(rects), rects.size(), color);
return surf;
}
示例12: logEntered
bool Canvas::create(int w, int h) {
logEntered();
_w = w;
_h = h;
int bpp;
Uint32 rmask, gmask, bmask, amask;
SDL_PixelFormatEnumToMasks(PIXELFORMAT, &bpp, &rmask, &gmask, &bmask, &amask);
_ownerSurface = true;
_surface = SDL_CreateRGBSurface(0, w, h, bpp, rmask, gmask, bmask, amask);
_pixels = (pixel_t *)_surface->pixels;
return _surface != NULL;
}
示例13: SDL_PixelFormatEnumToMasks
SurfaceSDL::SurfaceSDL(int width, int height, PixelFormat::PF format)
{
int bpp;
uint32_t rmask, gmask, bmask, amask;
SDL_bool ret = SDL_PixelFormatEnumToMasks(get_sdl_pixel_format(format), &bpp, &rmask, &gmask, &bmask, &amask);
ASSERT_LOG(ret != SDL_FALSE, "Unable to convert pixel format to masks: " << SDL_GetError());
surface_ = SDL_CreateRGBSurface(0, width, height, bpp, rmask, gmask, bmask, amask);
ASSERT_LOG(surface_ != nullptr, "Error creating surface: " << SDL_GetError());
auto pf = std::make_shared<SDLPixelFormat>(surface_->format->format);
setPixelFormat(PixelFormatPtr(pf));
createPalette();
}
示例14: logEntered
bool Canvas::create(int w, int h) {
logEntered();
_w = w;
_h = h;
int bpp;
Uint32 rmask, gmask, bmask, amask;
#if defined(PIXELFORMAT_RGB565)
Uint32 format = SDL_PIXELFORMAT_RGB565;
#else
Uint32 format = SDL_PIXELFORMAT_RGB888;
#endif
SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask);
_canvas = SDL_CreateRGBSurface(0, w, h, bpp, rmask, gmask, bmask, amask);
return _canvas != NULL;
}
示例15: NearestPowerOf2
void Texture::loadFromSurface(SDL_Surface* surface)
{
SDL_Surface* resizedSurface = NULL;
SDL_Rect area;
if (surface == NULL)
{
return;
}
int newWidth = NearestPowerOf2(_width);
int newHeight = NearestPowerOf2(_height);
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(
SDL_PIXELFORMAT_ABGR8888, &bpp,
&Rmask, &Gmask, &Bmask, &Amask
);
resizedSurface = SDL_CreateRGBSurface(0, newWidth, newHeight, bpp,
Rmask, Gmask, Bmask, Amask
);
area.x = 0;
area.y = 0;
area.w = surface->w;
area.h = surface->h;
SDL_SetSurfaceAlphaMod( surface, 0xFF );
SDL_SetSurfaceBlendMode( surface, SDL_BLENDMODE_NONE );
SDL_BlitSurface(surface, &area, resizedSurface, &area);
glBindTexture(GL_TEXTURE_2D, _textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, resizedSurface->w, resizedSurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, resizedSurface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
_textureWidth = resizedSurface->w;
_textureHeight = resizedSurface->h;
SDL_FreeSurface(resizedSurface);
}