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;
}
void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
{
    SDL_Surface *surface;

    surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
    SDL_FreeSurface(surface);
}
예제 #3
0
	int inline Window::setWindowData(State & state, SDL_Window  * window){
		Stack * stack = state.stack;
		if (stack->is<LUA_TSTRING>(1) && stack->is<LUA_TLIGHTUSERDATA>(2)){
			const std::string name = stack->to<const std::string>(1);
			SDL_SetWindowData(window, name.c_str(), stack->to<void*>(2));
		}
		return 0;
	}
예제 #4
0
SDLX::Window :: Window ( SDL_Window * WHandle, std :: string Name, uint32_t Flags ):
	RefCounted (),
	Flags ( Flags ),
	WHandle ( WHandle ),
	SurfaceInst ( NULL ),
	RenderInst ( NULL ),
	GLInst ( NULL ),
	Name ( Name ),
	Destroyed ( false ),
	EventMap ()
{
	
	SDL_SetWindowData ( WHandle, kDataName_WindowClassInstancePointer, reinterpret_cast <void *> ( this ) );
	
}
예제 #5
0
bool ZWindow::CreateWindow(const char *title,int x, int y, int w, int h, uint32_t flags)
{
	if (m_win)
		return false;
	m_win= SDL_CreateWindow(title, x,y,w,h,flags);
	
	if (m_win ){
		SDL_SetWindowBordered(m_win,SDL_FALSE);
		//SDL_SetWindowTransparent(m_win,SDL_TRUE);
		SDL_SetWindowData(m_win,WND_USER_DATA,this);

#ifdef WIN32
		SDL_SetWindowData(m_win,"EV_HitTest",WindowHitTestHandle);
		SDL_SetWindowData(m_win,"EV_Render",WindowRenderHandle);
#endif

		m_render=new ZRenerder(m_win);
		m_mgr.Init(this);
		Init();
		return true;
	}
	else
		return false;
}
예제 #6
0
static CoglBool
_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                            CoglError **error)
{
  CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
  CoglOnscreenSdl2 *sdl_onscreen;
  SDL_Window *window;
  int width, height;
  SDL_WindowFlags flags;

  width = cogl_framebuffer_get_width (framebuffer);
  height = cogl_framebuffer_get_height (framebuffer);

  flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;

  /* The resizable property on SDL window apparently can only be set
   * on creation */
  if (onscreen->resizable)
    flags |= SDL_WINDOW_RESIZABLE;

  window = SDL_CreateWindow ("" /* title */,
                             0, 0, /* x/y */
                             width, height,
                             flags);

  if (window == NULL)
    {
      _cogl_set_error (error, COGL_WINSYS_ERROR,
                       COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                       "SDL_CreateWindow failed: %s",
                       SDL_GetError ());
      return FALSE;
    }

  SDL_SetWindowData (window, COGL_SDL_WINDOW_DATA_KEY, onscreen);

  onscreen->winsys = g_slice_new (CoglOnscreenSdl2);
  sdl_onscreen = onscreen->winsys;
  sdl_onscreen->window = window;

  return TRUE;
}
예제 #7
0
SDL_Renderer *
SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
{
    SDL_Renderer *renderer = NULL;
    int n = SDL_GetNumRenderDrivers();
    const char *hint;

    if (!window) {
        SDL_SetError("Invalid window");
        return NULL;
    }

    if (SDL_GetRenderer(window)) {
        SDL_SetError("Renderer already associated with window");
        return NULL;
    }

    hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
    if (hint) {
        if (*hint == '0') {
            flags &= ~SDL_RENDERER_PRESENTVSYNC;
        } else {
            flags |= SDL_RENDERER_PRESENTVSYNC;
        }
    }

    if (index < 0) {
        hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
        if (hint) {
            for (index = 0; index < n; ++index) {
                const SDL_RenderDriver *driver = render_drivers[index];

                if (SDL_strcasecmp(hint, driver->info.name) == 0) {
                    /* Create a new renderer instance */
                    renderer = driver->CreateRenderer(window, flags);
                    break;
                }
            }
        }

        if (!renderer) {
            for (index = 0; index < n; ++index) {
                const SDL_RenderDriver *driver = render_drivers[index];

                if ((driver->info.flags & flags) == flags) {
                    /* Create a new renderer instance */
                    renderer = driver->CreateRenderer(window, flags);
                    if (renderer) {
                        /* Yay, we got one! */
                        break;
                    }
                }
            }
        }
        if (index == n) {
            SDL_SetError("Couldn't find matching render driver");
            return NULL;
        }
    } else {
        if (index >= SDL_GetNumRenderDrivers()) {
            SDL_SetError("index must be -1 or in the range of 0 - %d",
                         SDL_GetNumRenderDrivers() - 1);
            return NULL;
        }
        /* Create a new renderer instance */
        renderer = render_drivers[index]->CreateRenderer(window, flags);
    }

    if (renderer) {
        renderer->magic = &renderer_magic;
        renderer->window = window;

        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
            renderer->minimized = SDL_TRUE;
        } else {
            renderer->minimized = SDL_FALSE;
        }

        SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);

        SDL_RenderSetViewport(renderer, NULL);

        SDL_AddEventWatch(SDL_RendererEventWatch, renderer);

        SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
                    "Created renderer: %s", renderer->info.name);
    }
    return renderer;
}
예제 #8
0
 void Stage::associateWithWindow(SDL_Window* wnd)
 {
     _window = wnd;
     SDL_SetWindowData(wnd, "_", this);
     addRef();
 }
예제 #9
0
static bool
_cg_winsys_onscreen_init(cg_onscreen_t *onscreen,
                         cg_error_t **error)
{
    cg_framebuffer_t *framebuffer = CG_FRAMEBUFFER(onscreen);
    cg_onscreen_sdl2_t *sdl_onscreen;
    SDL_Window *window;
    int width, height;
    SDL_WindowFlags flags;

#ifdef __ANDROID__
    {
        cg_display_t *display = framebuffer->dev->display;
        cg_display_sdl2_t *sdl_display = display->winsys;
        int win_width, win_height;

        if (sdl_display->have_onscreen) {
            _cg_set_error(error,
                          CG_WINSYS_ERROR,
                          CG_WINSYS_ERROR_CREATE_ONSCREEN,
                          "Android platform only supports a single "
                          "onscreen window");
            return false;
        }

        window = sdl_display->dummy_window;

        SDL_GetWindowSize(window, &win_width, &win_height);

        _cg_framebuffer_winsys_update_size(framebuffer, win_width, win_height);

        sdl_display->have_onscreen = true;
    }

#else /* __ANDROID__ */

    width = cg_framebuffer_get_width(framebuffer);
    height = cg_framebuffer_get_height(framebuffer);

    flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;

    /* The resizable property on SDL window apparently can only be set
     * on creation */
    if (onscreen->resizable)
        flags |= SDL_WINDOW_RESIZABLE;

    window = SDL_CreateWindow("" /* title */,
                              0,
                              0, /* x/y */
                              width,
                              height,
                              flags);
    if (window == NULL) {
        _cg_set_error(error,
                      CG_WINSYS_ERROR,
                      CG_WINSYS_ERROR_CREATE_ONSCREEN,
                      "SDL_CreateWindow failed: %s",
                      SDL_GetError());
        return false;
    }

#endif /* __ANDROID__ */

    SDL_SetWindowData(window, CG_SDL_WINDOW_DATA_KEY, onscreen);

    onscreen->winsys = c_slice_new(cg_onscreen_sdl2_t);
    sdl_onscreen = onscreen->winsys;
    sdl_onscreen->window = window;

    return true;
}