Viewport or multiple viewport in a window!

Hi,

I’m sorry, but I don’t speak very good english…

I try to use multiple viewport in a windows… how can I use viewport A and after use viewport B. and viewport A again… and so one!..

I have different projection transformation for differente viewport…

Somebody have a idee?

Thank you a lot!

Best regards
Jérôme

try someit like this its one window devided up into 4 different regions. its a quick modify copy sio there might be mistakes but it should hopefully be enuf info

glViewport(0, 0, w/2, h/2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, (w>h) ? w/h : h/w , 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0,500,500, 0,0,0.1, 0,1,0);
glCallList(bauulmodel);

glViewport(0, h/2, w/2, h/2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, (w>h) ? w/h : h/w , 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,600, 0,0.1,0, 0,1,0);
glCallList(bauulmodel);

glViewport(w/2, h/2, w/2, h/2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, (w>h) ? w/h : h/w , 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(600,0,0, 0,0.1,0, 0,0,1);
glCallList(bauulmodel);

// 3d in the lowerright viewpoint
glViewport(w/2, 0, w/2, h/2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, (w>h) ? w/h : h/w , 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glCallList(bauulmodel);

OK thank a lot Zed…

But how can I use the first Viewport and after I use the second, I’d like to recall the first! How can I do this… ? I try to use the Rendering Context… It’s correct?

Thank you a lot

Best regards
Jérôme

im not sure if i understand fully what u want.
u need to render all 4 windows everyframe all 4 corners are independant from each other here im happening to draw the same thing from 4 different angles but u can just as easily draw a house in one corner + a car in another etc.
this is all one window thus one windoze RC

position the camera
gluLookAt(0,500,500, 0,0,0.1, 0,1,0);
draw whatever u want eg in this case a model
glCallList(bauulmodel);

Hi…

Thank you for your response.

I’m sorry, but it’s difficulte to explaine in english for me!

For exemple if I want to cute the windows in 2 viewport. I want to draw a car in the first viewport and a house in the second.

After that how can I change (for exemple) the colour of the car or the position of the camera in the first camera?

Thank you for your help
Best regards

Jérôme

i won’t swear on it, but i think you must obey to the law “one rendering context is bound to a single device context”

so, you can’t have two separate RC rendering on the same window.

if you wish to do so, you have to develope some workaround, like having two session of the same engine, rendering to the same RC but on different viewport.

…and then you have to manage the needed decoupling…

DMY

Originally posted by Boubou:
[b]

For exemple if I want to cute the windows in 2 viewport. I want to draw a car in the first viewport and a house in the second.

After that how can I change (for exemple) the colour of the car or the position of the camera in the first camera?

[/b]

If you have a display function like so…

void Display()
{
SetFirstViewport(); // using glViewport
DrawCar();
SetSecondViewport();
DrawHouse();
}

Assuming your DrawCar pulls the color from something such as a global variable, you could then just change that global variable and call the Display function again to get the new car color. The same thing goes for any transformations you have applied to your objects. Keep track of what they are somewhere, change them, then redraw the scene.

Thank you for your response DMY…

OK… I don’t use 2 RC in the same window… but for the moment, I don’t use just 1 RC… I put the code just here… somebody help me? Where is not correct? The compilaton is OK… but there are anything in the window.

void SetDCPixelFormat (HDC hDC)
{
int nPixelFormat;
int version;

//version = GetVersionEx();
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,
8,0,0,0,0,0,0,0,0,0,0,0,0,0,32,
0,0,PFD_MAIN_PLANE,
0,0,0,0 };

// Choose a pixel format that best matches that described in pfd
nPixelFormat = ChoosePixelFormat(hDC, &pfd);

// Set the pixel format for the device context
SetPixelFormat(hDC, nPixelFormat, &pfd);

DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
}

void display(void)
{
GLfloat mat_solid1 = { 0.75, 0.75, 0.0, 1.0 };
GLfloat mat_zero1 = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_solid2 = { 0.0, 0.75, 0.75, 1.0 };
GLfloat mat_zero2 = { 0.0, 0.0, 0.0, 1.0 };
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix ();
glTranslatef (-0.15f, -0.15f, solidZ);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_zero2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_solid2);
glCallList (sphereList);
glPopMatrix ();

SwapBuffers(premierContext);

void reshape(int we, int he)
{
int w = we/2;
int h = he/2;

SetDCPixelFormat(premierContext);
ContextRendu = wglCreateContext(premierContext);
wglMakeCurrent(premierContext,ContextRendu);
glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
else
glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
[/b]

Thank you a lot for your help!

Best regards
Jérôme

Oh… yes! Thank you Deiussum… it’s a good idee. I don’t think that…It’s too simple.

If I use your solution, I always can redraw all the scene… There don’t have a solution for not all redraw?

Thank you a lot for your help

Best regards
Jérôme

You could probably get by with just redrawing one of the viewports if only one of them change.