Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Second window not responding  (Read 1339 times)

0 Members and 1 Guest are viewing this topic.

shotoreaper

  • Newbie
  • *
  • Posts: 11
    • View Profile
Second window not responding
« on: May 22, 2013, 05:12:50 pm »
Hi!
When i create two windows, the second window not responding:
#include <iostream>
#include "SFML/Window.hpp"
#include "SFML/OpenGL.hpp"

using namespace std;

// http://www.sfml-dev.org/tutorials/2.0/window-opengl.php

void SetWindow(sf::Window &window, int x, int y, int w, int h)
{
    // cambia la posicion de la ventana
    window.setPosition(sf::Vector2i(x,y));

    window.setSize(sf::Vector2u(w,h));

    window.setTitle("SFML window");

    sf::WindowHandle handle = window.getSystemHandle();

    window.setFramerateLimit(30);
}

sf::ContextSettings SetGLWindow()
{
    sf::ContextSettings settings;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.antialiasingLevel = 4;
    settings.majorVersion = 3;
    settings.minorVersion = 0;
    return settings;

}

void renderingThread(sf::Window* window)
{
    // activa el contexto de ventana
    window->setActive(true);

    // el bucle de renderizado
    while(window->isOpen())
    {
        // draw...

        // Limpiamos los buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // termina el actual frame ( internamente intercambia el front y back buffer)
        window->display();
    }
}

int main()
{
    sf::Window window1(sf::VideoMode(800,600), "Window1",sf::Style::Default, SetGLWindow());

    sf::Window window2(sf::VideoMode(512,512), "Window2",sf::Style::Default, SetGLWindow());

    // Configuramos la ventana
    SetWindow(window1,10,50,800,600);
    SetWindow(window2,100,50,512,512);

    // desactivamos el OpenGL context
    window1.setActive(false);
    window2.setActive(false);


    // Iniciamos el RenderingThreading
    sf::Thread renderthreadWindow1(&renderingThread, &window1);
    renderthreadWindow1.launch();
    sf::Thread renderthreadWindow2(&renderingThread, &window2);
    renderthreadWindow2.launch();

    // corre el programa mientras la ventana este abierta
    while(window1.isOpen())
    {
        // Comprueba todos los eventos de ventana que fueron activados durante la ultima iteracion del bucle
        sf::Event event;
        while(window1.pollEvent(event))
        {
            // evento de "peticion de cerrado": cerramos la ventana
            if(event.type == sf::Event::Closed)
                window1.close();

            if(event.type == sf::Event::Resized)
                glViewport(0,0,event.size.width, event.size.height);
        }
    }

    while(window2.isOpen())
    {
        // Comprueba todos los eventos de ventana que fueron activados durante la ultima iteracion del bucle
        sf::Event event;
        while(window2.pollEvent(event))
        {
            // evento de "peticion de cerrado": cerramos la ventana
            if(event.type == sf::Event::Closed)
                window2.close();

            if(event.type == sf::Event::Resized)
                glViewport(0,0,event.size.width, event.size.height);
        }
    }

    return 0;
}

 
« Last Edit: May 23, 2013, 11:33:06 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Second window not responding
« Reply #1 on: May 22, 2013, 06:17:00 pm »
You must handle both windows' events in the same loop. Your second loop is never executed as long as the first window is alive.
Laurent Gomila - SFML developer

shotoreaper

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Second window not responding
« Reply #2 on: May 23, 2013, 11:14:20 am »
Yeah! Its works! Thank you! ;D