Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 与测试床应用程序相比,调试绘图Box2D非常大_C++_Opengl_Sdl_Box2d - Fatal编程技术网

C++ 与测试床应用程序相比,调试绘图Box2D非常大

C++ 与测试床应用程序相比,调试绘图Box2D非常大,c++,opengl,sdl,box2d,C++,Opengl,Sdl,Box2d,我正在尝试在自己的游戏中设置Box2D。我现在已经有了一些代码,我在游戏中添加了一个DebugDraw类,它可以绘制由Box2D创建的多边形 现在,如果我将其与来自测试床应用程序的代码(我复制了一些代码来重新创建OneSidedPlatform测试)进行比较,它在我的游戏中显示的要比在原始应用程序中显示的大得多 我想这与OpenGL/SDL本身有关,所以这里有一些代码: 这将在我的游戏中设置OpenGL: // START SDL if (SDL_Init(SDL_INIT_VIDEO) !=

我正在尝试在自己的游戏中设置Box2D。我现在已经有了一些代码,我在游戏中添加了一个DebugDraw类,它可以绘制由Box2D创建的多边形

现在,如果我将其与来自测试床应用程序的代码(我复制了一些代码来重新创建OneSidedPlatform测试)进行比较,它在我的游戏中显示的要比在原始应用程序中显示的大得多

我想这与OpenGL/SDL本身有关,所以这里有一些代码:

这将在我的游戏中设置OpenGL:

// START SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
    logSDLError(std::cout, "SDL_Init");
    return 1;
}

// SETUP OPENGL SETTINGS (THEY CAN BE SET WITHOUT ACTUALLY BEING USED)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

// CREATE A WINDOW
m_pWindow = SDL_CreateWindow("SDL/OpenGL Game Client - With Networking Library", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
if (m_pWindow == nullptr)
{
    logSDLError(std::cout, "CreateWindow");
    return 2;
}

m_GlContext = SDL_GL_CreateContext(m_pWindow);
if( m_GlContext == NULL )
{
    printf( "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() );
}
else
{
    //INITIALIZE GLEW
    glewExperimental = GL_TRUE; 
    GLenum glewError = glewInit();
    if( glewError != GLEW_OK )
    {
        printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

// CREATE A RENDERER TO DRAW THE WINDOW TO
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (m_pRenderer == nullptr)
{
    logSDLError(std::cout, "CreateRenderer");
    return 3;
}
这是Box2D对象的创建(从原始测试应用程序复制):


我不知道我要在哪里改变我的游戏观或Box2D的规模。我还将我的OpenGL代码与来自Testbed应用程序的代码进行了比较,我没有发现任何真正的差异。

请查看Testbed应用程序Main.cpp中的此方法:

static void Resize(int32 w, int32 h)
{
    ...
    // those are the lines you may consider incorporating into your code:

    b2Vec2 lower = settings.viewCenter - extents;
    b2Vec2 upper = settings.viewCenter + extents;

    // L/R/B/T
    gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
}
谢谢:)这确实解决了问题!我真的需要研究如何在游戏中使用矩阵。。。
static void Resize(int32 w, int32 h)
{
    ...
    // those are the lines you may consider incorporating into your code:

    b2Vec2 lower = settings.viewCenter - extents;
    b2Vec2 upper = settings.viewCenter + extents;

    // L/R/B/T
    gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
}