当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_calloc函数代码示例

本文整理汇总了C++中SDL_calloc函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_calloc函数的具体用法?C++ SDL_calloc怎么用?C++ SDL_calloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_calloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Emscripten_GLES_LoadLibrary

int
Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
    /*we can't load EGL dynamically*/
    _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
    if (!_this->egl_data) {
        return SDL_OutOfMemory();
    }

    /* Emscripten forces you to manually cast eglGetProcAddress to the real
       function type; grep for "__eglMustCastToProperFunctionPointerType" in
       Emscripten's egl.h for details. */
    _this->egl_data->eglGetProcAddress = (void *(EGLAPIENTRY *)(const char *)) eglGetProcAddress;

    LOAD_FUNC(eglGetDisplay);
    LOAD_FUNC(eglInitialize);
    LOAD_FUNC(eglTerminate);
    LOAD_FUNC(eglChooseConfig);
    LOAD_FUNC(eglGetConfigAttrib);
    LOAD_FUNC(eglCreateContext);
    LOAD_FUNC(eglDestroyContext);
    LOAD_FUNC(eglCreateWindowSurface);
    LOAD_FUNC(eglDestroySurface);
    LOAD_FUNC(eglMakeCurrent);
    LOAD_FUNC(eglSwapBuffers);
    LOAD_FUNC(eglSwapInterval);
    LOAD_FUNC(eglWaitNative);
    LOAD_FUNC(eglWaitGL);
    LOAD_FUNC(eglBindAPI);
    
    _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (!_this->egl_data->egl_display) {
        return SDL_SetError("Could not get EGL display");
    }
    
    if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
        return SDL_SetError("Could not initialize EGL");
    }

    if (path) {
        SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
    } else {
        *_this->gl_config.driver_path = '\0';
    }
    
    return 0;
}
开发者ID:Evengard,项目名称:UniMod,代码行数:46,代码来源:SDL_emscriptenopengles.c

示例2: CommonCreateState

CommonState *
CommonCreateState(char **argv, Uint32 flags)
{
    CommonState *state = SDL_calloc(1, sizeof(*state));
    if (!state) {
        SDL_OutOfMemory();
        return NULL;
    }

    /* Initialize some defaults */
    state->argv = argv;
    state->flags = flags;
    state->window_title = argv[0];
    state->window_flags = 0;
    state->window_x = SDL_WINDOWPOS_UNDEFINED;
    state->window_y = SDL_WINDOWPOS_UNDEFINED;
    state->window_w = DEFAULT_WINDOW_WIDTH;
    state->window_h = DEFAULT_WINDOW_HEIGHT;
    state->num_windows = 1;
    state->audiospec.freq = 22050;
    state->audiospec.format = AUDIO_S16;
    state->audiospec.channels = 2;
    state->audiospec.samples = 2048;

    /* Set some very sane GL defaults */
    state->gl_red_size = 3;
    state->gl_green_size = 3;
    state->gl_blue_size = 2;
    state->gl_alpha_size = 0;
    state->gl_buffer_size = 0;
    state->gl_depth_size = 16;
    state->gl_stencil_size = 0;
    state->gl_double_buffer = 1;
    state->gl_accum_red_size = 0;
    state->gl_accum_green_size = 0;
    state->gl_accum_blue_size = 0;
    state->gl_accum_alpha_size = 0;
    state->gl_stereo = 0;
    state->gl_multisamplebuffers = 0;
    state->gl_multisamplesamples = 0;
    state->gl_retained_backing = 1;
    state->gl_accelerated = -1;

    return state;
}
开发者ID:BarleyStudio,项目名称:CorsixTH-AndroidFrontend,代码行数:45,代码来源:common.c

示例3: sizeof

void *TIMIDITY_CreateFromRW(SDL_RWops *src, int freesrc)
{
    TIMIDITY_Music *music;
    SDL_AudioSpec spec;
    SDL_bool need_stream = SDL_FALSE;

    music = (TIMIDITY_Music *)SDL_calloc(1, sizeof(*music));
    if (!music) {
        SDL_OutOfMemory();
        return NULL;
    }

    SDL_memcpy(&spec, &music_spec, sizeof(spec));
    if (spec.channels > 2) {
        need_stream = SDL_TRUE;
        spec.channels = 2;
    }
    music->song = Timidity_LoadSong(src, &spec);
    if (!music->song) {
        TIMIDITY_Delete(music);
        return NULL;
    }

    if (need_stream) {
        music->stream = SDL_NewAudioStream(spec.format, spec.channels, spec.freq,
                                           music_spec.format, music_spec.channels, music_spec.freq);
        if (!music->stream) {
            TIMIDITY_Delete(music);
            return NULL;
        }

        music->buffer_size = spec.samples * (SDL_AUDIO_BITSIZE(spec.format) / 8) * spec.channels;
        music->buffer = SDL_malloc(music->buffer_size);
        if (!music->buffer) {
            SDL_OutOfMemory();
            TIMIDITY_Delete(music);
            return NULL;
        }
    }

    if (freesrc) {
        SDL_RWclose(src);
    }
    return music;
}
开发者ID:davidsiaw,项目名称:SDL2_mixer,代码行数:45,代码来源:music_timidity.c

