Question

I'm using OpenTK to fiddle around with OpenGL a bit. Displaying an area on the entire window ain't no big deal anymore, but trying to get some sort of splitscreen mechanic in is. For one screen I'd do:

GL.Viewport(0, 0, window.Width / 2, window.Height);
GL.LoadIdentity();
GL.Ortho(0, 800, 600, 0, -1, 1);

In the GameWindow's resize event. How will I be able to display 2 of these next to eachother? And how can I make em both display a different area in my 'game'?

Was it helpful?

Solution

The easiest way IMO, is to use two viewports.

Lets say you have 2 views, left and right, and that you will render the left view before the right one.

This way, you must setup your left viewport and projection, perform the left view rendering, setup the right viewport and projection, perform the right view rendering:

void draw() {
    // update your models or perform anything else here.
    (...)
    // setup your left view projection:
    GL.MatrixMode(GL_PROJECTION);
    GL.LoadIdentity();
    GL.Viewport(0, 0, window.Width / 2, window.Height);
    GL.Ortho(0, 800, 600, 0, -1, 1);
    GL.MatrixMode(GL_MODELVIEW);
    // draw your left view.
    (...)
    // setup your right view projection:
    GL.MatrixMode(GL_PROJECTION);
    GL.LoadIdentity();
    GL.Viewport(window.Width / 2, 0, window.Width, window.Height);
    GL.Ortho(0, 800, 600, 0, -1, 1);
    GL.MatrixMode(GL_MODELVIEW);
    // draw your left view.
    (...)
    // perform any cleanup you need.
    // swap buffers!
}

This is a very simplified code, but I hope it will give you a hint on how to do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top