Advertisement

Creating multiple viewports in SDL/OpenGL project, how to implement?

Started by February 23, 2016 05:35 AM
2 comments, last by learnedseeker 8 years, 9 months ago

Obviously the window/event etc is handled by SDL.

The main game has basically 3.5 viewports. There is the main viewport, which is purely opengl; then there will be a GUI across the bottom, a notification bar on the left hand side, and a minimap in the bottom left side. Not sure if I should make that a separate context or attach it to the giu bar...

Question is, how exactly should I implement it? Should I create a glcontext for the main window viewport, then 3 seperate SDL_Renderer viewports for the other three windows? Or should I just kind of "toss" the overlays on top of the 1 single glcontext, and not render graphics that are behind the sdl viewports?

And uhh,... How exactly would you implement that? 3 separate renderer objects in SDL?

thanks,

learnedseeker

You could create different contexts but thats simply creating more windows.

I've implemented back in OpenGL 2.1 a split screen using the glViewPort and glScissor

Basically all you need to do is something like this:

glViewPort(0,0,Width,Height);

<render>

glViewPort(0,200,Width,

With SDL I think it's sdl_setClipRect,

I'm not familiar with sdl as im with openGl.

Advertisement

You don't need any additional OpenGL contexts for multiple viewports.

You only need to call glViewport() to change which part of the screen to render, and then render as usual. You'd, of course, do this for each viewport.

If I'm understanding you question correctly, you want to overlay an HUD and minimap (etc...) over your 3D scene (much like any FPS, for example).

To do this, you don't need to change viewports at all.

You just need to render your 2D HUD (and minimap) after you render the 3D scene.

Changing viewports is used for things like, a 3D model editor (Blender, 3DS Max, etc) that has several views for the scene your editing, like this:

Blender%20minion%202015-1.png

If you want to check out a tutorial for multiple viewports, you can go to to NeHe's.

It does use deprecated OpenGL, but the viewports part is still used i modern OpenGL.

EDIT: WhoopASword beat me to it rolleyes.gif


To do this, you don't need to change viewports at all.
You just need to render your 2D HUD (and minimap) after you render the 3D scene.

Okay so, you basically "toss" the GUI elements on top of the gl context. Cool. Gotcha.

This topic is closed to new replies.

Advertisement