void calc_color_alias(t_rt *img, t_ray *ray, t_obj *tmp) { t_obj *obj_result; init_alias(img, ray); obj_result = NULL; while (img && ray && tmp && tmp->color) { assign_ray(img, ray, tmp); obj_result = cast_ray(ray, tmp, obj_result); tmp = tmp->next; } if (obj_result != NULL && obj_result->color) { assign_ray(img, ray, obj_result); obj_result->color->color = perlin_color(img, ray, obj_result); lighting(ray, obj_result, img->spot); shadows(img, ray, obj_result); } }
void Viewer::onGraphics(RenderDevice* rd) { LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); rd->setProjectionAndCameraMatrix(app->debugCamera); // Cyan background rd->setColorClearValue(Color3(0.1f, 0.5f, 1.0f)); rd->clear(app->sky.isNull(), true, true); if (app->sky.notNull()) { app->sky->render(rd, lighting); } rd->enableLighting(); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); rd->setAmbientLightColor(lighting.ambient); CoordinateFrame camera = rd->getCameraToWorldMatrix(); app->bumpShader->args.set("wsLightPos", Vector4(lighting.lightDirection, 0)); app->bumpShader->args.set("wsEyePos", camera.translation); app->bumpShader->args.set("texture", app->textureMap); app->bumpShader->args.set("normalBumpMap", app->normalBumpMap); app->bumpShader->args.set("reflectivity", 0);//0.35); app->bumpShader->args.set("specularity", 0);//0.4); app->bumpShader->args.set("bumpScale", bumpScale); app->bumpShader->args.set("environmentMap", app->sky->getEnvironmentMap()); rd->setShader(app->bumpShader); debugAssertGLOk(); for (int e = 0; e < entityArray.size(); ++e) { entityArray[e]->render(rd); debugAssertGLOk(); } rd->setShader(NULL); rd->disableLighting(); if (app->sky.notNull()) { app->sky->renderLensFlare(rd, lighting); } }
const void Scene::draw() { // Clear buffers glClearColor(0, 0, 0, 1); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); // Lighting lighting(); // Projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10, 10, -7.5, 7.5, -10, 60); // Modelview matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Camera glTranslatef(0, 0, -10); // Move 10 units backwards in z, since camera is at origin // Rotation glRotatef(10, 1, 0, 0); glRotatef(rotation, 0, 1, 0); // Translation glTranslatef(0, -2, 0); // Scale glScalef(scale, scale, scale); // Objects setMaterialColor(0, 1, 1); //gluSphere(gluNewQuadric(), 2, 50, 50); for (auto& object : renderObjects) { object->draw(); } }
void display(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glPushMatrix(); glRotatef((GLfloat) turn, 0.0, 1.0, 0.0); glRotatef((GLfloat) turn1, 1.0, 0.0, 0.0); #ifdef LIGHT if (solid_part) { glPushMatrix(); lighting(); glPopMatrix(); } else disable(); #endif #ifdef DRAW_MECH glPushMatrix(); glTranslatef(0.0, elevation, 0.0); DrawMech(); glPopMatrix(); #endif #ifdef DRAW_ENVIRO glPushMatrix(); if (distance >= 20.136) distance = 0.0; glTranslatef(0.0, -5.0, -distance); glCallList(SOLID_ENVIRO); glTranslatef(0.0, 0.0, 10.0); glCallList(SOLID_ENVIRO); glPopMatrix(); #endif glPopMatrix(); glFlush(); glutSwapBuffers(); }
int main(int argc, char* argv[]){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(windowWidth,windowWidth); glutInitWindowPosition(windowX,windowY); shape = readShapeFile(fileName); //load the shape into a winged-edge data structure //readShapeFile(fileName); scaled(shape); normalize(shape); vertexNormalize(shape); myWindow = glutCreateWindow("CMPT 764"); glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); //glShadeModel(GL_FLAT); //glShadeModel(GL_SMOOTH); lighting(); buildInterface(); glutMainLoop(); return 0; }
void doGraphics() { LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); renderDevice->beginFrame(); // Cyan background glClearColor(0.1f, 0.5f, 1.0f, 0.0f); renderDevice->clear(true, true, true); renderDevice->pushState(); renderDevice->setProjectionAndCameraMatrix(camera); renderDevice->enableLighting(); renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); Draw::axes(renderDevice); renderDevice->popState(); renderDevice->endFrame(); }
void GLWidget::draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(m_using_bloom) { m_fbo->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); m_zpos = sin(m_counter/500.0)*20; m_ypos = cos(m_counter/500.0)*20; m_counter++; glDisable(GL_DEPTH_TEST); cam->transformCamera(); glPushMatrix(); glLoadIdentity(); glRotatef(-cam->pitch, 1.0,0.0,0.0); glRotatef(-cam->yaw, 0.0,1.0,0.0); skybox->draw(); lighting(); if(m_using_bloom && m_bloom_not_broken) { glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuf); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width(), height()); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuf); } glEnable(GL_DEPTH_TEST); if(m_displaying_particles) { m_particles->draw(); } if(m_toon_lighting) { m_toonShader->bind(); } else { m_plainShader->bind(); } change_current_chunk(); if(m_fps_camera) { glTranslatef(-2.5, 0, -2.5); glPopMatrix(); } else { glTranslatef(0.0, 0.0, -7.0); glRotatef(m_xrot, 1.0, 0.0, 0.0); glRotatef(m_yrot, 0.0, 1.0, 0.0); glScalef(0.5, 0.5, 0.5); glScalef(m_zoom, m_zoom, m_zoom); } glPushMatrix(); if(!m_fps_camera) { glTranslatef(m_map->curx-2.5, 0.0, m_map->curz-2.5); } m_nchunk->draw(); m_nwchunk->draw(); m_wchunk->draw(); m_swchunk->draw(); m_schunk->draw(); m_sechunk->draw(); m_echunk->draw(); m_nechunk->draw(); m_centerchunk->draw(); glPopMatrix(); glLoadIdentity(); char cameraLocation[100]; sprintf(cameraLocation, "x:%2.3f y:%2.3f z:%2.3f yaw:%2.3f pitch:%2.3f", cam->x, cam->y, cam->z, cam->yaw, cam->pitch); glColor3f(1.0,1.0,1.0); renderText(0,30, cameraLocation); char chunkloc[80]; sprintf(chunkloc, "Chunk (%4i, %4i)", m_map->curx, m_map->curz); renderText(0,50, chunkloc); if(m_toon_lighting) { m_toonShader->release(); } else { m_plainShader->release(); } if(m_using_bloom) { m_fbo->release(); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); m_bloomShader->draw(m_fbo->texture(), m_width); } }
void Demo::onGraphics(RenderDevice* rd) { rd->clear(sky == NULL, true, false); rd->setProjectionAndCameraMatrix(app->debugCamera); LightingParameters lighting(gameTime, false); if (sky.notNull()) { sky->render(rd, lighting); } rd->pushState(); // Setup lighting rd->setSpecularCoefficient(1); rd->setShininess(64); debugAssertGLOk(); rd->enableLighting(); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); rd->setLight(1, GLight::directional(-lighting.lightDirection, Color3::white() * .25, false)); rd->setAmbientLightColor(lighting.ambient); rd->setShadeMode(RenderDevice::SHADE_SMOOTH); static const Color3 color[] = {Color3::black(), Color3::white(), Color3::orange(), Color3::blue()}; double t[2]; Vector3 c[2]; t[0] = System::time(); t[1] = t[0] + 0.01; // Draw the planes for (int x = 0; x < N; ++x) { for (int i = 0; i < 2; ++i) { double a = x + t[i] + 2; double a2 = t[i] * (x + 1) * .01 + 1005.1; c[i] = Vector3(cos(a) * (10 + x / 2.0), sin(a2) * 10, sin(a) * 15); } CoordinateFrame cframe(c[0]); double a = t[0] * (x + 1) * .1; cframe.lookAt(c[1], Vector3(cos(a), 3, sin(a)).direction()); rd->setColor(color[x % 4]); model->render(rd, cframe, lighting, varStream); } rd->popState(); if (sky.notNull()) { sky->renderLensFlare(rd, lighting); } rd->push2D(); char* str = NULL; switch (renderMethod) { case TRIANGLES: str = "Using begin/end (SPACE to change)"; break; case VARSTREAM: str = "Using streaming vertex array (SPACE to change)"; break; case VARSTATIC: str = "Using static vertex array (SPACE to change)"; break; default:; } app->debugFont->draw2D(rd, str, Vector2(10, rd->height() - 40), 20, Color3::yellow(), Color3::black()); rd->pop2D(); debugAssertGLOk(); varStream->reset(); }
void Demo::onGraphics(RenderDevice* rd) { LightingParameters lighting(G3D::toSeconds(2, 00, 00, AM), false); rd->setProjectionAndCameraMatrix(app->debugCamera); // Cyan background rd->setColorClearValue(Color3(0.1f, 0.5f, 1.0f)); rd->clear(app->sky.isNull(), true, true); if (app->sky.notNull()) { app->sky->render(rd, lighting); } // Create a light Vector4 wsLight(1.0f, 2.5f, 2.0f, 1.0f); // Vector4 wsLight(0,1,0,0); // Setup lighting rd->enableLighting(); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); rd->setAmbientLightColor(lighting.ambient); CoordinateFrame cframe; // Rotate the quad cframe.rotation = Matrix3::fromAxisAngle(Vector3::unitY(), System::time() * 0.1); rd->pushState(); GPUProgram::ArgList vertexArgs; rd->setObjectToWorldMatrix(cframe); // Take the light to object space Vector4 osLight = cframe.toObjectSpace(wsLight); // Take the viewer to object space Vector3 osEye = cframe.pointToObjectSpace(app->debugCamera.getCoordinateFrame().translation); vertexArgs.set("MVP", rd->getModelViewProjectionMatrix()); vertexArgs.set("osLight", osLight); vertexArgs.set("osEye", osEye); rd->setVertexProgram(parallaxVP, vertexArgs); GPUProgram::ArgList pixelArgs; pixelArgs.set("texture", texture); pixelArgs.set("normalMap", normalMap); rd->setPixelProgram(parallaxPP, pixelArgs); model.render(rd); rd->popState(); rd->disableLighting(); Draw::sphere(Sphere(wsLight.xyz(), .1f), rd, Color3::white(), Color4::clear()); if (app->sky.notNull()) { app->sky->renderLensFlare(rd, lighting); } rd->push2D(); app->debugFont->draw2D(rd, "The surface is a single quad textured with parallax bump mapping and per-pixel shading.", Vector2(10, 10), 10, Color3::white(), Color3::black()); app->debugFont->draw2D(rd, "Press TAB to toggle to first person camera controls.", Vector2(10, 30), 10, Color3::white(), Color3::black()); rd->pop2D(); }
void doGraphics() { bool screenshot = singleScreen || batchScreen; LightingParameters lighting(G3D::toSeconds(10, 00, 00, AM)); // Some models have part of their geometry stored in the "weapon" file. // Darth Maul, for example, has his lower half in the weapon. const double footy = 0.98 * min(model.boundingBox(MD2Model::STAND).getCorner(0).y, weapon.boundingBox(MD2Model::STAND).getCorner(0).y); renderDevice->beginFrame(); renderDevice->clear(true, true, true); renderDevice->pushState(); camera->setProjectionAndCameraMatrix(); beginLighting(lighting); int n = 1; if (!screenshot) { // Draw a bunch of characters for (int z = 0; z < 6; ++z) { for (int x = -2; x <= 2; ++x) { drawCharByParams(x, z, footy, n); ++n; } } } // Draw the main character { CoordinateFrame cframe(Vector3(0, -footy, -8)); if (modelTexture.size() > 0) { renderDevice->setTexture(0, modelTexture.last()); } // use global pose variable drawCharWithShadow(cframe, pose); } endLighting(); renderDevice->setObjectToWorldMatrix(CoordinateFrame()); // Ground plane (to hide parts of characters that stick through ground) renderDevice->setColor(Color3::WHITE); renderDevice->beginPrimitive(RenderDevice::QUADS); renderDevice->sendVertex(Vector3(-50, -.01, 50)); renderDevice->sendVertex(Vector3(50, -.01, 50)); renderDevice->sendVertex(Vector3(50, -.01, -50)); renderDevice->sendVertex(Vector3(-50, -.01, -50)); renderDevice->endPrimitive(); renderDevice->popState(); renderDevice->push2D(); double x = 10; double y = 10; double f = 16; int fontSize = (batchScreen) ? (22) : (30); font->draw2DString(model.name, renderDevice->getWidth()/2, renderDevice->getHeight() - 45, fontSize, Color3::BLACK, Color3::WHITE, GFont::XALIGN_CENTER); if (!screenshot) { font->draw2DString(format("%d fps", iRound(renderDevice->getFrameRate())), x, y, 20, Color3::YELLOW, Color3::BLACK); y += 30; font->draw2DString(format("%d characters", n), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString(format("%1.1f MB", model.mainMemorySize() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString(format("%1.0f Mtris/sec", renderDevice->getTriangleRate() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; x = renderDevice->getWidth() - 130; y = 10; f = 12; font->draw2DString("CLICK attack", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("SPACE jump", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("CTRL crouch", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("1 . . 5 taunt", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("6 . . 8 die", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("9 . . - pain", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("R/T run/back", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("E new character", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("Z single screen", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; } renderDevice->pop2D(); renderDevice->endFrame(); }
//display function void display(void) { glLoadIdentity(); /* clear the matrix */ //compute fps curF++; curClock = clock(); float elapsed = (curClock - startClock) / (float)CLOCKS_PER_SEC; if (elapsed>1.0f){ fps = (float)(curF - prevF) / elapsed; prevF = curF; startClock = curClock; std::string strng = "fps: " + std::to_string(fps); std::cout << strng << std::endl; } //create look at position Vector at; at.x = planeView.position.x - planeView.heading.x; at.y = planeView.position.y - planeView.heading.y; at.z = planeView.position.z - planeView.heading.z; //look at 'at' vector from planes position gluLookAt(planeView.position.x, planeView.position.y, planeView.position.z, at.x, at.y, at.z, planeView.up.x, planeView.up.y, planeView.up.z); //compute lighting lighting(); GLfloat tanamb[] = { 0.2, 0.15, 0.1, 1.0 }; GLfloat tandiff[] = { 0.4, 0.3, 0.2, 1.0 }; GLfloat tanspec[] = { 0.0, 0.0, 0.0, 1.0 }; // dirt doesn't glisten GLfloat seaamb[] = { 0.0, 0.0, 0.2, 1.0 }; GLfloat seadiff[] = { 0.0, 0.0, 0.8, 1.0 }; GLfloat seaspec[] = { 0.5, 0.5, 1.0, 1.0 }; // Single polygon, will only have highlight if light hits a vertex just right GLfloat lpos[] = { 0.0, 0.0, 10.0, 0.0 }; // sun, high noon glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); // send the light position down as if it was a vertex in world coordinates glLightfv(GL_LIGHT0, GL_POSITION, lpos); // load terrain material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, tanamb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, tandiff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, tanspec); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0); // Send terrain mesh through pipeline glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, verts); glNormalPointer(GL_FLOAT, 0, norms); glDrawElements(GL_TRIANGLES, 6 * (res - 1)*(res - 1), GL_UNSIGNED_INT, faces); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); // load water material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, seaamb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, seadiff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, seaspec); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0); // Send water as a single quad glNormal3f(0.0, 0.0, 1.0); glBegin(GL_QUADS); glVertex3f(-5, -5, sealevel); glVertex3f(5, -5, sealevel); glVertex3f(5, 5, sealevel); glVertex3f(-5, 5, sealevel); glEnd(); glutSwapBuffers(); glFlush(); glutPostRedisplay(); }
int GenericCLIInterface(int argc, char** argv, boost::shared_ptr<ElVis::Scene> scene, boost::shared_ptr<ElVis::Model> model, boost::shared_ptr<ElVis::ColorMap> colorMap, unsigned int width, unsigned int height, const std::string& outFilePath, const ElVis::Camera& c) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(100, 100); glutCreateWindow("fake"); std::cout << "Generic CLI Interface." << std::endl; const char* isovaluesLabel = "Isovalues"; const char* isosurfaceModuleEnabledLabel = "IsosurfaceModuleEnabled"; const char* volumeRenderingModuleEnabledLabel = "VolumeRenderingModuleEnabled"; const char* contourModuleEnabledLabel = "ContourModuleEnabled"; const char* meshModuleEnabledLabel = "MeshModuleEnabled"; const char* boundarySurfacesLabel = "BoundarySurfaces"; // Volume Rendering labels const char* integrationTypeLabel = "IntegrationType"; const char* breakpointLabel = "Breakpoints"; const char* colorsLabel = "Colors"; const char* hLabel = "h"; const char* epsilonLabel = "Epsilon"; const char* traceLabel = "EnableTrace"; const char* traceXLabel = "TraceX"; const char* traceYLabel = "TraceY"; const char* trackNumSamplesLabel = "TrackNumSamples"; const char* renderIntegrationTypeLabel = "RenderIntegrationType"; const char* emptySpaceSkippingLabel = "EnableEmptySpaceSkipping"; const char* cutPlaneNormalLabel = "CutPlaneNormal"; const char* cutPlanePointLabel= "CutPlanePoint"; const char* fieldLabel="Field"; const char* numTestsLabel = "NumTests"; std::vector<double> cutPlaneNormal; std::vector<double> cutPlanePoint; std::vector<double> breakpoints; std::vector<double> colors; std::vector<int> boundarySurfaces; std::vector<double> isovalues; bool isosurfaceModuleEnabled = false; bool volumeRenderingModuleEnabled = false; bool contourModuleEnabled = false; bool meshModuleEnabled = false; unsigned int numTests = 1; std::string configFile; int fieldIndex = 0; boost::program_options::options_description desc("GenericCLIOptions"); desc.add_options() (isovaluesLabel, boost::program_options::value<std::vector<double> >(&isovalues)->multitoken(), "Isovalues") (boundarySurfacesLabel, boost::program_options::value<std::vector<int> >(&boundarySurfaces)->multitoken(), "Boundary Surfaces") (isosurfaceModuleEnabledLabel, boost::program_options::value<bool>(&isosurfaceModuleEnabled), "Isosurface Module Enabled") (volumeRenderingModuleEnabledLabel, boost::program_options::value<bool>(&volumeRenderingModuleEnabled), "Volume Rendering Module Enabled") (contourModuleEnabledLabel, boost::program_options::value<bool>(&contourModuleEnabled), "Contour Module Enabled") (meshModuleEnabledLabel, boost::program_options::value<bool>(&meshModuleEnabled), "Mesh Module Enabled") (integrationTypeLabel, boost::program_options::value<int>(), "Integration Type") (breakpointLabel, boost::program_options::value<std::vector<double> >(&breakpoints)->multitoken(), "Breakpoints") (colorsLabel, boost::program_options::value<std::vector<double> >(&colors)->multitoken(), "Colors") (hLabel, boost::program_options::value<double>(), "h") (epsilonLabel, boost::program_options::value<double>(), "Epsilon") (traceLabel, boost::program_options::value<int>(), "Enable Trace") (traceXLabel, boost::program_options::value<int>(), "Trace X") (traceYLabel, boost::program_options::value<int>(), "Trace Y") (trackNumSamplesLabel, boost::program_options::value<int>(), "Track Num Samples") (renderIntegrationTypeLabel, boost::program_options::value<int>(), "RenderIntegrationType") (emptySpaceSkippingLabel, boost::program_options::value<int>(), "EnableEmptySpaceSkipping") (numTestsLabel, boost::program_options::value<unsigned int>(&numTests), "Number of Tests") (cutPlaneNormalLabel, boost::program_options::value<std::vector<double> >(&cutPlaneNormal)->multitoken(), "Cut Plane Normal") (cutPlanePointLabel, boost::program_options::value<std::vector<double> >(&cutPlanePoint)->multitoken(), "Cut Plane Point") (fieldLabel, boost::program_options::value<int>(&fieldIndex), "Field Index") ; const char* configFileNameLabel = "ConfigFile"; boost::program_options::options_description configFileOptions("ConfigFileOptions"); configFileOptions.add_options() (configFileNameLabel, boost::program_options::value<std::string>(&configFile), "Config File") ; boost::program_options::options_description commandLineOptions("CommandLineOptions"); commandLineOptions.add(desc).add(configFileOptions); boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(commandLineOptions).style(boost::program_options::command_line_style::allow_long | boost::program_options::command_line_style::long_allow_adjacent).allow_unregistered().run(), vm); boost::program_options::notify(vm); if( !configFile.empty() ) { std::ifstream inFile(configFile.c_str()); if( inFile ) { boost::program_options::store(boost::program_options::parse_config_file(inFile, desc, true), vm); boost::program_options::notify(vm); } inFile.close(); } #ifdef __GNUC__ system("nvidia-smi"); #endif ElVis::PointLight* l = new ElVis::PointLight(); ElVis::Color lightColor; lightColor.SetRed(.5); lightColor.SetGreen(.5); lightColor.SetBlue(.5); ElVis::WorldPoint lightPos(10.0, 0.0, 0.0); l->SetColor(lightColor); l->SetPosition(lightPos); scene->AddLight(l); ElVis::Color ambientColor; ambientColor.SetRed(.5); ambientColor.SetGreen(.5); ambientColor.SetBlue(.5); scene->SetAmbientLightColor(ambientColor); boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView()); view->SetCamera(c); view->SetScalarFieldIndex(fieldIndex); boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule()); view->AddRenderModule(primaryRayModule); if( cutPlaneNormal.size() == 3 && cutPlanePoint.size() == 3 ) { ElVis::WorldPoint normal(cutPlaneNormal[0], cutPlaneNormal[1], cutPlaneNormal[2]); ElVis::WorldPoint p(cutPlanePoint[0], cutPlanePoint[1], cutPlanePoint[2]); boost::shared_ptr<ElVis::Plane> cutPlane(new ElVis::Plane(normal, p)); boost::shared_ptr<ElVis::SampleVolumeSamplerObject> sampler(new ElVis::SampleVolumeSamplerObject(cutPlane)); primaryRayModule->AddObject(sampler); } if( contourModuleEnabled ) { std::cout << "Contour Module enabled. Number of isovalues = " << isovalues.size() << std::endl; boost::shared_ptr<ElVis::CutSurfaceContourModule> contourModule(new ElVis::CutSurfaceContourModule()); view->AddRenderModule(contourModule); for(unsigned int i = 0; i < isovalues.size(); ++i) { contourModule->AddIsovalue(isovalues[i]); } } if( meshModuleEnabled ) { boost::shared_ptr<ElVis::CutSurfaceMeshModule> meshModule(new ElVis::CutSurfaceMeshModule()); view->AddRenderModule(meshModule); } if( isosurfaceModuleEnabled ) { boost::shared_ptr<ElVis::IsosurfaceModule> isosurfaceModule(new ElVis::IsosurfaceModule()); view->AddRenderModule(isosurfaceModule); for(unsigned int i = 0; i < isovalues.size(); ++i) { isosurfaceModule->AddIsovalue(isovalues[i]); } } boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule()); view->AddRenderModule(colorMapperModule); colorMapperModule->SetColorMap(colorMap); if( boundarySurfaces.size() > 0) { boost::shared_ptr<ElVis::FaceObject> faceObject(new ElVis::FaceObject(scene)); boost::shared_ptr<ElVis::SampleFaceObject> obj(new ElVis::SampleFaceObject(faceObject)); primaryRayModule->AddObject(obj); for(int i = 0; i < boundarySurfaces.size(); ++i) { std::vector<int> faceIds; std::string boundaryName; model->GetBoundarySurface(boundarySurfaces[i], boundaryName, faceIds); if( faceIds.empty() ) continue; for(unsigned int j = 0; j < faceIds.size(); ++j) { obj->EnableFace(faceIds[j]); } } } if( volumeRenderingModuleEnabled ) { if( vm.count(integrationTypeLabel) == 0 ) { return 1; } if( breakpoints.size()*4 != colors.size() ) { std::cerr << "Invalid transfer specification." << std::endl; std::cerr << "Breakpoint size " << breakpoints.size() << std::endl; std::cerr << "Color size " << colors.size() << std::endl; return 1; } ElVis::VolumeRenderingIntegrationType integrationType = static_cast<ElVis::VolumeRenderingIntegrationType>(vm[integrationTypeLabel].as<int>()); double h = .1; if( vm.count(hLabel) == 1 ) { h = vm[hLabel].as<double>(); } double epsilon = .001; if( vm.count(epsilonLabel) == 1 ) { epsilon = vm[epsilonLabel].as<double>(); } bool trackNumSamples = false; if( vm.count(trackNumSamplesLabel) == 1 ) { trackNumSamples = (vm[trackNumSamplesLabel].as<int>() == 1); } bool renderIntegrationType = false; if( vm.count(renderIntegrationTypeLabel) == 1 ) { renderIntegrationType = (vm[renderIntegrationTypeLabel].as<int>() == 1); } bool enableEmptySpaceSkipping = true; if( vm.count(emptySpaceSkippingLabel) == 1 ) { enableEmptySpaceSkipping = (vm[emptySpaceSkippingLabel].as<int>() == 1); } boost::shared_ptr<ElVis::VolumeRenderingModule> m_volumeRenderingModule(new ElVis::VolumeRenderingModule()); m_volumeRenderingModule->SetIntegrationType(integrationType); m_volumeRenderingModule->SetCompositingStepSize(h); m_volumeRenderingModule->SetEpsilon(epsilon); m_volumeRenderingModule->SetRenderIntegrationType(renderIntegrationType); m_volumeRenderingModule->SetEnableEmptySpaceSkipping(enableEmptySpaceSkipping); m_volumeRenderingModule->SetTrackNumberOfSamples(trackNumSamples); // Setup the transfer function. boost::shared_ptr<ElVis::HostTransferFunction> transferFunction = m_volumeRenderingModule->GetTransferFunction(); for(unsigned int i = 0; i < breakpoints.size(); ++ i) { ElVis::Color c(colors[i*4], colors[i*4+1], colors[i*4+2], colors[i*4+3]); transferFunction->SetBreakpoint(breakpoints[i], c); } view->AddRenderModule(m_volumeRenderingModule); } boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule()); view->AddRenderModule(lighting); view->SetScene(scene); view->Resize(width, height); // Don't time to take care of initialization artifacts. view->Draw(); double* times = new double[numTests-1]; for(unsigned int testNum = 1; testNum < numTests; ++testNum) { // Repeated redraws will do nothing if we don't signal that the view has changed in some way. view->OnSceneViewChanged(*view); ElVis::Timer t = view->Draw(); times[testNum-1] = t.TimePerTest(1); } view->WriteColorBufferToFile(outFilePath.c_str()); if( numTests > 1 ) { ElVis::Stat runtimeStats(times, std::numeric_limits<ElVisFloat>::max(), numTests-1, .95); std::cout << "Average Time Per Run: " << runtimeStats.Mean << std::endl; #ifdef __GNUC__ system("nvidia-smi"); #endif } return 0; }
int ColorMapBulletNewApproachVolumeSampling(int argc, char** argv, boost::shared_ptr<ElVis::Model> model, unsigned int width, unsigned int height, const std::string& outFilePath) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(100, 100); glutCreateWindow("fake"); boost::shared_ptr<ElVis::Scene> scene(new ElVis::Scene()); scene->SetModel(model); boost::shared_ptr<ElVis::Cylinder> cylinder(new ElVis::Cylinder()); cylinder->GetTransformationMatrix()[11] = 2.0; cylinder->GetTransformationMatrix()[0] = .10001f; cylinder->GetTransformationMatrix()[5] = .10001f; cylinder->GetTransformationMatrix()[10] = .4f; ElVis::PointLight* l = new ElVis::PointLight(); ElVis::Color lightColor; lightColor.SetRed(.5); lightColor.SetGreen(.5); lightColor.SetBlue(.5); ElVis::WorldPoint lightPos(10.0, 0.0, 0.0); l->SetColor(lightColor); l->SetPosition(lightPos); scene->AddLight(l); ElVis::Color ambientColor; ambientColor.SetRed(.5); ambientColor.SetGreen(.5); ambientColor.SetBlue(.5); scene->SetAmbientLightColor(ambientColor); boost::shared_ptr<ElVis::Triangle> triangle1(new ElVis::Triangle()); triangle1->SetP0(ElVis::WorldPoint(0, -1, 0)); triangle1->SetP1(ElVis::WorldPoint(0, -1, 18)); triangle1->SetP2(ElVis::WorldPoint(0, 1, 18)); boost::shared_ptr<ElVis::Triangle> triangle2(new ElVis::Triangle()); triangle2->SetP0(ElVis::WorldPoint(0, -1, 0)); triangle2->SetP2(ElVis::WorldPoint(0, 1, 0)); triangle2->SetP1(ElVis::WorldPoint(0, 1, 18)); ElVis::Cylinder* cylinderToMap = new ElVis::Cylinder(); cylinderToMap->GetTransformationMatrix()[11] = 0; cylinderToMap->GetTransformationMatrix()[0] = .1f; cylinderToMap->GetTransformationMatrix()[5] = .1f; cylinderToMap->GetTransformationMatrix()[10] = 20.0f; boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule()); boost::shared_ptr<ElVis::SampleVolumeSamplerObject> t1Sampler(new ElVis::SampleVolumeSamplerObject(triangle1)); boost::shared_ptr<ElVis::SampleVolumeSamplerObject> t2Sampler(new ElVis::SampleVolumeSamplerObject(triangle2)); //boost::shared_ptr<ElVis::SurfaceObject> cylinderSurface(new ElVis::SurfaceObject(cylinder)); boost::shared_ptr<ElVis::SampleVolumeSamplerObject> cylinderSurface(new ElVis::SampleVolumeSamplerObject(cylinder)); primaryRayModule->AddObject(t1Sampler); primaryRayModule->AddObject(t2Sampler); primaryRayModule->AddObject(cylinderSurface); boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule()); boost::shared_ptr<ElVis::TextureColorMap> textureColorMapper(new ElVis::TextureColorMap(ElVis::GetColorMapPath() + "/diverging257.cmap")); textureColorMapper->SetMin(-.12); textureColorMapper->SetMax(0); colorMapperModule->SetColorMap(textureColorMapper); ElVis::Camera c; // Zoomed to region of interest. //c.SetParameters(ElVis::WorldPoint(.5, 0, 1.5), ElVis::WorldPoint(0, 0, 1.5), ElVis::WorldVector(0, 1, 0)); // Overall view //c.SetParameters(ElVis::WorldPoint(6, 0, 3.5), ElVis::WorldPoint(0, 0, 3.5), ElVis::WorldVector(0, 1, 0)); //c.SetParameters(ElVis::WorldPoint(1.8, 1.2, 3.0), ElVis::WorldPoint(0, 0, 1), ElVis::WorldVector(0, 1, 0)); c.SetParameters(ElVis::WorldPoint(1.8, .46, 3.7), ElVis::WorldPoint(0, 0, 2.7), ElVis::WorldVector(0, 1, 0)); boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView()); view->SetCamera(c); boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule()); view->AddRenderModule(primaryRayModule); view->AddRenderModule(colorMapperModule); view->AddRenderModule(lighting); view->SetScene(scene); view->Resize(width, height); //view->GetScene()->SetEnableOptixTrace(true); //ElVis::Point<int, ElVis::TwoD> pixel1(10, 10); //view->GetScene()->SetOptixTracePixelIndex(pixel1); view->Draw(); //std::cout << "Second pixel." << std::endl; //ElVis::Point<int, ElVis::TwoD> pixel(10, 1000-10-1); //view->GetScene()->SetOptixTracePixelIndex(pixel); //view->Draw(); //ElVis::Point<int, ElVis::TwoD> pixel2(10, 1000-10-1); //view->GetScene()->SetOptixTracePixelIndex(pixel2); //view->GetScene()->SetEnableOptixTrace(true); //view->Draw(); view->WriteColorBufferToFile(outFilePath.c_str()); return 0; }
void Assignment3::Render() { // Render VBO here glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Temp variables Mtx44 translate, rotate, scale; Mtx44 MVP; //These will be replaced by matrix stack soon Mtx44 model; Mtx44 view; Mtx44 projection; //Set all matrices to identity translate.SetToIdentity(); rotate.SetToIdentity(); scale.SetToIdentity(); model.SetToIdentity(); //Set view matrix using camera settings viewStack.LoadIdentity(); viewStack.LookAt( camera.position.x, camera.position.y, camera.position.z, camera.target.x, camera.target.y, camera.target.z, camera.up.x, camera.up.y, camera.up.z ); //Set projection matrix to perspective mode projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 10000.0f); //FOV, Aspect Ratio, Near plane, Far plane lighting(); lighting2(); modelStack.PushMatrix(); modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z); modelStack.Scale(0.1f, 0.1f, 0.1f); renderMesh(meshList[GEO_LIGHTBALL], false); modelStack.PopMatrix(); /*modelStack.PushMatrix(); renderMesh(meshList[GEO_AXES], false); modelStack.PopMatrix();*/ modelStack.PushMatrix(); modelStack.Translate(boxX, 496.9, boxZ); RenderSkybox(); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowWallCoord.x, 0, snowWallCoord.z); modelStack.Rotate(-90, 0, 1, 0); //modelStack.Scale(10, 10, 10); renderMesh(meshList[GEO_SNOWWALL], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowBallCoord.x, snowBallCoord.y, snowBallCoord.z); modelStack.Scale(0.2, 0.2, 0.2); renderMesh(meshList[GEO_SNOWBALLPILE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowBallCoord1.x, snowBallCoord1.y, snowBallCoord1.z); modelStack.Scale(0.2, 0.2, 0.2); renderMesh(meshList[GEO_SNOWBALLPILE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowBallCoord2.x, snowBallCoord2.y, snowBallCoord2.z); modelStack.Scale(0.2, 0.2, 0.2); renderMesh(meshList[GEO_SNOWBALLPILE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowBallCoord5.x, snowBallCoord5.y, snowBallCoord5.z); modelStack.Scale(0.2, 0.2, 0.2); renderMesh(meshList[GEO_SNOWBALLPILE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowBallCoord6.x, snowBallCoord6.y, snowBallCoord6.z); modelStack.Scale(0.2, 0.2, 0.2); renderMesh(meshList[GEO_SNOWBALLPILE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(robbyCoord.x, robbyCoord.y, robbyCoord.z); modelStack.Scale(0.5, 0.5, 0.5); modelStack.Rotate(robbyRotate, 0, 1, 0); modelStack.Rotate(-90, 0, 1, 0); renderMesh(meshList[GEO_ROBBY], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(0, -1, 0); modelStack.Rotate(-90, 0, 1, 0); modelStack.Scale(1500, 1500, 1500); renderMesh(meshList[GEO_BOTTOM], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(snowBarricadeCoord.x, snowBarricadeCoord.y, snowBarricadeCoord.z); renderMesh(meshList[GEO_SNOWBARRICADE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); //modelStack.Translate(snowBarricadeCoord.x, snowBarricadeCoord.y, snowBarricadeCoord.z); modelStack.Scale(7.5, 7.5, 7.5); renderMesh(meshList[GEO_SNOWFORT], true); modelStack.PopMatrix(); if (throwSnowball == true) { modelStack.PushMatrix(); modelStack.Translate(ballCoord.x, ballCoord.y, ballCoord.z); modelStack.Scale(0.2, 0.2, 0.2); renderMesh(meshList[GEO_SPHERE], true); modelStack.PopMatrix(); } std::stringstream playerPos; playerPos << "X = " << camPosX << " Y = " << camPosY << " Z = " << camPosz; //RenderTextOnScreen(meshList[GEO_TEXT], playerPos.str(), Color(1, 0, 0), 2, 0, 18); std::stringstream ss; ss << "FPS:" << fps<<" "<<playerPos.str(); RenderTextOnScreen(meshList[GEO_TEXT], ss.str(), Color(0, 1, 0), 3, 0, 19); std::stringstream snowballcount; snowballcount << "Snow Ball Count: " << snowBallCount; RenderTextOnScreen(meshList[GEO_TEXT], snowballcount.str(), Color(0, 1, 0), 3, 0, 1); if (showdialog1 == true) { RenderTextOnScreen(meshList[GEO_TEXT], "Hi Pingu, can you get me 1 snowball?", Color(1, 0, 1), 2, 0, 15); } if (showdialog2 == true) { RenderTextOnScreen(meshList[GEO_TEXT], "Thank You!", Color(1, 0, 1), 2, 0, 15); } if (showdialog3 == true || showdialog5 == true || showdialog7 == true || showdialog13 == true || showdialog15 == true) { RenderTextOnScreen(meshList[GEO_TEXT], "Gained 1 Snow Ball, Max capacity", Color(1, 0, 1), 2, 0, 15); } if (showdialog4 == true || showdialog6 == true || showdialog8 == true || showdialog14 == true || showdialog16 == true) { RenderTextOnScreen(meshList[GEO_TEXT], "You can only hold 1 Snow Ball!", Color(1, 0, 1), 2, 0, 15); } if (isHit == true) { RenderTextOnScreen(meshList[GEO_TEXT], "NICE SHOT", Color(1, 0, 1), 3, 0, 18); } }
void GanonIntro::update() { /* ************************ * GANON INTRO SEQUENCE * ************************ -25 DOT updates -24 LINK in 0 TRIFORCE overhead - code begins at this point (counter == 0) 47 GANON in 58 LIGHT step 68 LIGHT step 78 LIGHT step 255 TRIFORCE out 256 TRIFORCE in 270 TRIFORCE out 271 GANON out, LINK face up */ if(counter==47) { music_stop(); stop_sfx(WAV_ROAR); sfx(WAV_GASP); sfx(WAV_GANON); int Id=0; for(int i=0; i<eMAXGUYS; i++) { if(guysbuf[i].flags2&eneflag_ganon) { Id=i; break; } } if(current_item(itype_ring)) addenemy(160,96,Id,0); else addenemy(80,32,Id,0); } else if(counter==48) { lighting(true,true); // Hmm. -L counter += 30; } //NES Z1, the triforce vanishes for one frame in two cases //while still showing Link's two-handed overhead sprite. else if(counter==255 || counter==270) link.setHeldItem(-1); else if(counter==256) link.setHeldItem(getItemID(itemsbuf,itype_triforcepiece,1)); counter++; if(counter<271) return; link.setAction(none); link.dir=up; if(!getmapflag() && (tunes[MAXMIDIS-1].data)) jukebox(MAXMIDIS-1); else playLevelMusic(); currcset=DMaps[currdmap].color; showCurrentDMapIntro(); cont_sfx(WAV_ROAR); finish(); }
void SceneLight2::Render() { // Render VBO here glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Temp variables Mtx44 translate, rotate, scale; Mtx44 MVP; //These will be replaced by matrix stack soon Mtx44 model; Mtx44 view; Mtx44 projection; //Set all matrices to identity translate.SetToIdentity(); rotate.SetToIdentity(); scale.SetToIdentity(); model.SetToIdentity(); //Set view matrix using camera settings viewStack.LoadIdentity(); viewStack.LookAt( camera.position.x, camera.position.y, camera.position.z, camera.target.x, camera.target.y, camera.target.z, camera.up.x, camera.up.y, camera.up.z ); //Set projection matrix to perspective mode projection.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); //FOV, Aspect Ratio, Near plane, Far plane lighting(); lighting2(); modelStack.PushMatrix(); modelStack.Translate(light[0].position.x, light[0].position.y, light[0].position.z); modelStack.Scale(0.5f, 0.5f, 0.5f); renderMesh(meshList[GEO_LIGHTBALL], false); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(light[1].position.x, light[1].position.y, light[1].position.z); modelStack.Scale(0.5f, 0.5f, 0.5f); renderMesh(meshList[GEO_LIGHTBALL], false); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(0, 0, 0); renderMesh(meshList[GEO_SPHERE], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(2, 0, 0); renderMesh(meshList[GEO_SPHERE1], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(-2, 0, 0); renderMesh(meshList[GEO_SPHERE2], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(2, 0, 2); renderMesh(meshList[GEO_SPHERE3], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(-2, 0, 2); renderMesh(meshList[GEO_SPHERE4], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(0, 0, 2); renderMesh(meshList[GEO_SPHERE5], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(0, 0, -2); renderMesh(meshList[GEO_SPHERE6], true); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(2, 0, -2); renderMesh(meshList[GEO_SPHERE7], true); modelStack.PopMatrix(); /*modelStack.PushMatrix(); modelStack.Translate(-2, 0, -2); renderMesh(meshList[GEO_CYLINDER], true); modelStack.PopMatrix();*/ //modelStack.PopMatrix(); modelStack.PushMatrix(); renderMesh(meshList[GEO_AXES], false); modelStack.PopMatrix(); modelStack.PushMatrix(); modelStack.Translate(0, -1, 0); modelStack.Scale(10, 10, 10); renderMesh(meshList[GEO_QUAD], true); modelStack.PopMatrix(); }
//-------------------------------------------------------------------------------------------------- /// Draw the legend using immediate mode OpenGL //-------------------------------------------------------------------------------------------------- void OverlayColorLegend::renderLegendImmediateMode(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout) { #ifdef CVF_OPENGL_ES CVF_UNUSED(layout); CVF_FAIL_MSG("Not supported on OpenGL ES"); #else CVF_TIGHT_ASSERT(layout); CVF_TIGHT_ASSERT(layout->size.x() > 0); CVF_TIGHT_ASSERT(layout->size.y() > 0); Depth depth(false); depth.applyOpenGL(oglContext); Lighting_FF lighting(false); lighting.applyOpenGL(oglContext); // All vertices. Initialized here to set Z to zero once and for all. static float vertexArray[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, }; // Per vector convenience pointers float* v0 = &vertexArray[0]; float* v1 = &vertexArray[3]; float* v2 = &vertexArray[6]; float* v3 = &vertexArray[9]; float* v4 = &vertexArray[12]; // Constant coordinates v0[0] = v3[0] = layout->x0; v1[0] = v4[0] = layout->x1; // Render color bar as one colored quad per pixel int legendHeightPixelCount = static_cast<int>(layout->tickPixelPos->get(m_tickValues.size() - 1) - layout->tickPixelPos->get(0) + 0.01); if (m_scalarMapper.notNull()) { int iPx; for (iPx = 0; iPx < legendHeightPixelCount; iPx++) { const Color3ub& clr = m_scalarMapper->mapToColor(m_scalarMapper->domainValue((iPx+0.5)/legendHeightPixelCount)); float y0 = static_cast<float>(layout->legendRect.min().y() + iPx); float y1 = static_cast<float>(layout->legendRect.min().y() + iPx + 1); // Dynamic coordinates for rectangle v0[1] = v1[1] = y0; v3[1] = v4[1] = y1; // Draw filled rectangle elements glColor3ubv(clr.ptr()); glBegin(GL_TRIANGLE_FAN); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v4); glVertex3fv(v3); glEnd(); } } // Render frame // Dynamic coordinates for tickmarks-lines bool isRenderingFrame = true; if (isRenderingFrame) { v0[0] = v2[0] = layout->legendRect.min().x()-0.5f; v1[0] = v3[0] = layout->legendRect.max().x()-0.5f; v0[1] = v1[1] = layout->legendRect.min().y()-0.5f; v2[1] = v3[1] = layout->legendRect.max().y()-0.5f; glColor3fv(m_color.ptr()); glBegin(GL_LINES); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v3); glVertex3fv(v2); glVertex3fv(v2); glVertex3fv(v0); glEnd(); } // Render tickmarks bool isRenderingTicks = true; if (isRenderingTicks) { // Constant coordinates v0[0] = layout->x0; v1[0] = layout->x1 - 0.5f*(layout->tickX - layout->x1) - 0.5f; v2[0] = layout->x1; v3[0] = layout->tickX - 0.5f*(layout->tickX - layout->x1) - 0.5f; v4[0] = layout->tickX; size_t ic; for (ic = 0; ic < m_tickValues.size(); ic++) { float y0 = static_cast<float>(layout->legendRect.min().y() + layout->tickPixelPos->get(ic) - 0.5f); // Dynamic coordinates for tickmarks-lines v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0; glColor3fv(m_color.ptr()); glBegin(GL_LINES); if ( m_visibleTickLabels[ic]) { glVertex3fv(v0); glVertex3fv(v4); } else { glVertex3fv(v2); glVertex3fv(v3); } glEnd(); } } // Reset render states Lighting_FF resetLighting; resetLighting.applyOpenGL(oglContext); Depth resetDepth; resetDepth.applyOpenGL(oglContext); CVF_CHECK_OGL(oglContext); #endif // CVF_OPENGL_ES }
void userSettings(void) { lighting(currentLighting); materials(currentMaterials); if ( lightingEnabled ) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } else { glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); } if ( smoothEnabled ) { glShadeModel(GL_SMOOTH); } else { glShadeModel(GL_FLOAT); } if ( idleSpin ) { glutIdleFunc(spinCube); } else { glutIdleFunc(NULL); } if ( texEnabled ) { glEnable(GL_TEXTURE_2D); } else { glDisable(GL_TEXTURE_2D); } if ( fastTexture ) { glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); } else { glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); } if ( mipmapEnabled ) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); } else { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } if ( fogEnabled ) { float fogColor[] = {0.7, 0.6, 0.6, 1.0}; glClearColor(fogColor[0], fogColor[1], fogColor[2], fogColor[3]); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_DENSITY, 1.0); glFogf(GL_FOG_START, zNear); glFogf(GL_FOG_END, zFar); glFogfv(GL_FOG_COLOR, fogColor); } else { glDisable(GL_FOG); glClearColor(0.0, 0.0, 0.0, 1.0 ); } if ( lineAAEnabled ) glEnable(GL_BLEND); else glDisable(GL_BLEND); if ( lineAAEnabled ) { glEnable( GL_LINE_SMOOTH ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } else { glDisable( GL_LINE_SMOOTH ); } if ( depthEnabled ) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if ( perspectiveXform ) { glFrustum(-1.25, 1.25, -1.25, 1.25, zNear, zFar); viewxform_z = -5.0; } else { glOrtho(-2.0, 2.0, -2.0, 2.0, zNear, zFar); viewxform_z = -5.0; } glMatrixMode(GL_MODELVIEW); }