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

Author Topic: How to create multiple window application  (Read 2397 times)

0 Members and 1 Guest are viewing this topic.

Hari bharath

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to create multiple window application
« on: January 24, 2009, 09:21:33 am »
I need to create a multiple window application. One window will be displaying data and other one will take inputs. So both windows have to be visible at a time.
I tried extending multiple thread example.

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace sf;

RenderWindow DispPan;
RenderWindow CtrlPan;
sf::Mutex GlobalMutex;

void initSetup();
void HandleEvents();
void HandleEventsC();
void MyThreadFunc(void* UserData)
{
sf::Image img;
sf::Sprite sprite;
GlobalMutex.Lock();
   img.LoadFromFile("sprite.tga");
   GlobalMutex.Unlock();
   sprite.SetImage(img);

   while(CtrlPan.IsOpened()) {
Lock lock(GlobalMutex);
       CtrlPan.SetActive(true);
  CtrlPan.Clear();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
  glLoadIdentity();
  CtrlPan.Draw(sprite);
       CtrlPan.Display();
  CtrlPan.SetActive(false);
  HandleEventsC();
}

}
int main() {
   initSetup();
   sf::Thread Thread1(&MyThreadFunc);
   Thread1.Launch();

   sf::Image img;
   sf::Sprite sprite;
   GlobalMutex.Lock();
   img.LoadFromFile("sprite1.jpg");
   GlobalMutex.Unlock();
   sprite.SetImage(img);

   while(DispPan.IsOpened()) {
       Lock lock(GlobalMutex);
  DispPan.SetActive(true);
  DispPan.Clear();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
  glLoadIdentity();
  DispPan.Draw(sprite);
  DispPan.SetActive(false);
       DispPan.Display();
  HandleEvents();
  //GlobalMutex.Unlock();
  //HandleEventsC();
   }
   Thread1.Wait();
   return 0;
}

void initSetup() {
    sf::WindowSettings settings;
    settings.DepthBits = 24;
    settings.StencilBits = 8;
settings.AntialiasingLevel = 2;
DispPan.Create(sf::VideoMode(800, 600, 32), "Display", sf::Style::Close, settings);
DispPan.SetActive(true);
DispPan.PreserveOpenGLStates(true);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glViewport(0,0,800,600); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

glOrtho(0.0f,800,600,0.0f,-1.0f,1.0f); // Create Ortho 640x480 View (0,0 At Top Left)

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

CtrlPan.Create(sf::VideoMode(800, 600, 32), "Control", sf::Style::Close, settings);
CtrlPan.SetActive(true);
CtrlPan.PreserveOpenGLStates(true);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glViewport(0,0,800,600); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

glOrtho(0.0f,800,600,0.0f,-1.0f,1.0f); // Create Ortho 640x480 View (0,0 At Top Left)

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

}


void HandleEvents() {
sf::Event event;
while(DispPan.GetEvent(event)) {
switch(event.Type) {
case sf::Event::Closed:
DispPan.Close();
break;
           
default:
break;
      }
   }
}

void HandleEventsC() {
sf::Event event;
while(CtrlPan.GetEvent(event)) {
switch(event.Type) {
case sf::Event::Closed:
CtrlPan.Close();
break;
           
default:
break;
      }
   }
}



Problem I am facing with this code is:
I am not able to move or highlight or close the window rendered last i.e. in the thread..

Some one please throw some light on this.  :?: