![]() |
are you ready for a mindfuck? |
|
....::::Menu::::.... ---------------------------...::About::... ...::Articles::... ...::Contact::... ...::Home & News::... ...::Links & Credits::... --------------------------- --------------------------- |
Using multiple viewports and the scissortestby Elie De BrauwerGoal of this fileThis artcle gives an example of how to use multiple viewports in your application. History of this file
Multiple viewports ?
Indeed multiple viewports, for those of you who already worked with (or have seen) 3d modelers or used
applications like
blender know that it is a nice feature that you can view
a three dimensional object that you are creating from multiple angles. So many of thos applications split the
screen in four and show a perspective in one segment and an xy, xz, yz orthographic projection in the remaining
three windows.
If you would try to run the application without using the scissor test each viewport would be overwritten and only the last viewport drawn would remain visible. Putting it all together
In the code we use the glutReshapeFunc to set the global variables x and y that contain the dimensions
of the window.
#include <cstdlib>
#include <GL/glut.h>
using namespace std;
typedef unsigned char uchar;
// callbacks
void disp(void);
void drawScene(void);
void keyb(uchar key, int x, int y);
void reshape(int x, int y);
static int width =0 , height=0;
////////////////////////////////
// main
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowSize(600,600);
glutInitWindowPosition(100,100);
glutCreateWindow("scissor test");
glClearColor(0.0,0.0,0.0,0.0);
glutDisplayFunc(disp);
glutKeyboardFunc(keyb);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
////////////////
// disp
void disp(void){
glEnable(GL_SCISSOR_TEST);
glMatrixMode(GL_MODELVIEW);
// lower left
glViewport(0,0,width/2,height/2);
glScissor(0,0,width/2,height/2);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
drawScene();
// lower right
glViewport(width/2,0,width/2,height/2);
glScissor(width/2,0,width/2,height/2);
glLoadIdentity();
glRotatef(90,0.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
drawScene();
// upper left
glViewport(0,height/2,width/2,height/2);
glScissor(0,height/2,width/2,height/2);
glLoadIdentity();
glRotatef(90,1.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
drawScene();
// upper right
glViewport(width/2,height/2,width/2,height/2);
glScissor(width/2,height/2,width/2,height/2);
glLoadIdentity();
glRotatef(90,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
drawScene();
glFlush();
}
/////////////////////
// drawScene
void drawScene(void){
glutWireTeapot(0.5);
}
////////////////////////////////////
// keyb
void keyb(uchar key, int x, int y ){
if(key == 'q'){
exit(0);
}
}
//////////////////////////
// reshape
void reshape(int x,int y){
width = x;
height=y;
}
You can also download the sourcode here |