How to generate two viewports in one window and one for 3D the other for 2D?

I want to show a 3D object in one view port, and the other 2D picture in another view port, but both are in one window.

Any suggestions?

Thanks

Hmm, off the top of my head:

use glViewport to denote where in the window the 3D stuff should be

enable and use glScissor to clip to the 3D area

set up your projection and modelview matrices

draw, but don’t swap if you’re double buffering

Now, start from the top again for the 2D area

Now swap.

I hope this helps…

Is it possible to have 4 viewports of the same world data in the same window (YES 3DSMAX style)? You could create 4 windows, but then you have to re-pass all data to the OpenGL RC.

this is a hot topic! cypher…i just got an app running doing exactly what you stated…4 views (front, top, side, 3-d) in one glut window (would work just fine in Win32). i made a viewport class that does all the work for me.

#include “vector.h” // my own Vector class (x,y,z)

class Viewport
{
public:
Viewport(){}

void init(int ox, int oy, int w, int h);
void lookAt(Vector e, Vector l, Vector u);
void set();
void wh(int w, int h);

private:
GLfloat aspect;
Vector eye;
int height;
Vector look;
Vector up;
int width;
};

//viewport.cc
void Viewport::init(int ox, int oy, int w, int h)
{
startx = ox;
starty = oy;
width = w;
height = h;
aspect = (GLfloat)width / (GLfloat)height;
}

void Viewport::lookAt(Vector e, Vector l, Vector u)
{
eye = e;
look = l;
up = u;
set();
}

void Viewport:set()
{
glViewport(startx, starty, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, aspect, 0.01, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z);
}

void Viewport::wh(int w, int h)
{
width = w;
height = h;
aspect = (GLfloat)width / (GLfloat)height;
set();
}

// main.cpp

int width = 800;
int height = 600;

Viewport front; // lower-left
Viewport top; // upper-left
Viewport side; // lower-right
Viewport camera; // upper-right

void init()
{

front.init(0, 0, width / 2, height / 2);
front.lookAt(Vector(0, 0, 40), Vector(0, 0, 0), Vector(0, 1, 0));
top.init(0, height / 2, width / 2, height / 2);
top.lookAt(Vector(0, 40, 0), Vector(0, 0, 0), Vector(0, 0, -1));
side.init(width / 2, 0, widh / 2, height / 2);
side.lookAt(Vector(40, 0, 0), Vector(0, 0, 0), Vector(0, 1, 0));
camera.init(width / 2, height / 2, width / 2, height / 2);
camera.lookAt(Vector(30, 30, 30), Vector(0, 0, 0), Vector(-0.577, 0.577, -0.577));

}

void resize(int w, int h)
{
if (h == 0)
h = 1;
width = w;
height = h;
front.wh(width / 2, height / 2);
top.wh(width / 2, height / 2);
side.wh(width / 2, height / 2);
camera.wh(width / 2, height / 2);
}

void display()
{

front.set();
drawGeometry();
top.set();
drawGeometry();
side.set();
drawGeometry();
camera.set();
drawGeometry();
glutSwapBuffers();
}

this way, you can use glut’s passive motion callback to identify which window you were in, panning and zooming would be easy (altering the eye, look vectors) it would be a little trickier fopr the 3-d view. maybe using quaternions to make the camera do a 3-D “circle-strafe” around the origin. and having each viewports origin and w/h, you can use gluUnProject to get the window coordinates to draw 4 separate grids. just some thoughts. happy coding

b

i guess 3-D circle-strafing would be sphere-strafing

b

good idea - thanx coredump
Though, you don’t avoid passing the geometry 4 times to OpengL (I don’t believe there is a way to do so), but you don’t need to manipulate 4 windows, so I believe it worths using it.

B