void SpaceStation::Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { Body *b = GetFrame()->GetBody(); assert(b); if (!b->IsType(Object::PLANET)) { // orbital spaceport -- don't make city turds or change lighting based on atmosphere RenderModel(r, camera, viewCoords, viewTransform); r->GetStats().AddToStatCount(Graphics::Stats::STAT_SPACESTATIONS, 1); } else { // don't render city if too far away if (viewCoords.LengthSqr() >= SQRMAXCITYDIST) { return; } std::vector<Graphics::Light> oldLights; Color oldAmbient; SetLighting(r, camera, oldLights, oldAmbient); if (!m_adjacentCity) { m_adjacentCity = new CityOnPlanet(static_cast<Planet*>(b), this, m_sbody->GetSeed()); } m_adjacentCity->Render(r, camera->GetContext()->GetFrustum(), this, viewCoords, viewTransform); RenderModel(r, camera, viewCoords, viewTransform, false); ResetLighting(r, oldLights, oldAmbient); r->GetStats().AddToStatCount(Graphics::Stats::STAT_GROUNDSTATIONS, 1); } }
// Renders space station and adjacent city if applicable // For orbital starports: renders as normal // For surface starports: // Lighting: Calculates available light for model and splits light between directly and ambiently lit // Lighting is done by manipulating global lights or setting uniforms in atmospheric models shader void SpaceStation::Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { Body *b = GetFrame()->GetBody(); assert(b); if (!b->IsType(Object::PLANET)) { // orbital spaceport -- don't make city turds or change lighting based on atmosphere RenderModel(r, camera, viewCoords, viewTransform); } else { std::vector<Graphics::Light> oldLights; Color oldAmbient; SetLighting(r, camera, oldLights, oldAmbient); Planet *planet = static_cast<Planet*>(b); /* don't render city if too far away */ if (viewCoords.Length() < 1000000.0){ if (!m_adjacentCity) { m_adjacentCity = new CityOnPlanet(planet, this, m_sbody->seed); } m_adjacentCity->Render(r, camera, this, viewCoords, viewTransform); } RenderModel(r, camera, viewCoords, viewTransform, false); ResetLighting(r, oldLights, oldAmbient); } }
void avtTruecolorPlot::SetAtts(const AttributeGroup *a) { const TruecolorAttributes *newAtts = (const TruecolorAttributes *)a; needsRecalculation = atts.ChangesRequireRecalculation(*newAtts); atts = *newAtts; SetOpacity(atts.GetOpacity()); SetLighting(atts.GetLightingFlag()); }
void InitOpenGL_model( HWND hWnd, const PorousModel& model ) { SetOpenGLPerspective( hWnd, model ); glEnable(GL_LIGHTING); glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, 0 ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT1 ); SetLighting( model ); }
void RageDisplay::SetDefaultRenderStates() { SetLighting( false ); SetCullMode( CULL_NONE ); SetZWrite( false ); SetZTestMode( ZTEST_OFF ); SetAlphaTest( true ); SetBlendMode( BLEND_NORMAL ); SetTextureFiltering( TextureUnit_1, true ); SetZBias( 0 ); LoadMenuPerspective( 0, 640, 480, 320, 240 ); // 0 FOV = ortho }
void RageDisplay::SetDefaultRenderStates() { SetLighting( false ); SetCullMode( CULL_NONE ); SetZWrite( false ); SetZTestMode( ZTEST_OFF ); SetAlphaTest( true ); SetBlendMode( BLEND_NORMAL ); SetTextureFiltering( true ); LoadMenuPerspective(0, SCREEN_CENTER_X, SCREEN_CENTER_Y); // 0 FOV = ortho ChangeCentering(0,0,0,0); }
/** * Copy this material from another. */ void vtMaterial::CopyFrom(vtMaterial *pFrom) { SetDiffuse1(pFrom->GetDiffuse()); SetSpecular1(pFrom->GetSpecular()); SetAmbient1(pFrom->GetAmbient()); SetEmission1(pFrom->GetEmission()); SetCulling(pFrom->GetCulling()); SetLighting(pFrom->GetLighting()); // SetTexture(pFrom->GetTexture()); SetTransparent(pFrom->GetTransparent()); }
//------------------------------------------------------------------------ int InitGL(GLvoid) // All Setup For OpenGL Goes Here { glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_SMOOTH); // Enables Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations SetLighting(); return TRUE; // Initialization Went OK }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); start_timing(); SetLighting(); CALL_MEMBER_FN(bunny, bunny.render)(); float timeElapsed = stop_timing(); gTotalFrames++; gTotalTimeElapsed += timeElapsed; float fps = gTotalFrames / gTotalTimeElapsed; char string[1024] = {0}; sprintf(string, "OpenGL Bunny: %0.2f FPS", fps); glutSetWindowTitle(string); glutPostRedisplay(); glutSwapBuffers(); }
void ModelBody::RenderModel(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform, const bool setLighting) { std::vector<Graphics::Light> oldLights; Color oldAmbient; if (setLighting) SetLighting(r, camera, oldLights, oldAmbient); matrix4x4d m2 = GetInterpOrient(); m2.SetTranslate(GetInterpPosition()); matrix4x4d t = viewTransform * m2; glPushMatrix(); // Otherwise newmodels leave a dirty matrix matrix4x4f trans; for (int i=0; i<12; i++) trans[i] = float(t[i]); trans[12] = viewCoords.x; trans[13] = viewCoords.y; trans[14] = viewCoords.z; trans[15] = 1.0f; m_model->Render(trans); glPopMatrix(); if (setLighting) ResetLighting(r, oldLights, oldAmbient); }
void avtPseudocolorPlot::SetAtts(const AttributeGroup *a) { const PseudocolorAttributes *newAtts = (const PseudocolorAttributes *)a; // See if the colors will need to be updated. bool updateColors = (!colorsInitialized) || (atts.GetColorTableName() != newAtts->GetColorTableName()) || (atts.GetInvertColorTable() != newAtts->GetInvertColorTable()) || (atts.GetOpacityType() != newAtts->GetOpacityType()) || (atts.GetOpacityType() == PseudocolorAttributes::Ramp && atts.GetOpacity() != newAtts->GetOpacity()); // See if any attributes that require the plot to be regenerated were // changed and copy the state object. needsRecalculation = atts.ChangesRequireRecalculation(*newAtts); atts = *newAtts; // Update the plot's colors if needed. if(updateColors || atts.GetColorTableName() == "Default") { colorsInitialized = true; SetColorTable(atts.GetColorTableName().c_str()); } else SetOpacityFromAtts(); SetLighting(atts.GetLightingFlag()); SetLegend(atts.GetLegendFlag()); SetScaling(atts.GetScaling(), atts.GetSkewFactor()); SetLimitsMode(atts.GetLimitsMode()); glyphMapper->SetLineWidth(Int2LineWidth(atts.GetLineWidth())); glyphMapper->SetLineStyle(Int2LineStyle(atts.GetLineStyle())); glyphMapper->SetScale(atts.GetPointSize()); // ARS - FIX ME - FIX ME - FIX ME - FIX ME - FIX ME if( atts.GetOpacityType() == PseudocolorAttributes::VariableRange && atts.GetOpacityVariable() != "" && atts.GetOpacityVariable() != "\0") { // glyphMapper->SetVariableOpacity(atts.GetOpacity()); // if( atts.GetOpacityVarMinFlag() ) // glyphMapper->SetVariableMinOpacity(atts.GetOpacityVarMin()); // if( atts.GetOpacityVarMaxFlag() ) // glyphMapper->SetVariableMaxOpacity(atts.GetOpacityVarMax()); if (atts.GetOpacityVariable() == "default") { // if (varname != NULL) // glyphMapper->ScaleOpacityByVar(varname); } else { // glyphMapper->ScaleOpacityByVar(atts.GetOpacityVariable()); } } else { // glyphMapper->OpacityScalingOff(); } // ARS - FIX ME - FIX ME - FIX ME - FIX ME - FIX ME if( //(topoDim == 1 || (topoDim > 1 && atts.GetRenderWireframe())) && atts.GetLineType() == PseudocolorAttributes::Tube && atts.GetTubeRadiusVarEnabled() == true && atts.GetTubeRadiusVar() != "" && atts.GetTubeRadiusVar() != "\0" ) { if (atts.GetTubeRadiusVar() == "default") { // if (varname != NULL) // glyphMapper->ScaleTubesByVar(varname); } else { // glyphMapper->ScaleTubesByVar(atts.GetTubeRadiusVar()); } } else { // glyphMapper->TubeScalingOff(); } if( //(topoDim == 0 || (topoDim > 0 && atts.GetRenderPoints())) && atts.GetPointType() != PseudocolorAttributes::Point && atts.GetPointType() != PseudocolorAttributes::Sphere && atts.GetPointSizeVarEnabled() && atts.GetPointSizeVar() != "" && atts.GetPointSizeVar() != "\0" ) { if (atts.GetPointSizeVar() == "default") { if (varname != NULL) glyphMapper->ScaleByVar(varname); } else { glyphMapper->ScaleByVar(atts.GetPointSizeVar()); } } else { glyphMapper->DataScalingOff(); } if (atts.GetPointType() == PseudocolorAttributes::Box) glyphMapper->SetGlyphType(avtPointGlypher::Box); else if (atts.GetPointType() == PseudocolorAttributes::Axis) glyphMapper->SetGlyphType(avtPointGlypher::Axis); else if (atts.GetPointType() == PseudocolorAttributes::Icosahedron) glyphMapper->SetGlyphType(avtPointGlypher::Icosahedron); else if (atts.GetPointType() == PseudocolorAttributes::Octahedron) glyphMapper->SetGlyphType(avtPointGlypher::Octahedron); else if (atts.GetPointType() == PseudocolorAttributes::Tetrahedron) glyphMapper->SetGlyphType(avtPointGlypher::Tetrahedron); else if (atts.GetPointType() == PseudocolorAttributes::SphereGeometry) glyphMapper->SetGlyphType(avtPointGlypher::SphereGeometry); else if (atts.GetPointType() == PseudocolorAttributes::Point) glyphMapper->SetGlyphType(avtPointGlypher::Point); else if (atts.GetPointType() == PseudocolorAttributes::Sphere) glyphMapper->SetGlyphType(avtPointGlypher::Sphere); SetPointGlyphSize(); if (varname != NULL) { glyphMapper->ColorByScalarOn(std::string(varname)); } }
void avtStreamlinePlot::SetAtts(const AttributeGroup *a) { renderer->SetAtts(a); needsRecalculation = atts.ChangesRequireRecalculation(*(const StreamlineAttributes*)a); atts = *(const StreamlineAttributes*)a; #ifdef ENGINE // // Set the filter's attributes based on the plot attributes. // switch (atts.GetSourceType()) { case StreamlineAttributes::SpecifiedPoint: streamlineFilter->SetPointSource(atts.GetPointSource()); break; case StreamlineAttributes::SpecifiedPointList: streamlineFilter->SetPointListSource(atts.GetPointList()); break; case StreamlineAttributes::SpecifiedLine: streamlineFilter->SetLineSource(atts.GetLineStart(), atts.GetLineEnd(), atts.GetSampleDensity0(), atts.GetRandomSamples(), atts.GetRandomSeed(), atts.GetNumberOfRandomSamples()); break; case StreamlineAttributes::SpecifiedPlane: streamlineFilter->SetPlaneSource(atts.GetPlaneOrigin(), atts.GetPlaneNormal(), atts.GetPlaneUpAxis(), atts.GetSampleDensity0(), atts.GetSampleDensity1(), atts.GetSampleDistance0(), atts.GetSampleDistance1(), atts.GetFillInterior(), atts.GetRandomSamples(), atts.GetRandomSeed(), atts.GetNumberOfRandomSamples()); break; case StreamlineAttributes::SpecifiedCircle: streamlineFilter->SetCircleSource(atts.GetPlaneOrigin(), atts.GetPlaneNormal(), atts.GetPlaneUpAxis(), atts.GetRadius(), atts.GetSampleDensity0(), atts.GetSampleDensity1(), atts.GetFillInterior(), atts.GetRandomSamples(), atts.GetRandomSeed(), atts.GetNumberOfRandomSamples()); break; case StreamlineAttributes::SpecifiedSphere: streamlineFilter->SetSphereSource(atts.GetSphereOrigin(), atts.GetRadius(), atts.GetSampleDensity0(), atts.GetSampleDensity1(), atts.GetSampleDensity2(), atts.GetFillInterior(), atts.GetRandomSamples(), atts.GetRandomSeed(), atts.GetNumberOfRandomSamples()); break; case StreamlineAttributes::SpecifiedBox: streamlineFilter->SetBoxSource(atts.GetBoxExtents(),atts.GetUseWholeBox(), atts.GetSampleDensity0(), atts.GetSampleDensity1(), atts.GetSampleDensity2(), atts.GetFillInterior(), atts.GetRandomSamples(), atts.GetRandomSeed(), atts.GetNumberOfRandomSamples()); break; case StreamlineAttributes::Selection: streamlineFilter->SetSelectionSource(atts.GetSelection(), atts.GetSampleDensity0(), atts.GetRandomSamples(), atts.GetRandomSeed(), atts.GetNumberOfRandomSamples()); break; } int CMFEType = (atts.GetPathlinesCMFE() == StreamlineAttributes::CONN_CMFE ? PICS_CONN_CMFE : PICS_POS_CMFE); streamlineFilter->SetPathlines(atts.GetPathlines(), atts.GetPathlinesOverrideStartingTimeFlag(), atts.GetPathlinesOverrideStartingTime(), atts.GetPathlinesPeriod(), CMFEType); streamlineFilter->SetIntegrationDirection(atts.GetIntegrationDirection()); streamlineFilter->SetFieldType(atts.GetFieldType()); streamlineFilter->SetFieldConstant(atts.GetFieldConstant()); streamlineFilter->SetVelocitySource(atts.GetVelocitySource()); streamlineFilter->SetIntegrationType(atts.GetIntegrationType()); streamlineFilter->SetParallelizationAlgorithm(atts.GetParallelizationAlgorithmType(), atts.GetMaxProcessCount(), atts.GetMaxDomainCacheSize(), atts.GetWorkGroupSize()); if (atts.GetIntegrationType() == StreamlineAttributes::DormandPrince) { // For DoPri, the max time step is sent in to the PICS filter as the max step length. double step = atts.GetMaxTimeStep(); if (! atts.GetLimitMaximumTimestep()) step = 0; streamlineFilter->SetMaxStepLength(step); } else streamlineFilter->SetMaxStepLength(atts.GetMaxStepLength()); double absTol = 0.; bool doBBox = (atts.GetAbsTolSizeType() == StreamlineAttributes::FractionOfBBox); if (doBBox) absTol = atts.GetAbsTolBBox(); else absTol = atts.GetAbsTolAbsolute(); streamlineFilter->SetTolerances(atts.GetRelTol(), absTol, doBBox); streamlineFilter->SetTermination(atts.GetMaxSteps(), atts.GetTerminateByDistance(), atts.GetTermDistance(), atts.GetTerminateByTime(), atts.GetTermTime()); streamlineFilter->SetDisplayMethod(atts.GetDisplayMethod()); streamlineFilter->IssueWarningForMaxStepsTermination(atts.GetIssueTerminationWarnings()); streamlineFilter->IssueWarningForStiffness(atts.GetIssueStiffnessWarnings()); streamlineFilter->IssueWarningForCriticalPoints(atts.GetIssueCriticalPointsWarnings(), atts.GetCriticalPointThreshold()); streamlineFilter->SetColoringMethod(int(atts.GetColoringMethod()), atts.GetColoringVariable()); if (atts.GetColoringMethod() == StreamlineAttributes::ColorByCorrelationDistance) { bool doBBox = (atts.GetCorrelationDistanceMinDistType() == StreamlineAttributes::FractionOfBBox); double minDist = (doBBox ? atts.GetCorrelationDistanceMinDistBBox() : atts.GetCorrelationDistanceMinDistAbsolute()); double angTol = atts.GetCorrelationDistanceAngTol(); streamlineFilter->SetColorByCorrelationDistanceTol(angTol, minDist, doBBox); } streamlineFilter->SetVelocitiesForLighting(atts.GetLightingFlag()); streamlineFilter->SetReferenceTypeForDisplay(atts.GetReferenceTypeForDisplay()); streamlineFilter->SetCoordinateSystem(atts.GetCoordinateSystem()); streamlineFilter->SetPhiScaling(atts.GetPhiScalingFlag(), atts.GetPhiScaling()); if (atts.GetOpacityType() == StreamlineAttributes::VariableRange) streamlineFilter->SetOpacityVariable(atts.GetOpacityVariable()); if (atts.GetVaryTubeRadius() != StreamlineAttributes::None && !atts.GetVaryTubeRadiusVariable().empty()) streamlineFilter->SetScaleTubeRadiusVariable(atts.GetVaryTubeRadiusVariable()); #endif UpdateMapperAndLegend(); SetColorTable(atts.GetColorTableName().c_str()); if (atts.GetLegendFlag()) { varLegend->LegendOn(); varLegend->SetLookupTable(avtLUT->GetLookupTable()); } else varLegend->LegendOff(); if (atts.GetColoringMethod() == StreamlineAttributes::Solid) avtLUT->SetLUTColors(atts.GetSingleColor().GetColor(), 1); else varLegend->SetLookupTable(avtLUT->GetLookupTable()); SetLighting(atts.GetLightingFlag()); }
void OpenGLDraw( HWND hWnd, const PorousModel& model, float zoom, float h_angle, float v_angle ) { //GLfloat trf[4][4]; // //memset( trf, 0, sizeof(trf) ); // //for( int i = 0; i < 3; ++i ) // trf[i][i] = 1.0f; // //for( int i = 0; i < 3; ++i ) //{ // trf[0][i] = TrfMatrix[0][i]; // trf[1][i] = TrfMatrix[1][i]; // trf[2][i] = TrfMatrix[2][i]; // trf[i][3] = 0.0; //} // //// Coordinates of the center //trf[3][0] = 0.0; //trf[3][1] = 0.0; //trf[3][2] = 0.0; //trf[3][3] = 1.0; // //trf_x_pnt( trf, trf[3], trf[3] ); //glMultMatrixf( (const GLfloat*)trf ); SetOpenGLPerspective( hWnd, model ); // как обычно указываем какие буферы будем чистить glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // обнуляем текущую матрицу glLoadIdentity(); float r = Length( model.GetSize() ); float cos_vert = cos(v_angle); //FPoint eye( r*sin(h_angle)*cos_vert, r*sin(v_angle), r*cos(h_angle)*cos_vert ); //FPoint up( 0.0f, cos_vert > 0 ? 1.0f : -1.0f, 0.0f ); FPoint eye( 0, 0, r ); FPoint up( 0.0f, 1.0f, 0.0f ); FPoint center( 0.0f, 0.0f, 0.0f ); gluLookAt( eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z ); glScalef( zoom, zoom, zoom ); SetLighting( model ); static const float koeff = (const float)(180.0f/M_PI); glRotatef( koeff*v_angle, 1.0f, 0.0f, 0.0f ); glRotatef( -koeff*(M_PI/2+h_angle), 0.0f, 1.0f, 0.0f ); glPushMatrix(); DrawBounds( model ); glPopMatrix(); DrawModel( model ); SwapBuffers(hDC); }
//--------------------------------------------------------------------------- void CFabAtHomeView::DrawScene(void) //--------------------------------------------------------------------------- {// draw the scene m_bDrawing = true; CFabAtHomeDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CSingleLock lockModel(&pDoc->model.m_mutAccess); lockModel.Lock(100); if(!lockModel.IsLocked()) return; CFabAtHomeApp *pApp = (CFabAtHomeApp *) AfxGetApp(); CVec platetop(0,0,0); //get the graphics position (offset by PrinterComponent home from the hardware home (0,0,0). if (pApp->printer.IsDefined()) platetop = pApp->printer.component[3].GetGraphicsRTPos() + pApp->printer.component[3].pmax; // background glClearColor(1,1,1,1); ReportGLError(CString("ClearColor")); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ReportGLError(CString("Clear")); // lighting SetLighting(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); ReportGLError(CString("PolygonMode")); // draw glPushMatrix(); ReportGLError(CString("PushMatrix1")); if(bPanning) { view.x=(eye.x+view.z)/view.z; view.y=(eye.y+view.z)/view.z; } gluLookAt(eye.x, eye.y, eye.z, view.x, view.y, view.z, up.x, up.y, up.z); ReportGLError(CString("gluLookAt")); glMultMatrixd(rotmat); ReportGLError(CString("MultMatrix")); glPushMatrix(); ReportGLError(CString("PushMatrix2")); glEnable(GL_NORMALIZE); ReportGLError(CString("Enable")); if(bShowPrinter) { ((CFabAtHomeApp*) AfxGetApp())->printer.Draw(); ReportGLError(CString("printer.Draw")); } // model glPushMatrix(); ReportGLError(CString("PushMatrix3")); glTranslated(0,0,platetop.z); ReportGLError(CString("Translate")); DrawMainAxes(20); ReportGLError(CString("DrawAxes")); glPushName(1); ReportGLError(CString("PushName1")); glLoadName(NAMESTACK_CHUNK); ReportGLError(CString("LoadName1")); glPushName(NAMESTACK_CHUNK); ReportGLError(CString("PushName")); if (bShowModel) { glColor3d(0.4,0.8,0.2); for (int i=0; i<pDoc->model.chunk.GetSize(); i++) { glLoadName(i); ReportGLError(CString("LoadName2")); pDoc->model.chunk[i].Draw(&pDoc->model, bModelNormals, bShaded); ReportGLError(CString("DrawChunk")); } } glPopName(); ReportGLError(CString("PopName1")); // paths if(bFollowCurrentLayer) { UpdateCurrentLayer(); } pDoc->model.fab.DrawLayers(&pDoc->model, firstlayer, lastlayer, bShowPaths, bShowTrace); ReportGLError(CString("DrawLayers")); glColor3d(1,1,1); ReportGLError(CString("Color3d")); glLineWidth(5); ReportGLError(CString("LineWidth1")); glLineWidth(1); ReportGLError(CString("LineWidth2")); glPopName(); ReportGLError(CString("PopName2")); glPopMatrix(); ReportGLError(CString("PopMatrix1")); glPopMatrix(); ReportGLError(CString("PopMatrix2")); // end glDisable(GL_COLOR_MATERIAL); ReportGLError(CString("Disable")); glPopMatrix(); ReportGLError(CString("PopMatrix3")); glFinish(); ReportGLError(CString("Finish")); HDC localDC = wglGetCurrentDC(); ASSERT(localDC != NULL); SwapBuffers(localDC); ReportGLError(CString("SwapBuffers")); m_bDrawing = false; }