SDL:Xcode上的未知类型SDL_Window

时间:2014-09-08 21:16:43

标签: c++ sdl osx-yosemite

我从LibGDX和Java(最后!)转移到C ++和SDL。但是,在关注了许多设置视频和帖子后,我总是得到同样的错误:

Unknown type name SDL_Window
Unknown type name SDL_GLContext

非常感谢帮助。

   #include <iostream>
#include <SDL2/SDL.h>

#ifdef __IPHONEOS__
#   include <SDL2/SDL_opengles.h>
#else
#include <SDL2/SDL_opengl.h>
#endif

int width = 800;
int height = 600;

int main(int argc, char * argv[])
{
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window* window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);

    if(!window)
    {
        std::cerr << "Error failed to create window!\n";
        return 1;
    }

    SDL_GLContext context = SDL_GL_CreateContext(window);

    if(!context)
    {
        std::cerr << "Error failed to create a context\n!";
        return 2;
    }

    SDL_Event event;
    bool running = true;

    glClearColor(1, 0, 0, 1);
    while(running)
    {

        while(SDL_PollEvent(&event))
        {

            running = event.type != SDL_QUIT;
        }

        glClear(GL_COLOR_BUFFER_BIT);

        SDL_GL_SwapWindow(window);
    }


    SDL_GL_DeleteContext(context);


    SDL_DestroyWindow(window);


    SDL_Quit();

    return 0;
}

(这只是一个测试脚本,看它是否有效)

SDL2 - MacOSX 10.10 Beta - Xcode 6 Beta

2 个答案:

答案 0 :(得分:0)

对我而言,这听起来像您已下载框架等并将其置于构建阶段,但可能您忘记更改其他标头和框架搜索路径的项目设置。

如果您想轻松入手,本教程有一个指向Xcode模板的链接,该模板可从Github下载,该模板将具有相关的项目设置。

答案 1 :(得分:0)

检查您的构建设置。提到的模板(在另一个答案中)使用以下标题搜索路径:/usr/include /usr/local/include

我添加了第三个:/opt/local/include/SDL2

请注意,第三个来自MacPorts