0

我有两台具有不同本机分辨率且刷新率相同的显示器,在 Ubuntu 14.04 上使用 GPU Nvidia Titan X(驱动程序版本 375.66)。我想在第二台监视器上实时全屏显示捕获的图像,同时在主监视器上操作相机 GUI。

使用glfwand的最小复制OpenGL是:

#include <stdio.h>
#include <stdlib.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

GLFWwindow* open_window(const char* title, GLFWmonitor* monitor)
{
    const GLFWvidmode* mode = glfwGetVideoMode(monitor);

    glfwWindowHint(GLFW_RED_BITS, mode->redBits);
    glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
    glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);

    GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, title, monitor, NULL);
    if (!window)
        return NULL;

    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);

    glfwSwapInterval(1);
    glfwShowWindow(window);

    return window;
}

GLuint create_texture(GLFWmonitor* monitor)
{
    const GLFWvidmode* mode = glfwGetVideoMode(monitor);
    int width  = mode->width;
    int hieght = mode->height;

    char pixels[width * hieght];
    GLuint texture;

    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    for (int y = 0;  y < hieght;  y++)
        for (int x = 0;  x < width;  x++)
            pixels[y * width + x] = rand() % width;

    glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, hieght, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    return texture;
}

void draw_quad(GLuint texture)
{
    int width, height;
    glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height);

    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.f, 1.f, 0.f, 1.f, 0.f, 1.f);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glBegin(GL_QUADS);

    glTexCoord2f(0.f, 0.f);
    glVertex2f(0.f, 0.f);

    glTexCoord2f(1.f, 0.f);
    glVertex2f(1.f, 0.f);

    glTexCoord2f(1.f, 1.f);
    glVertex2f(1.f, 1.f);

    glTexCoord2f(0.f, 1.f);
    glVertex2f(0.f, 1.f);

    glEnd();
}

int main(int argc, char** argv)
{
    if (!glfwInit())
        exit(EXIT_FAILURE);

    // detect and print monitor information
    int monitor_count;
    GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);
    printf("Number of monitors detected: %d\n", monitor_count);
    if (monitor_count < 2)
    {
        printf("The second monitor is not connected.\n");
        return false;
    }

    // open a window fullscreen on second monitor
    GLFWwindow *window = open_window("Captured image", monitors[1]);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    // the loop
    while (!glfwWindowShouldClose(window))
    {
        // create the image (say, the captured image via camera App)
        GLuint texture = create_texture(monitors[1]);

        // show the image
        draw_quad(texture);
        glfwSwapBuffers(window);
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}

问题是,当我将当前焦点切换到相机 GUI 或终端时,会显示 Ubuntu 的标题栏。例如: 顶部:专注于窗口(完美全屏)。底部:关注终端;请注意,现在出现不需要的顶部标题栏(标记为红色)。全屏 不是全屏

X 把两台显示器当成一个大屏幕,所以我的屏幕截图有额外的黑色像素: 显示设定

我发现https://bugs.launchpad.net/unity/+bug/853865说第二个显示器的顶部面板无法隐藏,并且被认为是 Unity 的一个待实现的功能。

我怎样才能克服这个问题glfw?如果没有,还有其他OpenGL框架替代建议吗?我想保持多平台。

4

0 回答 0