Archived

This topic is now archived and is closed to further replies.

orcblood

Viewport frames

Recommended Posts

Im wondering how its possible to create a frame between my four viewports with open gl. Ive tried to create lines that spread between the viewports but they didnt work, about the cneter of the screen (where the edge of the two viewports would go) they disappear for some odd reason. So, is there a command for adding a frame to the viewports? Or is it possible to change the background color of each viewport that would be different than the glClearcolor? Since it seems to change it for every viewport, which I dont want... Im so lost right now... Hopefully someone can help me with atleast a tip.

Share this post


Link to post
Share on other sites
A viewport in OpenGL is nothing more than a transformation from normalized device coordinates to window coordinates. There''s nothing else the viewport does.

If you want to draw lines outside the viewports (I assume you want the border drawn just outside the viewport, on the outside of the edge), then make sure you draw the lines with the correct viewport and matrix settings. Normally, this would be a viewport that covers the entire window and the usual "2D" setup.

Another thing to keep in mind is that the viewport does not perform scissoring. That means fragmens generated outside the viewport (for example by glDrawPixels) are not rejected, and glClear is not affected by the viewport bounds. You have to use a scissor box for that. Look up glScissor.

Share this post


Link to post
Share on other sites
Ok, Ive added a scissor to the program, however, when I attempt to line it up with the top of the window, nothing appears... My code for DragGL is below, prehaps Ive made it so it lines up with the wrong y value... I dont really know.


int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
RECT rect; // Holds Coordinates Of A Rectangle

GetClientRect(hWnd, &rect); // Get Window Dimensions
int window_width=rect.right-rect.left; // Calculate The Width (Right Side-Left Side)
int window_height=rect.bottom-rect.top;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity ();

//glViewport (0, window_height/2, window_width/2, window_height/2);

glScissor(1, window_height/2, window_height/2,window_width/2); // Define Scissor Region
glEnable(GL_SCISSOR_TEST);

glTranslatef(0.0f,0.0f,-6.0f);
glRotatef(rquad,0.0f,0.0f,1.0f);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

glDisable(GL_SCISSOR_TEST);

glViewport (window_width/2, window_height/2, window_width/2, window_height/2);

glTranslatef(0.0f,0.0f,-6.0f);
glRotatef(rquad,0.0f,-1.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

glViewport (window_width/2, 0, window_width/2, window_height/2);

glTranslatef(0.0f,0.0f,-6.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

glViewport (0, 0, window_width/2, window_height/2);

glTranslatef(0.0f,0.0f,-6.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

glScissor(1, 1.0, window_height/2,window_width/2); // Define Scissor Region
glEnable(GL_SCISSOR_TEST);
glDisable(GL_SCISSOR_TEST);

gluLookAt(Camera.xPos, Camera.yPos, Camera.zPos,
Camera.xView, Camera.yView, Camera.zView,
Camera.xUp, Camera.yUp, Camera.zUp);



/*glViewport (0, window_height/2, window_width/2, window_height/2);

glViewport (window_width/2, window_height/2, window_width/2, window_height/2);

glViewport (window_width/2, 0, window_width/2, window_height/2);

glViewport (0, 0, window_width/2, window_height/2); */

rquad-=1.0f;
yrot += 1.0f; // Increase yrot By One

return TRUE; // Keep Going
}


As you can see, Ive added some multi-colored quads in an attempt to tell the diference between each viewport. If the scissor is working properly, then there should be another visible quad rotating in the proper place (unless I have made some kinf of mistake in assuming that only one scissor will work with the other viewports alread there... Prehaps someone could shed some light on this for me?

Share this post


Link to post
Share on other sites
Your code seems to miss a lot of stuff to make sense to me. You''re changing the viewport several times, but you never set it when you enter the function, which means the last set viewport is still in effect when entering the function next time (unless you change it outside of course). You''re making transforms for each quad, and transformations for each new quad will accumulate as each quad is drawn, is thast intentional?

And you''re only setting the scissor box once, but viewport several times. Usually when you want to use viewports and scissor boxes, you call both glViewport and glScissor at the same time, with the same parameters. Otherwise you get a viewport for one part of the window, and a scissor box for another. The result is either a partly rendred viewport (if the viewport and scissor box overlap), or nothing at all (if there is no overlap).

Try this code and see if you can understand what how the viewport and scissor box interacts. Just replace the entire DrawGLScene, except the part where you calculate width and height in the beginning, and increment angles at the end.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.5, 1.5, -1.5, 1.5, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// First viewport, the entire screen.

// No scissoring needed now.

// Light blue background.

glViewport(0, 0, window_width, window_height);
glClearColor(0.5, 0.5, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glRotatef(rquad, 0, 0, 1);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,1.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glPopMatrix();

// Second viewport, the lower right one third of the window.

// Enable scissoring to prevent glClear to clear entire screen.

// Light red background.

glViewport(window_width-window_width/3, 0, window_width/3, window_height/3);
glScissor(window_width-window_width/3, 0, window_width/3, window_height/3);
glEnable(GL_SCISSOR_TEST);
glClearColor(1.0, 0.5, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glRotatef(rquad, 0, 0, 1);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,1.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glPopMatrix();

glDisable(GL_SCISSOR_TEST);

Share this post


Link to post
Share on other sites