glDrawPixels没有填满窗口

时间:2019-04-02 03:29:38

标签: c++ opengl glfw

我在MacOS上使用GLFW,并且正在使用一些OpenGL调用在窗口中绘制图像。由于某些原因,glDrawPixels(...)无法填充窗口。这就是我所拥有的:

#define IMAGE_WIDTH     800
#define IMAGE_HEIGHT    600

int main(int argc, const char * argv[])
{
    GLFWwindow* window;
    int nx = IMAGE_WIDTH;
    int ny = IMAGE_HEIGHT;

    // One time during setup.
    unsigned int data[ny][nx][3];
    for( size_t y = 0; y < ny; ++y )
    {
        for( size_t x = 0; x < nx; ++x )
        {
            data[y][x][0] = ( rand() % 256 ) * 256 * 256 * 256;
            data[y][x][1] = 0;
            data[y][x][2] = 0;
        }
    }

    // Initialize the library
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(nx, ny, "FOO", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        glDrawPixels( nx, ny, GL_RGB, GL_UNSIGNED_INT, data );

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

我试图使其尽可能清晰。窗口尺寸和像素数据应基于所提供的相同尺寸,因此我不清楚为什么它似乎只占屏幕的四分之一。这是该窗口的屏幕截图:https://imgur.com/4kbFzij

0 个答案:

没有答案