Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9052399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:09:39+00:00 2026-06-16T13:09:39+00:00

How do I create two SFML windows, and then draw to both of them

  • 0

How do I create two SFML windows, and then draw to both of them using OpenGL?

If you ever wondered how to create and use two or more SFML windows with OpenGL, then here is the solution. I was not able to find the information on how to do this anywhere else on the internet, so here it is. I hope this will be useful to someone, someday.

As an aside, you might want to know why this might be a useful thing to do:

It is a very useful thing for physicists to be able to show animations of systems to other people, because we often want to program a demonstration of something to help us explain it. A trivial example would be the behaviour of gas particles in a box. In on window, particles would be drawn and move about as they do in the real world thanks to our fancy physics calculations, and in the other window, graphs might be drawn to show the total energy inside the box or average particle velocity (temperature) and other such things. Another good example would be a simulation of the solar system. Data about planets can be drawn to one window, and a view of the solar system can be drawn to another.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:09:40+00:00Added an answer on June 16, 2026 at 1:09 pm

    There are several steps required to make this work. The subtly with multiple windows lies with the fact that you have to resize each window before drawing to it, or at least this is the easiest way of doing things. With one window, you would only resize after the window was created, and every time it was resized or reshaped. You might argue that there are better ways of doing this by pushing and popping from the matrix stack, in which case, please comment and leave other answers.

    Firstly you need to declare two sfml windows, as you would expect: sf::Window window, window2; (Probably you should check that they are both closed at end of program execution too!)

    Secondly, implement a resize method for both. Something like this will do.

    /// Window
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
    // Set matrix mode back again
    glMatrixMode(GL_PROJECTION);
    // Reset matrix stack
    glLoadIdentity();
    // Set drawing surface properties - either Perspective or Orthographic
    ///gluPerspective(45.0, (double)w / (double)h, 1.0d, 100.0d);
    glOrtho(-50.0d, 50.0d, -50.0d, 50.0d, -10.0d, 10.0d);
    // Put matrix mode back
    glMatrixMode(GL_MODELVIEW);
    

    And now the other:

    /// Window2, which can be different to window!
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
    // Set matrix mode back again
    glMatrixMode(GL_PROJECTION);
    // Reset matrix stack
    glLoadIdentity();
    // Set drawing surface properties - either Perspective or Orthographic
    ///gluPerspective(45.0, (double)w / (double)h, 1.0d, 100.0d);
    glOrtho(-50.0d, 50.0d, -50.0d, 50.0d, -10.0d, 10.0d);
    // Put matrix mode back
    glMatrixMode(GL_MODELVIEW);
    

    You might want to put these two blocks of code in two different functions, and perhaps implement a camera class of your choice. The reason for this is that you will need to call the resize function for each window before drawing to it using the various OpenGL drawing methods.

    Now for the fun part. Before drawing call the resize method for the window you are going to draw to. Then if you need to call glMatrixMode(GL_MODELVIEW); (just in case!), glLoadIdentity();, and glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);. Obviously, if you dont want to clear the screen, don’t call glClear or glLoadIdentity, if you dont want to reset the matrix transformation stack…

    Now do your drawing: glBegin() and glEnd() and all the other things you need to do.

    Finally, call window.Display() or window2.Display(), depending on which one you were just drawing stuff to. Now go back to the fun part above, and call the resize method for the other window, and continue doing everything you need to do for this second window, exactly as for the first!

    Now enjoy OpenGL SFML programming with multiple windows. You might like to plonk a load of windows into a vector or other fancy container too.

    [EDIT] For some reason sf::Windows are non-copyable, which means you cannot push_back() them into a container like a deque or vector. This is probably due to some OpenGL specific things, which would “go wrong” if you tried to copy all the bits from one window class to another. (Perhaps?) Instead, a sf::Window* = new sf::Window[number_of_windows] and unsigned int number_of_windows = 2 will suffice, although it is not as nice…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create two method to serialize/deserialize classes using Json.Net and save/load them
I need to create two (or more) WPF windows from the same process. But
If I create two lists and zip them a=[1,2,3] b=[7,8,9] z=zip(a,b) Then I typecast
I need to create two separate linked lists and then compare them. However, when
I want to create two and three dimensional vectors using a constructor in a
I need to create two radio buttons using RAZOR in MVC3 C#. Shown below
I want to create two JQuery functions. One of which will use the data
I want to create two dimensional array of buttons in windows form. I have
I create two standard vector of unique_ptr: std::vector<std::unique_ptr<Student>> students; std::vector<std::unique_ptr<Teacher>> teachers; Then, I create
I'm trying to create two buttons that using the hover event, hide some divs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.