2

我正在尝试将 SDL 2 用于 iOS 应用程序。我正在构建 libSDL2.a 并将其添加到我的项目中。此外,我将所有标题添加到应用程序项目中。对于初始化,我使用下一个代码:

/* initialize SDL */ 
if (SDL_Init(SDL_INIT_VIDEO) < 0) { 
        fatalError("Could not initialize SDL"); 
} 
window = SDL_CreateWindow(NULL, 0, 0, m_curScreenResolutions.deviceScreenResolution.size.height, 
                              m_curScreenResolutions.deviceScreenResolution.size.width, 
                              SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | 
                              SDL_WINDOW_BORDERLESS); 

    renderer = SDL_CreateRenderer(window, -1, 0);

然后为了绘制我的图像,我使用下一个代码:

struct displayImage 
{ 
    float x, y;                
    SDL_Texture *texture; 
    long width, height; 

}; 

SDL_Rect srcRect; 
    SDL_Rect dstRect; 

    for (int i = 0; i < [m_imagesForDisplaying count]; i++) 
    { 
        NSValue *value = [m_imagesForDisplaying objectAtIndex:i]; 
        displayImage preImage; 
        [value getValue:&preImage]; 

        srcRect.x = 0; 
        srcRect.y = 0; 
        srcRect.w = preImage.width; 
        srcRect.h = preImage.height; 

        dstRect.w = preImage.width; 
        dstRect.h = preImage.height; 
        dstRect.x = preImage.x; 
        dstRect.y = preImage.y; 
        SDL_RenderCopy(inputRenderer, preImage.texture, &srcRect, &dstRect); 
    } 
    /* update screen */ 
    SDL_RenderPresent(inputRenderer);

图片绘制得很完美,但在绘制后我看不到任何 iOS 原生对象(UIView,UIButton等),没有应用程序 UI,即使我以编程方式添加这些对象也是如此。我尝试在创建 SDL 的窗口 + 渲染器后添加 UIKit 控件。例如,对于添加 UIKit 控件,UIView我使用下一个代码:

UIView* newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
newView.backgroundColor = [UIColor yellowColor]; 
[self.view addSubView:newView];

哪里 self 是 UIViewController。

然后我尝试UIWindowSDL_SysWMinfo代码中获取:

// Retrieve SDL's root UIViewController (iOS only!) 
// This function is completely NOT guaranteed to work in the future. 
// Use it at your own risk! 
UIViewController * GetSDLViewController(SDL_Window * sdlWindow) 
{ 
    SDL_SysWMinfo systemWindowInfo; 
    SDL_VERSION(&systemWindowInfo.version); 
    if ( ! SDL_GetWindowWMInfo(sdlWindow, &systemWindowInfo)) { 
        // consider doing some kind of error handling here 
        return nil; 
    } 
    UIWindow * appWindow = systemWindowInfo.info.uikit.window; 
    UIViewController * rootViewController = appWindow.rootViewController; 
    return rootViewController; 
} 

但是当我尝试初始化时SDL_SysWMinfo我有一个嵌套问题: https ://docs.google.com/open?id=0B1IEde1HB7cUSVE1NGpVNDRHTUU

有人有什么想法吗?

4

0 回答 0