OStack程序员社区-中国程序员成长平台

标题: ios - SDL 和 iOS main() 方法冲突 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:37
标题: ios - SDL 和 iOS main() 方法冲突

我了解到 SDL 项目需要 main() 方法来运行循环,代码如下:

#include "SDL.h"

int main(int argc, char *argv[])
{
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("%s\n", SDL_GetError());
    }

    SDL_Window *window = SDL_CreateWindow(NULL, 0, 0, 320, 640, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
    SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, 0);

    SDL_Surface *bmp_surface = SDL_LoadBMP("space.bmp");
    SDL_Texture *space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
    SDL_FreeSurface(bmp_surface);

    SDL_RenderCopy(renderer, space, NULL, NULL);
    SDL_RenderPresent(renderer);

    int done = 0;
    while (!done) {
        Uint32 startFrame = SDL_GetTicks();
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                done = 1;
            }
        }
        Uint32 endFrame = SDL_GetTicks();

        Sint32 delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
        if (delay < 0) {
            delay = 0;
        } else if (delay > MILLESECONDS_PER_FRAME) {
            delay = MILLESECONDS_PER_FRAME;
        }
        SDL_Delay(delay);
    }

    SDL_DestroyTexture(space);
    SDL_Quit();

    return 0;
}

而iOS项目也需要main()方法,代码如下:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

现在我需要将 SDL 库集成到 iOS 项目中,但需要两个 main() 方法。如何?如果是,有人可以显示更多代码吗?谢谢。



Best Answer-推荐答案


你需要获取 SDLMain.m 和 SDLMain.h

在此处了解更多信息 - http://beefchunk.com/documentation/lib/libSDL/faq/FAQ-MacOSX.html

关于ios - SDL 和 iOS main() 方法冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23452160/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4