示例4: D3D_CreateTexture

static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
    D3D_TextureData *data;
    D3DPOOL pool;
    DWORD usage;
    HRESULT result;

    data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        SDL_OutOfMemory();
        return -1;
    }
    data->scaleMode = GetScaleQuality();

    texture->driverdata = data;

#ifdef USE_DYNAMIC_TEXTURE
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
        pool = D3DPOOL_DEFAULT;
        usage = D3DUSAGE_DYNAMIC;
    } else
#endif
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
        /* D3DPOOL_MANAGED does not work with D3DUSAGE_RENDERTARGET */
        pool = D3DPOOL_DEFAULT;
        usage = D3DUSAGE_RENDERTARGET;
    } else {
        pool = D3DPOOL_MANAGED;
        usage = 0;
    }

    result =
        IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
                                       texture->h, 1, usage,
                                       PixelFormatToD3DFMT(texture->format),
                                       pool, &data->texture, NULL);
    if (FAILED(result)) {
        D3D_SetError("CreateTexture()", result);
        return -1;
    }

    return 0;
}
开发者ID:Deraen,项目名称:ohj2710,代码行数:45,代码来源:SDL_render_d3d.c

示例5: PSP_CreateWindow

int
PSP_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *wdata;

    /* Allocate window internal data */
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
    if (wdata == NULL) {
        return SDL_OutOfMemory();
    }

    /* Setup driver data for this window */
    window->driverdata = wdata;


    /* Window has been successfully created */
    return 0;
}
开发者ID:MichalWolodkiewicz,项目名称:wizznic-android,代码行数:18,代码来源:SDL_pspvideo.c

示例6: GDI_CreateTexture

static int
GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
    SDL_Window *window = renderer->window;
    SDL_VideoDisplay *display = window->display;
    GDI_TextureData *data;

    data = (GDI_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        SDL_OutOfMemory();
        return -1;
    }

    texture->driverdata = data;

    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
        data->yuv =
            SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
        if (!data->yuv) {
            return -1;
        }
        data->format = display->current_mode.format;
    } else {
        data->format = texture->format;
    }
    data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));

    if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING
        || texture->format != display->current_mode.format) {
        data->hbm = GDI_CreateDIBSection(renderdata->memory_hdc,
                                         texture->w, texture->h,
                                         data->pitch, data->format,
                                         &data->hpal, &data->pixels);
    } else {
        data->hbm = CreateCompatibleBitmap(renderdata->window_hdc,
                                           texture->w, texture->h);
    }
    if (!data->hbm) {
        WIN_SetError("Couldn't create bitmap");
        return -1;
    }
    return 0;
}
开发者ID:weimingtom,项目名称:eriri_lua,代码行数:44,代码来源:SDL_gdirender.c

示例7: SDL_EVDEV_device_added

static int
SDL_EVDEV_device_added(const char *devpath)
{
    SDL_evdevlist_item *item;

    /* Check to make sure it's not already in list. */
    for (item = _this->first; item != NULL; item = item->next) {
        if (strcmp(devpath, item->path) == 0) {
            return -1;  /* already have this one */
        }
    }
    
    item = (SDL_evdevlist_item *) SDL_calloc(1, sizeof (SDL_evdevlist_item));
    if (item == NULL) {
        return SDL_OutOfMemory();
    }

    item->fd = open(devpath, O_RDONLY, 0);
    if (item->fd < 0) {
        SDL_free(item);
        return SDL_SetError("Unable to open %s", devpath);
    }
    
    item->path = SDL_strdup(devpath);
    if (item->path == NULL) {
        close(item->fd);
        SDL_free(item);
        return SDL_OutOfMemory();
    }
    
    /* Non blocking read mode */
    fcntl(item->fd, F_SETFL, O_NONBLOCK);
    
    if (_this->last == NULL) {
        _this->first = _this->last = item;
    } else {
        _this->last->next = item;
        _this->last = item;
    }
    
    SDL_EVDEV_sync_device(item);
    
    return _this->numdevices++;
}
开发者ID:1414648814,项目名称:Torque3D,代码行数:44,代码来源:SDL_evdev.c

示例8: Emscripten_GLES_LoadLibrary

