Results 1 to 5 of 5

Thread: Multiple OpenGL Windows in one application

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2015
    Posts
    5

    Multiple OpenGL Windows in one application

    Hello,

    I would like to know how it would be possible to have multiple OpenGL windows in a single application. From what I can see at this moment is that the open GL commands do not take a specific handle so there does not seem to be a way to distinguish between instances within a single application.

    Thanks,

    James

  2. #2
    Do you mean multiple windows as in one window for each monitor or single monitor having multiple windows?

  3. #3
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678
    Every OpenGL API call operates on the current OpenGL context. Thus, the current OpenGL context is basically a global value (technically a thread-local value, since different threads can have different contexts be current) which all OpenGL calls use. The context contains all of the state for an instance of OpenGL. Contexts are usually created to be associated with a window, which is what their default framebuffer represents.

    So if you want to render to two windows, you generally create two separate OpenGL contexts (possibly sharing objects between them), then you switch which context is current to decide which to render to.

    However, the function to make a context current is not itself part of OpenGL; it's part of the interface between OpenGL and the windowing system. Most such interfaces (wglMakeCurrent and glXMakeCurrent at least) take an object that represents a window (on Win32, this is a window's device context; on X, it's a Display object).

    If that window has been properly set up to use OpenGL (typically by pixel format), then you can use a single context to render to both windows. You simply make the one context current with one window, render to that window, then make it current with the other window, then render to it.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2015
    Posts
    5
    Quote Originally Posted by EmJayJay View Post
    Do you mean multiple windows as in one window for each monitor or single monitor having multiple windows?
    I mean a single main window with two child windows contained inside of the main parent window which has their only OpenGL context. I don't really want to isolate this into independent threads at this point in time.

  5. #5
    I suggest to checkout glViewPort function. You only create one OpenGL context, create virtual windows which all have position, width and height as well as their elements to draw with in that window and just do X amount of draw calls by just switching the glViewPort values in between the draw calls. If you allow overlapping between the windows then try to put them in an array sorted "farthest" to "nearest" and start the drawing from the farthest.

    EDIT: If you wanted to create totally separate windows (window in this case is the same as you would have a web browser open) which each are in fullscreen or in windowed mode then you have to create multiple contexts with shared context from the first context since each .

Similar Threads

  1. Windows Menu Bar in an OpenGL Application
    By DreamScape in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-27-2014, 10:00 PM
  2. how OpenGL for a windows forms application in c++?
    By o0zkar in forum OpenGL: Windows
    Replies: 0
    Last Post: 03-13-2011, 10:17 PM
  3. Packaging an OpenGL application for Windows
    By Minotaar in forum OpenGL: Windows
    Replies: 3
    Last Post: 03-02-2010, 07:20 PM
  4. OpenGL application running under Windows XP
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-14-2003, 01:38 AM
  5. Two OpenGL Windows in an Application
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-17-2002, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean