PDA

View Full Version : Rendering to 4 different windows



bavarianbasti
13th October 2013, 22:07
Hi everyone,
I am working on an OpenGL project where I am rendering my scene from 4 different views (perspective, top, front and side). Right now, I am using 4 camera settings and render the scene once per frame with each camera , each camera drawing to a quarter of the viewport, i.e. it's a quadsplit.
That is working perfectly but I was wondering whether it is possible to render each view into a different window (e.g. QWindow) so that I can resize and move them around completely independent of each other.
Since I am loading and changing massive amounts of data during runtime, I don't want to create 4 running instances with equal data and different camera settings, but to keep one program which simply renders to 4 different windows using different camera settings.
Does anyone know whether there is an easy way to set that up?

I would really appreciate your help.

wysota
14th October 2013, 08:07
You can share the OpenGL context between different windows so that all data, including GL programs are available to all four windows. Then you just render what you want four times using different matrices (or other settings).

bavarianbasti
14th October 2013, 12:51
Thanks for the fast answer.
I have been trying to get that to work. It seems like Qt5 has more options than qt 4.8. Unfortunately I have to use 4.8 for my program because it must interact with several 4.8 widgets.

Is there any good example showing how to share contexts? I can't find any.

I tried to set up a simple program but I cannot get it to work. I created a simple class (GLWidget) deriving from QGLWidget. It loads in shaders and only draws a single triangle. In my main.cpp, I was trying to create a new QGLWidget from my context which should also show the triangle.

The code:

-------------------------------------------------------------
#include <QApplication>
#include "glwidget.h"
#include "QGLContext"
#include <iostream>
using namespace std;


int main(int argc, char *argv[])
{
QApplication *a = new QApplication(argc, argv);
GLWidget *myW = new GLWidget;
myW->show();


QGLContext *myContext = new QGLContext(myW->context()->format(), myW->context()->device());
cout << "Create: " << myContext->create(myW->context()) << endl;

QGLWidget *test = new QGLWidget(myContext, 0,0,0);

cout << "Valid: " << myW->context()->isValid() << " " << test->context()->isValid() << endl;

test->show();


return a->exec();
}
-------------------------------------------------------------

Unfortunately my test widget only shows a white screen and I get the following output:

Create: 1
QGLWidget::setContext: Context must refer to this widget
Valid: 1 0


Do you happen to know what I need to change in order to make it work?
Thanks a lot