void Camera::Render(){ GzPose pose; GzVector a, b; // Compute the point to look at, and the orientation vector pose = this->cameraPose; a = GzVectorSet(1, 0, 0); b = GzVectorSet(1, 0, 1); a = GzCoordPositionAdd(a, pose.pos, pose.rot); b = GzCoordPositionAdd(b, pose.pos, pose.rot); b = GzVectorSub(b, a); // Fill in the current camera index this->renderOpt.cameraIndex = this->context.GetContextIndex(); this->renderOpt.cameraPose = this->cameraPose; this->renderOpt.farClip = this->farClip; // Select the GL context if (this->context.MakeCurrent() != 0) return; // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); PRINT_GL_ERR(); // Set the camera lens propeties (assumes square pixels) glMatrixMode(GL_PROJECTION); glLoadIdentity(); double ratio = (double)this->imageWidth / this->imageHeight; double vfov = 2.0 * atan(tan(this->hfov / 2.0) / ratio) * 180 / M_PI; gluPerspective(vfov, ratio, this->nearClip, this->farClip); // Store the projection matrix for later use glGetFloatv(GL_PROJECTION_MATRIX, this->cameraProjectionMatrix); // Set the camera pose glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(pose.pos.x, pose.pos.y, pose.pos.z, a.x, a.y, a.z, b.x, b.y, b.z); PRINT_GL_ERR(); glGetFloatv(GL_MODELVIEW_MATRIX, this->cameraViewMatrix); // Counter Clockwise rotation are front faces glFrontFace(GL_CCW); // Enable lighting glEnable(GL_LIGHTING); // Set global rendering properties glPolygonMode( GL_FRONT_AND_BACK, this->renderOpt.polygonMode ); PRINT_GL_ERR(); glShadeModel(this->renderOpt.shadeModel); PRINT_GL_ERR(); // Reset material properties glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, GzColor(0.2, 0.2, 0.2, 1.0)); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, GzColor(0.8, 0.8, 0.8, 1.0)); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, GzColor(0.0, 0.0, 0.0, 1.0)); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0); PRINT_GL_ERR(); //this->shaderObject->Begin(); // Make multiple passes to ensure geoms get rendered in correct // order (needed for lights, for example) for (int p = 0; p < GZ_RENDER_MAX_PASSES; p++) { this->RenderModels(p); PRINT_GL_ERR(); } //this->shaderObject->End(); // Make sure we are done glFinish(); PRINT_GL_ERR(); // Get the image from the frame buffer glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, this->imageWidth, this->imageHeight, GL_RGB, GL_UNSIGNED_BYTE, this->rgbImage); PRINT_GL_ERR(); return;}