int
Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
    /*we can't load EGL dynamically*/
    _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
    if (!_this->egl_data) {
        return SDL_OutOfMemory();
    }
    
    LOAD_FUNC(eglGetDisplay);
    LOAD_FUNC(eglInitialize);
    LOAD_FUNC(eglTerminate);
    LOAD_FUNC(eglGetProcAddress);
    LOAD_FUNC(eglChooseConfig);
    LOAD_FUNC(eglGetConfigAttrib);
    LOAD_FUNC(eglCreateContext);
    LOAD_FUNC(eglDestroyContext);
    LOAD_FUNC(eglCreateWindowSurface);
    LOAD_FUNC(eglDestroySurface);
    LOAD_FUNC(eglMakeCurrent);
    LOAD_FUNC(eglSwapBuffers);
    LOAD_FUNC(eglSwapInterval);
    LOAD_FUNC(eglWaitNative);
    LOAD_FUNC(eglWaitGL);
    LOAD_FUNC(eglBindAPI);
    
    _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (!_this->egl_data->egl_display) {
        return SDL_SetError("Could not get EGL display");
    }
    
    if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
        return SDL_SetError("Could not initialize EGL");
    }

    _this->gl_config.driver_loaded = 1;

    if (path) {
        SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
    } else {
        *_this->gl_config.driver_path = '\0';
    }
    
    return 0;
}
开发者ID:03050903,项目名称:Torque3D,代码行数:44,代码来源:SDL_emscriptenopengles.c

示例9: PND_createwindow

int
PND_createwindow(_THIS, SDL_Window * window)
{
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;

    SDL_WindowData *wdata;

    /* Allocate window internal data */
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
    if (wdata == NULL) {
        return SDL_OutOfMemory();
    }

    /* Setup driver data for this window */
    window->driverdata = wdata;

    /* Check if window must support OpenGL ES rendering */
    if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {

        EGLBoolean initstatus;

        /* Mark this window as OpenGL ES compatible */
        wdata->uses_gles = SDL_TRUE;

        /* Create connection to OpenGL ES */
        if (phdata->egl_display == EGL_NO_DISPLAY) {
            phdata->egl_display = eglGetDisplay((NativeDisplayType) 0);
            if (phdata->egl_display == EGL_NO_DISPLAY) {
                return SDL_SetError("PND: Can't get connection to OpenGL ES");
            }

            initstatus = eglInitialize(phdata->egl_display, NULL, NULL);
            if (initstatus != EGL_TRUE) {
                return SDL_SetError("PND: Can't init OpenGL ES library");
            }
        }

        phdata->egl_refcount++;
    }

    /* Window has been successfully created */
    return 0;
}
开发者ID:Evengard,项目名称:UniMod,代码行数:43,代码来源:SDL_pandora.c

示例10: D3D_CreateTexture

static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
    SDL_Window *window = renderer->window;
    D3DFORMAT display_format = renderdata->pparams.BackBufferFormat;
    D3D_TextureData *data;
    D3DPOOL pool;
    DWORD usage;
    HRESULT result;

    data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        SDL_OutOfMemory();
        return -1;
    }
    data->scaleMode = GetScaleQuality();

    texture->driverdata = data;

#ifdef USE_DYNAMIC_TEXTURE
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
        pool = D3DPOOL_DEFAULT;
        usage = D3DUSAGE_DYNAMIC;
    } else
#endif
    {
        pool = D3DPOOL_MANAGED;
        usage = 0;
    }

    result =
        IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
                                       texture->h, 1, usage,
                                       PixelFormatToD3DFMT(texture->format),
                                       pool, &data->texture, NULL);
    if (FAILED(result)) {
        D3D_SetError("CreateTexture()", result);
        return -1;
    }

    return 0;
}
开发者ID:0xD34D,项目名称:supermariowar-android,代码行数:43,代码来源:SDL_render_d3d.c

示例11: ANDROIDAUDIO_OpenDevice

static int
ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
    SDL_AudioFormat test_format;

    SDL_assert((captureDevice == NULL) || !iscapture);
    SDL_assert((audioDevice == NULL) || iscapture);

    if (iscapture) {
        captureDevice = this;
    } else {
        audioDevice = this;
    }

    this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden));
    if (this->hidden == NULL) {
        return SDL_OutOfMemory();
    }

    test_format = SDL_FirstAudioFormat(this->spec.format);
    while (test_format != 0) { /* no "UNKNOWN" constant */
        if ((test_format == AUDIO_U8) ||
			(test_format == AUDIO_S16) ||
			(test_format == AUDIO_F32)) {
            this->spec.format = test_format;
            break;
        }
        test_format = SDL_NextAudioFormat();
    }

    if (test_format == 0) {
        /* Didn't find a compatible format :( */
        return SDL_SetError("No compatible audio format!");
    }

    if (Android_JNI_OpenAudioDevice(iscapture, &this->spec) < 0) {
        return -1;
    }

    SDL_CalculateAudioSpec(&this->spec);

    return 0;
}
开发者ID:GWRon,项目名称:sdl.mod,代码行数:43,代码来源:SDL_androidaudio.c

