bool GLSLShader::activate_texture(TEXTUREglptr& tex) { // Load (if needed) and activate the texture. if (!load_texture(tex)) { bool debug=true; if (debug) { cerr << "GLSLShader::activate_texture: can't load texture: " << (tex ? tex->file() : "null pointer") << " at texture unit " << (tex ? tex->get_raw_unit() : -1) << endl; } return false; } tex->apply_texture(); if (debug) { char tmp[64]; sprintf(tmp, "%d", tex->get_raw_unit()); GL_VIEW_PRINT_GL_ERRORS( string("activating texture ") + (tex ? tex->file() : "null pointer") + " at unit " + tmp); } return true; }
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(); }