Can I draw to 2 viewports with one OpenGL context?

My app currently offers perspective projection as well as color anaglyph images of my 3D fractals.

I also want to teach it to create side-by-side stereograms.

I would like to be able to set up space on my application window for two identical sized viewports. I would set the viewport position to the left area of the window, draw my left eye view, then shift the viewport to the right area of the window and draw the right eye view. (or reverse them if the user has asked for a “cross-eyed” stereogram.

Will that work?

I create my OpenGL display object as a subclass of NSOpenGLView. I was thinking that I would continue to use one NSOpenGLView. For normal perspective projection or anaglyph display, I’d use the whole area of the NSOpenGLView to display my 3D image.

If the user asks for a side-by-side stereogram, I would set up the viewport for the left half, draw that, move the viewport to the right half of the view’s rectangle, then draw that half.

Would that work? I’m thinking that I would add logic in my -drawRect method that would figure out which of the left/right rectangles need updating, and set up the viewport appropriately for that part of the display.

Would it make more sense to create two separate NSOpenGLViews? That would play havoc with my class structure, as my subclass of NSOpenGLView saves all the settings for the view, along with the data needed to display it.

Using one view is fine. You’ll need to glScissor as well as glViewport [on some hardware?]

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.