/************************************************************** This is the basic display callback routine It creates the geometry, lighting, and viewing position In this case it rotates the camera around the scene ***************************************************************/ void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); MakeCamera(FALSE,0,0); MakeLighting(); MakeGeometry(); glPopMatrix(); //glFlush(); This isn't necessary for double buffers glutSwapBuffers(); }
/* This is the basic display callback routine It creates the geometry, lighting, and viewing position In this case it rotates the camera around the scene */ void Display(void) { XYZ r,eyepos; double dist,ratio,radians,scale,wd2,ndfl; double left,right,top,bottom; /* Do we need to recreate the list ? */ if (geometrydirty != NOTDIRTY) { MakeGeometry(); geometrydirty = NOTDIRTY; } /* Clip to avoid extreme stereo */ near = 0.1; far = 1000; if (stereo) near = camera.focallength / 5; /* Misc stuff */ ratio = camera.screenwidth / (double)camera.screenheight; radians = DTOR * camera.aperture / 2; wd2 = near * tan(radians); ndfl = near / camera.focallength; /* Clear the buffers */ glDrawBuffer(GL_BACK_LEFT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (stereo) { glDrawBuffer(GL_BACK_RIGHT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } if (stereo) { /* Derive the two eye positions */ CROSSPROD(camera.vd,camera.vu,r); Normalise(&r); r.x *= camera.eyesep / 2.0; r.y *= camera.eyesep / 2.0; r.z *= camera.eyesep / 2.0; eyepos = VectorAdd(camera.vp,r); glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2 - 0.5 * camera.eyesep * ndfl; right = ratio * wd2 - 0.5 * camera.eyesep * ndfl; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_RIGHT); glLoadIdentity(); gluLookAt(eyepos.x,eyepos.y,eyepos.z, eyepos.x + camera.vd.x, eyepos.y + camera.vd.y, eyepos.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); MakeLighting(); glCallList(1); eyepos = VectorSub(r,camera.vp); glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2 + 0.5 * camera.eyesep * ndfl; right = ratio * wd2 + 0.5 * camera.eyesep * ndfl; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_LEFT); glLoadIdentity(); gluLookAt(eyepos.x,eyepos.y,eyepos.z, eyepos.x + camera.vd.x, eyepos.y + camera.vd.y, eyepos.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); MakeLighting(); glCallList(1); } else { glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2; right = ratio * wd2; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_LEFT); glLoadIdentity(); gluLookAt(camera.vp.x,camera.vp.y,camera.vp.z, camera.vp.x + camera.vd.x, camera.vp.y + camera.vd.y, camera.vp.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); MakeLighting(); glCallList(1); } /* glFlush(); This isn't necessary for double buffers */ glutSwapBuffers(); if (record || windowdump) { WindowDump(camera.screenwidth,camera.screenheight,stereo); windowdump = FALSE; } if (demomode && iterationdepth < 1000) { iterationdepth++; geometrydirty = ADDONE; if (debug) fprintf(stderr,"Iteration: %d\n",iterationdepth); } }
void HandleDisplay(void) { int i,j; int rc; int maxdim; XYZ right; unsigned int textureid; GLfloat white[4] = {1.0,1.0,1.0,1.0}; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glShadeModel(GL_SMOOTH); glDrawBuffer(GL_BACK_LEFT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(camera.aperture,1,0.1,10000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,0, focus.x,focus.y,focus.z, 0,1,0); /* Create Scene */ MakeExperiment(); MakeLighting(); /* Copy the image to be used as a texture */ /* Deep Magic */ maxdim = camera.screenwidth >= camera.screenheight ? camera.screenwidth : camera.screenheight; if ((thetex = (PIXELA*) malloc(camera.screenwidth*camera.screenheight*sizeof(PIXELA))) == NULL) { fprintf(stderr,"Failed to allocate memory for the texture\n"); return; } glReadPixels(0,0,camera.screenwidth,camera.screenheight,GL_RGBA,GL_UNSIGNED_BYTE,thetex); glGenTextures(1,&textureid); glBindTexture(GL_TEXTURE_2D,textureid); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,4, camera.screenwidth,camera.screenheight, 0,GL_RGBA,GL_UNSIGNED_BYTE,thetex); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glDrawBuffer(GL_BACK_LEFT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-camera.screenwidth/2,camera.screenwidth/2, -camera.screenheight/2,camera.screenheight/2,1.0,10000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0); glNormal3f(0.0,0.0,1.0); glColor3f(1.0,1.0,1.0); glDisable(GL_LIGHTING); glShadeModel(GL_FLAT); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,white); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,textureid); /* Now distort the image. */ CreateGrid(); /* Apply edge blending */ EdgeBlend(); /* Clean up, swap buffers. */ glDisable(GL_TEXTURE_2D); glutSwapBuffers(); glDeleteTextures(1,&textureid); free(thetex); }
void display() { double nearp = 0.1; double farp = 10000; XYZ r; double dist, ratio, radians, scale, wd2, ndfl; double left, right, top, bottom; /* Clip to avoid extreme stereo */ #ifdef STEREO_3D nearp = camera.focallength / 5; #endif /* Misc stuff */ ratio = camera.screenwidth / (double)camera.screenheight; radians = DTOR * camera.aperture / 2; wd2 = nearp * tan(radians); ndfl = nearp / camera.focallength; glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #ifdef STEREO_3D update(); /* Derive the two eye positions */ CROSSPROD(camera.vd,camera.vu,r); Normalise(&r); r.x *= camera.eyesep / 2.0; r.y *= camera.eyesep / 2.0; r.z *= camera.eyesep / 2.0; glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2 - 0.5 * camera.eyesep * ndfl; right = ratio * wd2 - 0.5 * camera.eyesep * ndfl; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,nearp,farp); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK); #ifdef INVERT_STEREO glViewport ( camera.screenwidth / 2, 0, camera.screenwidth / 2, camera.screenheight); #else glViewport ( 0, 0, camera.screenwidth / 2, camera.screenheight); #endif glLoadIdentity(); gluLookAt(camera.vp.x + r.x,camera.vp.y + r.y,camera.vp.z + r.z, camera.vp.x + r.x + camera.vd.x, camera.vp.y + r.y + camera.vd.y, camera.vp.z + r.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); glTranslatef(-0.5f, -0.5f, -2.0f); MakeLighting(); MakeGeometry(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2 + 0.5 * camera.eyesep * ndfl; right = ratio * wd2 + 0.5 * camera.eyesep * ndfl; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,nearp,farp); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK); #ifdef INVERT_STEREO glViewport ( 0, 0, camera.screenwidth / 2, camera.screenheight); #else glViewport ( camera.screenwidth / 2, 0, camera.screenwidth / 2, camera.screenheight); #endif // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(camera.vp.x - r.x,camera.vp.y - r.y,camera.vp.z - r.z, camera.vp.x - r.x + camera.vd.x, camera.vp.y - r.y + camera.vd.y, camera.vp.z - r.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); glTranslatef(-0.5f, -0.5f, -2.0f); MakeLighting(); MakeGeometry(); glutSwapBuffers(); glutPostRedisplay(); #else update(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2; right = ratio * wd2; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,nearp,farp); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camera.vp.x,camera.vp.y,camera.vp.z, camera.vp.x + camera.vd.x, camera.vp.y + camera.vd.y, camera.vp.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); glTranslatef(-0.5f, -0.5f, -2.0f); MakeLighting(); MakeGeometry(); glutSwapBuffers(); glutPostRedisplay(); #endif // STEREO_3D }
void draw_s2fishdome(CAMERA cam) { // draw a fisheye / warped projection of the geometry double r, near, far; XYZ vp, vd, vr, vl; XYZ vright, vleft, vup; // Calculate various view vectors vp = cam.vp; vd = cam.vd; vr = CrossProduct(vd,cam.vu); vl = CrossProduct(cam.vu,vd); vd = ArbitraryRotate(vd,cam.fishrotate,vr); vup = CrossProduct(vr,vd); vright = VectorAdd(vr,vd); vleft = VectorAdd(vl,vd); near = VectorLength(_s2priv_pmin(),_s2priv_pmax()) / 100; far = MAX(cam.focallength,VectorLength(_s2priv_pmin(), _s2priv_pmax())) * 20; // Left glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glViewport(0,0,TEXTURESIZE,TEXTURESIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); s2Perspective(90.0,1.0,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); s2LookAt(vp.x,vp.y,vp.z,vp.x+vleft.x,vp.y+vleft.y,vp.z+vleft.z,vup.x,vup.y,vup.z); MakeLighting(); MakeMaterial(); MakeGeometry(FALSE, FALSE); glBindTexture(GL_TEXTURE_2D,walltextureid[2]); glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE); // Right glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glViewport(0,0,TEXTURESIZE,TEXTURESIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); s2Perspective(90.0,1.0,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); s2LookAt(vp.x,vp.y,vp.z,vp.x+vright.x,vp.y+vright.y,vp.z+vright.z,vup.x,vup.y,vup.z); MakeLighting(); MakeMaterial(); MakeGeometry(FALSE, FALSE); glBindTexture(GL_TEXTURE_2D,walltextureid[3]); glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE); // Top glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glViewport(0,0,TEXTURESIZE,TEXTURESIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); s2Perspective(90.0,1.0,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); s2LookAt(vp.x,vp.y,vp.z,vp.x+vup.x,vp.y+vup.y,vp.z+vup.z,-vright.x,-vright.y,-vright.z); MakeLighting(); MakeMaterial(); MakeGeometry(FALSE, FALSE); glBindTexture(GL_TEXTURE_2D,walltextureid[0]); glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE); // Bottom glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glViewport(0,0,TEXTURESIZE,TEXTURESIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); s2Perspective(90.0,1.0,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); s2LookAt(vp.x,vp.y,vp.z,vp.x-vup.x,vp.y-vup.y,vp.z-vup.z,-vleft.x,-vleft.y,-vleft.z); MakeLighting(); MakeMaterial(); MakeGeometry(FALSE, FALSE); glBindTexture(GL_TEXTURE_2D,walltextureid[1]); glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE); // Remember the graphics state and return it at the end glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); glDisable(GL_COLOR_MATERIAL); glDisable(GL_DITHER); //glDisable(GL_FOG); glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_STIPPLE); glDisable(GL_SCISSOR_TEST); glDisable(GL_STENCIL_TEST); // Setup projections for the dome glDrawBuffer(GL_BACK); if (_s2fd_options->dometype == WARPMAP) glClearColor(0.0,0.0,0.0,0.0); else glClearColor(0.05,0.05,0.05,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0,0,_s2fd_options->screenwidth,_s2fd_options->screenheight); r = _s2fd_options->screenwidth / (double)_s2fd_options->screenheight; switch (_s2fd_options->dometype) { case TRUNCTOP: case TRUNCBOTTOM: glOrtho(-r*0.75,r*0.75,-0.75,0.75,0.1,10.0); break; case HSPHERICAL: glOrtho(-r*0.75,r*0.75,-0.75,0.75,0.1,10.0); break; case VSPHERICAL: case WARPMAP: default: glOrtho(-r,r,-1.0,1.0,0.1,10.0); break; } // Create camera projection for dome glMatrixMode(GL_MODELVIEW); glLoadIdentity(); switch (_s2fd_options->dometype) { case TRUNCBOTTOM: s2LookAt(0.0,-1.0,0.25,0.0,0.0,0.25,0.0,0.0,1.0); break; case TRUNCTOP: s2LookAt(0.0,-1.0,-0.25,0.0,0.0,-0.25,0.0,0.0,1.0); break; case HSPHERICAL: case VSPHERICAL: case WARPMAP: default: s2LookAt(0.0,-1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0); break; } // Finally draw the dome geometry glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glColor3f(1.0,1.0,1.0); DrawDome(TRUE,FALSE); _s2_fadeinout(); DrawExtras(); glPopAttrib(); }