4
\$\begingroup\$

I'm trying to use GLFW3 to develop VJing application. So basic idea is use two windows:

1st window for fullscreen projection on secondary monitor (basically projector)

2nd window for (hopefully) fullscreen GUI.

It does not have to share context, as GUI window will be just using libRocket for controlling content, recieving MIDI & OSC commands, etc.

Problem is that so far, when I switch projection window on second monitor to fullscreen, it runs, but as soon as I move mouse to primary monitor and click somewhere, projection window gets minimized. Also, GUI window gets a poor framerate.

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

using namespace std;

void errorCallback(int error, const char *description){
fputs(description, stderr);
}

static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods){
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
{
    glfwSetWindowShouldClose(window, GL_TRUE);
}
}


int main(){


glfwSetErrorCallback(errorCallback);
if (!glfwInit())
{
    exit(EXIT_FAILURE);
}

int MonitorCount;
GLFWmonitor ** monitors = glfwGetMonitors(&MonitorCount);

//GLFWvidmode* modes = glfwGetVideoModes(monitors, &MonitorCount); 

GLFWwindow *window;
window = glfwCreateWindow(1024, 768,"Projection", monitors[0], NULL);
GLFWwindow *controls;
controls = glfwCreateWindow(1024, 768, "Controls", glfwGetPrimaryMonitor(), NULL);

glfwSetKeyCallback(window, keyCallback);
while(!glfwWindowShouldClose(window)){


     //// PROJECTION WINDOW
    glfwMakeContextCurrent(window);

    float ratio;
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    ratio = width / (float) height;
    glViewport(0,0, width, height);
    glClear(GL_COLOR_BUFFER_BIT);

      glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
    glBegin(GL_TRIANGLES);
    glColor3f(1.f, 0.f, 0.f);
    glVertex3f(-0.6f, -0.4f, 0.f);
    glColor3f(0.f, 1.f, 0.f);
    glVertex3f(0.6f, -0.4f, 0.f);
    glColor3f(0.f, 0.f, 1.f);
    glVertex3f(0.f, 0.6f, 0.f);
    glEnd();

    //// ---- CONTROL WINDOW ---- 
    glfwMakeContextCurrent(controls);
    glfwGetFramebufferSize(controls, &width, &height);
    ratio = width / (float) height;
    glViewport(0,0, width, height);
    glClear(GL_COLOR_BUFFER_BIT);

          glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef((float) glfwGetTime() * 100.f, 0.f, 0.f, 1.f);
    glBegin(GL_TRIANGLES);
    glColor3f(0.f, 0.f, 0.f);
    glVertex3f(-0.6f, -0.4f, 0.f);
    glColor3f(0.f, 1.f, 0.f);
    glVertex3f(0.6f, -0.4f, 0.f);
    glColor3f(0.f, 0.f, 1.f);
    glVertex3f(0.f, 0.6f, 0.f);
    glEnd();

    glfwSwapBuffers(controls);
    glfwSwapBuffers(window);


    glfwPollEvents();
}

glfwDestroyWindow(controls);
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);

}

I'm on Win7 / VS2012 using nVidia 680m

\$\endgroup\$
  • \$\begingroup\$ Did you already resolve why it has low fps when multi window? I'm also planning to make an app that has two monitors at the same time using glfw3. \$\endgroup\$ – mr5 Mar 10 '14 at 2:33
  • \$\begingroup\$ I think our assumptions here were wrong. I try to unlock the fps from 60 on every loop by putting this inside the loop glfwSwapInterval(GL_FALSE); and I get a high fps but still it's glitching, any idea why? \$\endgroup\$ – mr5 Mar 10 '14 at 2:57
1
\$\begingroup\$

Set the GLFW_AUTO_ICONIFY window hint to false to disable automatic iconification of full screen windows.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.