示例12: LoadTracks

/* Read a list of tracks from the volume */
static int LoadTracks (SDL_CD *cdrom)
{
    /* Check if tracks are already loaded */
    if  ( tracks[cdrom->id] != NULL )
        return 0;
        
    /* Allocate memory for tracks */
    tracks[cdrom->id] = (FSRef*) SDL_calloc (1, sizeof(**tracks) * cdrom->numtracks);
    if (tracks[cdrom->id] == NULL) {
        SDL_OutOfMemory ();
        return -1;
    }
    
    /* Load tracks */
    if (ListTrackFiles (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0)
        return -1;

    return 0;
}
开发者ID:cuttl,项目名称:wii2600,代码行数:20,代码来源:SDL_syscdrom.c

示例13: gf_createtexture

static int gf_createtexture(SDL_Renderer* renderer, SDL_Texture* texture)
{
   SDL_RenderData* renderdata=(SDL_RenderData*)renderer->driverdata;
   SDL_Window* window=SDL_GetWindowFromID(renderer->window);
   SDL_VideoDisplay* display=SDL_GetDisplayFromWindow(window);
   SDL_TextureData* tdata=NULL;

   /* Allocate texture driver data */
   tdata=(SDL_TextureData*)SDL_calloc(1, sizeof(SDL_TextureData));
   if (tdata==NULL)
   {
      SDL_OutOfMemory();
      return -1;
   }

   /* Set texture driver data */
   texture->driverdata=tdata;

}
开发者ID:jjgod,项目名称:SDL,代码行数:19,代码来源:SDL_gf_render.c

示例14: SDL_EVDEV_Init

int
SDL_EVDEV_Init(void)
{
    if (_this == NULL) {
        _this = (SDL_EVDEV_PrivateData*)SDL_calloc(1, sizeof(*_this));
        if (_this == NULL) {
            return SDL_OutOfMemory();
        }

#if SDL_USE_LIBUDEV
        if (SDL_UDEV_Init() < 0) {
            SDL_free(_this);
            _this = NULL;
            return -1;
        }

        /* Set up the udev callback */
        if (SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback) < 0) {
            SDL_UDEV_Quit();
            SDL_free(_this);
            _this = NULL;
            return -1;
        }
        
        /* Force a scan to build the initial device list */
        SDL_UDEV_Scan();
#else
        /* TODO: Scan the devices manually, like a caveman */
#endif /* SDL_USE_LIBUDEV */
        
        /* We need a physical terminal (not PTS) to be able to translate key
           code to symbols via the kernel tables */
        _this->console_fd = SDL_EVDEV_get_active_tty();
        
        /* Mute the keyboard so keystrokes only generate evdev events and do not
           leak through to the console */
        SDL_EVDEV_mute_keyboard(_this->console_fd, &_this->kb_mode);
    }
    
    _this->ref_count += 1;
    
    return 0;
}
开发者ID:abakobo,项目名称:monkey2,代码行数:43,代码来源:SDL_evdev.c

示例15: VIVANTE_AddVideoDisplays

static int
VIVANTE_AddVideoDisplays(_THIS)
{
    SDL_VideoData *videodata = _this->driverdata;
    SDL_VideoDisplay display;
    SDL_DisplayMode current_mode;
    SDL_DisplayData *data;
    int pitch = 0, bpp = 0;
    unsigned long pixels = 0;

    data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
    if (data == NULL) {
        return SDL_OutOfMemory();
    }

    SDL_zero(current_mode);
#if SDL_VIDEO_DRIVER_VIVANTE_VDK
    data->native_display = vdkGetDisplay(videodata->vdk_private);

    vdkGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
#else
    data->native_display = videodata->fbGetDisplayByIndex(0);

    videodata->fbGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
#endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */

    switch (bpp)
    {
    default: /* Is another format used? */
    case 16:
        current_mode.format = SDL_PIXELFORMAT_RGB565;
        break;
    }
    /* FIXME: How do we query refresh rate? */
    current_mode.refresh_rate = 60;

    SDL_zero(display);
    display.desktop_mode = current_mode;
    display.current_mode = current_mode;
    display.driverdata = data;
    SDL_AddVideoDisplay(&display);
    return 0;
}
开发者ID:mgerhardy,项目名称:caveexpress,代码行数:43,代码来源:SDL_vivantevideo.c


注:本文中的SDL_calloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。