0

I have two monitors with different native resolutions at the same refresh rate, with GPU Nvidia Titan X (driver version 375.66) on Ubuntu 14.04. I would like to real-time show the captured image full screen on the second monitor, and at the same time operating the camera GUI on the main monitor.

A minimum reproduction using glfw and OpenGL is:

#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);
}

The problem is, the title bar of Ubuntu shows up when I switch the current focus to either the camera GUI or the terminal. For example: full screen not full screen Top: focus on the window (full screen perfectly). Bottom: focus on the terminal; note the unwanted top title bar now appears (marked in red).

X takes the two monitors as one big screen, so there are extra black pixels of my screen shots: Display setting

I found https://bugs.launchpad.net/unity/+bug/853865 which says the top panel on the second display cannot be hided, and is considered a to-be-implemented feature for Unity.

How can I overcome this issue within glfw? If not, any other OpenGL framework alternatives suggestions? I would like to keep multi-platform.

WDC
  • 334
  • 1
  • 3
  • 14
  • Is this about unity or pure OpenGL? – BDL Sep 24 '17 at 19:26
  • @BDL I think it is OpenGL. But I am not sure if Unity gets invovled or not. – WDC Sep 24 '17 at 19:33
  • For future reference: I (kind of) solved the problem by switching from Unity to Gnome, in which the top panel is naturally hided on the second monitor. – WDC Sep 26 '17 at 07:58
  • Wait, are you talking about [tag:ubuntu-unity] or [tag:unity3d]? This are completely different things. Please read the tag descriptions and choose the correct one. Sorting questions into categories that they don't belong to makes it harder for you to get answers. I, for example, can answer OpenGL questions but have little knowledge about unity3d. So if you tell me this question involves unity3d I'll skip it. – BDL Sep 26 '17 at 08:38
  • @BDL Oh my bad. My apology to the community. Thanks for the reminding. – WDC Sep 26 '17 at 08:48

0 Answers0