PDA

View Full Version : viewport



10-29-2000, 03:01 AM
can anybody help me i have the code below and basically i need to be able to change the 2nd veiwport window so it "zooms in" on the first. i try to use the glortho command and it just leaves the screen blank. any help??

/* map.c - world map - display map of the world */

#include <windows.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>

long int points[170000] ;


void myinit(void)
{
glColor3f(1.0, 1.0, 1.0) ;

/* set up background colour */

glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
return;
}

void readdata(void){

/* read data points from a binary file into memory. Values are stored in an array `points` */

unsigned long i;
FILE *world;

if ((world=fopen("world.dat", "rb")) == NULL){
printf("Cannot open file.\n");
return;
}
i = 0;
while ( ! feof(world)){
unsigned char b1,b2,b3,b4;
fread(&b1,1,1,world);
fread(&b2,1,1,world);
fread(&b3,1,1,world);
fread(&b4,1,1,world);
points[i]=(long int)(((unsigned long)b1<<24) | ((unsigned long)b2<<16) | ((unsigned long)b3<<8) | ((unsigned long)b4));
// if ((fread(&points[i], sizeof(int), 1, world) !=1) && (! feof(world))){
// printf("error reading file. \n");
// break;
// }
i++;
}
fclose(world);
return;
}


void drawmap(void){
int npts;
int k = 0;
long base = 0;

/* cycle through the list of points sequentially using them to define vertices. Vertices are joined with a line-strip */

do{
npts = points[base];
glBegin(GL_LINE_STRIP);
for (k=1 ; k <= (npts*2) ; k = k+2)
glVertex2s(points[base + k],points[base + k+1]);
glEnd();
base = base + (npts*2+ 1);
glFlush();
}
while (npts != 0);
return;
}


void display(void){

/* clear background */
myinit();

/* set up a clip window and a viewport for the map data */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-33000.0, 33000.0, -33000.0, 33000.0, -1.0, 1.0);
glViewport(00, 00, 500, 250);

/* Draw border just inside the edges of the clip window */
glBegin(GL_LINE_LOOP);
glVertex2i(-32995, -32995);
glVertex2i(32995, -32995);
glVertex2i(32995, 32995);
glVertex2i(-32995, 32995);
glEnd();

/* Draw the interior map */
drawmap();

============================> here is where i need to change the viewport below.

glViewport(00, 250, 500, 250);

/* Draw border just inside the edges of the clip window */
glBegin(GL_LINE_LOOP);
glVertex2i(-32995, -32995);
glVertex2i(32995, -32995);
glVertex2i(32995, 32995);
glVertex2i(-32995, 32995);
glEnd();

/* Draw the interior map */
drawmap();
return;
}


int main(int argc, char** argv){
/* set up window and call-back procedures */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100, 100);
glutCreateWindow("World Map");
readdata();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

zed
10-29-2000, 12:18 PM
are all your points in the acceptable range
lOrtho(-33000.0, 33000.0, -33000.0, 33000.0, -1.0, 1.0);
ie the near + far planes are a lot smaller than the others

10-29-2000, 02:07 PM
all the points for the first viewports are correct cause it shows the right thing in the first viewport.
i need to show a zoomed in version of the first viewport in the second viewport.
can you help me with this??

-kebabinho

zed
10-29-2000, 11:50 PM
well u cant really do a zoomin with an orthogonal matrix (though u can a perspective viewmatrix)
the only way i see it is to draw everything bigger maybe use glScale(2,2,2

Bob
10-30-2000, 01:29 AM
When drawing the second viewport, build a new projection matrix with glOrtho, and pass the new viewing volume as parameters. Instead of +-33000, call it with smaller values. This will result in a smaller viewing volume, and therefore a zooming effect.