void RENDER_INPUT::PushShadowMatrices() { glActiveTexture(GL_TEXTURE3); glMatrixMode(GL_TEXTURE); MATRIX4<float> m; glGetFloatv (GL_TEXTURE_MATRIX, m.GetArray()); m = m.Inverse(); //std::cout << m << std::endl; for (int i = 0; i < 3; i++) { glActiveTexture(GL_TEXTURE4+i); glPushMatrix(); glMultMatrixf(m.GetArray()); } glActiveTexture(GL_TEXTURE0); glMatrixMode(GL_MODELVIEW); }
void GRAPHICS_GL2::ChangeDisplay( const int width, const int height, std::ostream & error_output) { glViewport(0, 0, (GLint)width, (GLint)height); GLfloat ratio = (GLfloat)width / (GLfloat)height; MATRIX4<float> m; glMatrixMode(GL_PROJECTION); m.Perspective(45.0f, ratio, 0.1f, 100.0f); glLoadMatrixf(m.GetArray()); glMatrixMode(GL_MODELVIEW); m.LoadIdentity(); glLoadMatrixf(m.GetArray()); GLUTIL::CheckForOpenGLErrors("ChangeDisplay", error_output); w = width; h = height; }
void GRAPHICS_GL2::SetupScene( float fov, float new_view_distance, const MATHVECTOR <float, 3> cam_position, const QUATERNION <float> & cam_rotation, const MATHVECTOR <float, 3> & dynamic_reflection_sample_pos) { // setup the default camera from the passed-in parameters { GRAPHICS_CAMERA & cam = cameras["default"]; cam.fov = fov; cam.pos = cam_position; cam.orient = cam_rotation; cam.view_distance = new_view_distance; cam.w = w; cam.h = h; } // create a camera for the skybox with a long view distance { GRAPHICS_CAMERA & cam = cameras["skybox"]; cam = cameras["default"]; cam.view_distance = 10000.0; } // create a camera for 3d ui elements that has a fixed FOV { GRAPHICS_CAMERA & cam = cameras["ui3d"]; cam.fov = 45; cam.pos = cam_position; cam.orient = cam_rotation; cam.view_distance = new_view_distance; cam.w = w; cam.h = h; } // create a camera for the dynamic reflections { GRAPHICS_CAMERA & cam = cameras["dynamic_reflection"]; cam.pos = dynamic_reflection_sample_pos; cam.fov = 90; // this gets automatically overridden with the correct fov (which is 90 anyway) cam.orient.LoadIdentity(); // this gets automatically rotated for each cube side cam.view_distance = 100.f; cam.w = 1.f; // this gets automatically overridden with the cubemap dimensions cam.h = 1.f; // this gets automatically overridden with the cubemap dimensions } // create a camera for the dynamic reflection skybox { GRAPHICS_CAMERA & cam = cameras["dynamic_reflection_skybox"]; cam = cameras["dynamic_reflection"]; cam.view_distance = 10000.f; } // create an ortho camera for 2d drawing { GRAPHICS_CAMERA & cam = cameras["2d"]; // this is the glOrtho call we want: glOrtho( 0, 1, 1, 0, -1, 1 ); cam.orthomode = true; cam.orthomin = MATHVECTOR <float, 3> (0, 1, -1); cam.orthomax = MATHVECTOR <float, 3> (1, 0, 1); } // put the default camera transform into texture3, needed by shaders only MATRIX4<float> viewMatrix; cam_rotation.GetMatrix4(viewMatrix); float translate[4] = {-cam_position[0], -cam_position[1], -cam_position[2], 0}; viewMatrix.MultiplyVector4(translate); viewMatrix.Translate(translate[0], translate[1], translate[2]); glActiveTexture(GL_TEXTURE3); glMatrixMode(GL_TEXTURE); glLoadMatrixf(viewMatrix.GetArray()); // create cameras for shadow passes if (shadows) { MATRIX4<float> viewMatrixInv = viewMatrix.Inverse(); std::vector <std::string> shadow_names; shadow_names.push_back("near"); shadow_names.push_back("medium"); shadow_names.push_back("far"); for (int i = 0; i < 3; i++) { float shadow_radius = (1<<i)*closeshadow+(i)*20.0; //5,30,60 MATHVECTOR <float, 3> shadowbox(1,1,1); shadowbox = shadowbox * (shadow_radius*sqrt(2.0)); MATHVECTOR <float, 3> shadowoffset(0,0,-1); shadowoffset = shadowoffset * shadow_radius; (-cam_rotation).RotateVector(shadowoffset); shadowbox[2] += 60.0; GRAPHICS_CAMERA & cam = cameras["shadows_"+shadow_names[i]]; cam = cameras["default"]; cam.orthomode = true; cam.orthomin = -shadowbox; cam.orthomax = shadowbox; cam.pos = cam.pos + shadowoffset; cam.orient = lightdirection; // go through and extract the clip matrix, storing it in a texture matrix // premultiply the clip matrix with default camera view inverse matrix renderscene.SetOrtho(cam.orthomin, cam.orthomax); renderscene.SetCameraInfo(cam.pos, cam.orient, cam.fov, cam.view_distance, cam.w, cam.h); MATRIX4<float> clipmat; clipmat.Scale(0.5f); clipmat.Translate(0.5f, 0.5f, 0.5f); clipmat = renderscene.GetProjMatrix().Multiply(clipmat); clipmat = renderscene.GetViewMatrix().Multiply(clipmat); clipmat = viewMatrixInv.Multiply(clipmat); glActiveTexture(GL_TEXTURE4+i); glLoadMatrixf(clipmat.GetArray()); } } glMatrixMode(GL_MODELVIEW); glActiveTexture(GL_TEXTURE0); }