| 18 | using namespace ci::app; |
| 19 | |
| 20 | Earth::Earth() |
| 21 | : mLoc( 0 ), mRadius( 250 ), mMinMagToRender( 2 ), mNumQuakes( 0 ) |
| 22 | { |
| 23 | mLightDir = glm::normalize( vec3( 0.025f, 0.25f, 1.0f ) ); |
| 24 | |
| 25 | // Load the textures for the Earth. |
| 26 | auto fmt = gl::Texture2d::Format().wrap( GL_REPEAT ).mipmap().minFilter( GL_LINEAR_MIPMAP_LINEAR ); |
| 27 | mTexDiffuse = gl::Texture2d::create( loadImage( loadResource( RES_EARTHDIFFUSE ) ), fmt ); |
| 28 | mTexNormal = gl::Texture2d::create( loadImage( loadResource( RES_EARTHNORMAL ) ), fmt ); |
| 29 | mTexMask = gl::Texture2d::create( loadImage( loadResource( RES_EARTHMASK ) ), fmt ); |
| 30 | |
| 31 | // Create the Earth mesh with a custom shader. |
| 32 | auto earthShader = gl::GlslProg::create( loadResource( RES_PASSTHRU_VERT ), loadResource( RES_EARTH_FRAG ) ); |
| 33 | earthShader->uniform( "texDiffuse", 0 ); |
| 34 | earthShader->uniform( "texNormal", 1 ); |
| 35 | earthShader->uniform( "texMask", 2 ); |
| 36 | mEarth = gl::Batch::create( geom::Sphere().radius( mRadius ).subdivisions( 120 ), earthShader ); |
| 37 | |
| 38 | // Create a cone mesh with a custom shader, which we use to visualize earthquakes. |
| 39 | gl::VboMeshRef mesh = gl::VboMesh::create( geom::Cone().height( 1 ).ratio( 0.25f ).subdivisionsHeight( 6 ).subdivisionsAxis( 30 ) ); |
| 40 | |
| 41 | // Create an array of initial per-instance model matrices. |
| 42 | std::vector<mat4> transforms; |
| 43 | transforms.resize( MAX_NUMBER_OF_QUAKES ); |
| 44 | |
| 45 | // Create the VBO which will contain per-instance (rather than per-vertex) data. |
| 46 | mInstanceDataVbo = gl::Vbo::create( GL_ARRAY_BUFFER, transforms.size() * sizeof( mat4 ), transforms.data(), GL_STATIC_DRAW ); |
| 47 | |
| 48 | // We need a geom::BufferLayout to describe this data as mapping to the CUSTOM_0 semantic, |
| 49 | // and the 1 (rather than 0) as the last param indicates per-instance (rather than per-vertex). |
| 50 | geom::BufferLayout instanceDataLayout; |
| 51 | instanceDataLayout.append( geom::Attrib::CUSTOM_0, 16, sizeof( mat4 ), 0, 1 /* per instance */ ); |
| 52 | |
| 53 | // Now add it to the VboMesh we already made of the Cone. |
| 54 | mesh->appendVbo( instanceDataLayout, mInstanceDataVbo ); |
| 55 | |
| 56 | // And finally, build our batch, mapping our CUSTOM_0 attribute to the "iModelMatrix" GLSL vertex attribute. |
| 57 | auto quakeShader = gl::GlslProg::create( loadResource( RES_QUAKE_VERT ), loadResource( RES_QUAKE_FRAG ) ); |
| 58 | mQuake = gl::Batch::create( mesh, quakeShader, { { geom::Attrib::CUSTOM_0, "iModelMatrix" } } ); |
| 59 | } |
| 60 | |
| 61 | void Earth::update() |
| 62 | { |
nothing calls this directly
no test coverage detected