示例#1
0
inline bool
load_texture(TEXTUREglptr& tex)
{
   // Load the texture (should be already allocated TEXTUREgl
   // with filename set as member variable).
   //
   // Note: Does not activate the texture.
   //
   // This is a no-op of the texture was previously loaded.

   if (!tex) {
      return false;
   } else if (tex->is_valid()) {
      return true;
   } else if (tex->load_attempt_failed()) {
      // we previously tried to load this texture and failed.
      // no sense trying again with the same filename.
      return false;
   }

   return tex->load_texture();
}
示例#2
0
void 
SKY_BOX::test_perlin(CVIEWptr &v)
{
   //test
   if (!perlin_tex) {
      perlin_tex = make_shared<TEXTUREgl>(
         Config::JOT_ROOT() +
         "nprdata/other_textures/" +
         "perlin_tex_RGB.png"
         );
      perlin_tex->load_texture();
   }
   assert(perlin_tex);
   if (perlin_tex->load_attempt_failed()) {
      cerr << "SKY_BOX::test_perlin: could not load file: "
           << perlin_tex->file()
           << endl;
      return;
   }
   
   // load identity for model matrix
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();

   // set up to draw in XY coords:
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadMatrixd(VIEW::peek()->xypt_proj().transpose().matrix());

   // set opengl state:
   glPushAttrib(GL_ENABLE_BIT);
   glDisable(GL_LIGHTING);
   glEnable(GL_TEXTURE_2D);
   glDisable(GL_CULL_FACE);
   glDisable(GL_DEPTH_TEST); // prevents depth testing AND writing to depth buffer
   glDisable(GL_ALPHA_TEST);
   //glDisable(GL_BLEND);

   perlin_tex->apply_texture(); // GL_ENABLE_BIT

   GLfloat a = 0.5f;
   glColor4f(0.5, 0.5, 0.5, 1);
   glBegin(GL_QUADS);
   // draw vertices in CCW order starting at bottom left:
   glTexCoord2f( 0,  0);
   glVertex2f  (-a, -a);
   glTexCoord2f( 1,  0);
   glVertex2f  ( a, -a);
   glTexCoord2f( 1,  1);
   glVertex2f  ( a,  a);
   glTexCoord2f( 0,  1);
   glVertex2f  (-a,  a);
   glEnd();

   // restore state:
   glPopAttrib();

   // restore projection matrix
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();

   // restore modelview matrix
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix();

}