void testApp::generateVBOs() { // If the meshes have already been generated once, we need to clear their data vboMeshOriginal.clear(); vboMeshMirrored.clear(); // Shorthand to make the equations more readable // r is the radius of a circle that is inscribed by the display window // a is the current angle heading we will use to sample the image // da is half the span of the triangle float r = minWindowDimension/2.0; float a = ofDegToRad(imageSectionHeading); float da = ofDegToRad(triangleAngularWidth/2); // Define the vertices of the triangular face ofVec3f triangleBottom(0, 0, 0); ofVec3f triangleLeft(r*cos(a+da), -r*sin(a+da), 0); // Flip because of drawing ofVec3f triangleRight(r*cos(a-da), -r*sin(a-da), 0); // Flip because of drawing float cx = imageSectionCenter.x; float cy = imageSectionCenter.y; r = minImageDimension/2.0; // Define the triangular section of the image that we want to draw on the face ofVec2f textureBottom(cx, cy); ofVec2f textureLeft(cx+r*cos(a+da), cy-r*sin(a+da)); ofVec2f textureRight(cx+r*cos(a-da), cy-r*sin(a-da)); // Add the vertices to the VBO mesh to form a triangle addFace(vboMeshOriginal, triangleBottom, triangleLeft, triangleRight); addFace(vboMeshMirrored, triangleBottom, triangleLeft, triangleRight); // Add the texture coordinates to the mesh addTexture(vboMeshOriginal, textureBottom, textureLeft, textureRight); addTexture(vboMeshMirrored, textureBottom, textureRight, textureLeft); }
void TutorialScene::loadData() { addTexture("font", "data/image/character.png"); addTexture("atackStart", "data/image/script/atackStart.png", 1); addTexture("now", "data/image/script/nowLoading.png", 1); addTexture("inst", "data/image/instruction.bmp"); }
void cVisual::setMousePointer(int type) { mouse.type = type; if (mouse.type == POINTER_HARDWARE) { mouse.showHardware(); } else if (mouse.type == POINTER_DEFAULT) { mouse.texture = database.texture[TEX_MOUSE_DEFAULT]; mouse.texturePress = database.texture[TEX_MOUSE_DEFAULTPRESS]; } else if (mouse.type == POINTER_POINT) { mouse.texture = database.texture[TEX_MOUSE_POINT]; mouse.texturePress = database.texture[TEX_MOUSE_POINT]; } else if (mouse.type == POINTER_TARGET) { mouse.texture = database.texture[TEX_MOUSE_TARGET]; mouse.texturePress = database.texture[TEX_MOUSE_TARGET]; } else if (mouse.type == POINTER_NONE) { mouse.texture = addTexture("alpha.png"); mouse.texturePress = addTexture("alpha.png"); } // Hide hardware pointer mouse.hideHardware(); if (mouse.type != POINTER_HARDWARE) { mouse.hideHardware(); } }
/* TextureXList::readTEXTURESData * Reads in a ZDoom-format TEXTURES entry. Returns true on success, * false otherwise *******************************************************************/ bool TextureXList::readTEXTURESData(ArchiveEntry* entry) { // Check for empty entry if (!entry) { Global::error = "Attempt to read texture data from NULL entry"; return false; } if (entry->getSize() == 0) { txformat = TXF_TEXTURES; return true; } // Get text to parse Tokenizer tz; tz.openMem(&(entry->getMCData()), entry->getName()); // Parsing gogo string token = tz.getToken(); while (!token.IsEmpty()) { // Texture definition if (S_CMPNOCASE(token, "Texture")) { CTexture* tex = new CTexture(); if (tex->parse(tz, "Texture")) addTexture(tex); } // Sprite definition if (S_CMPNOCASE(token, "Sprite")) { CTexture* tex = new CTexture(); if (tex->parse(tz, "Sprite")) addTexture(tex); } // Graphic definition if (S_CMPNOCASE(token, "Graphic")) { CTexture* tex = new CTexture(); if (tex->parse(tz, "Graphic")) addTexture(tex); } // WallTexture definition if (S_CMPNOCASE(token, "WallTexture")) { CTexture* tex = new CTexture(); if (tex->parse(tz, "WallTexture")) addTexture(tex); } // Flat definition if (S_CMPNOCASE(token, "Flat")) { CTexture* tex = new CTexture(); if (tex->parse(tz, "Flat")) addTexture(tex); } token = tz.getToken(); } txformat = TXF_TEXTURES; return true; }
void Entity::initTextures() { /*Player Textures*/ //Standing addTexture("S-RIGHT", "assets/player/stand_right.png"); addTexture("S-LEFT", "assets/player/stand_left.png"); //Running addTextures("R-RIGHT", "assets/player/run_right_", 8); addTextures("R-LEFT", "assets/player/run_left_", 8); /*Planet Textures*/ addTexture("Planet1", "assets/new_planet.png"); /*Asteroid Textures*/ addTexture("Asteroid1", "assets/asteroid_1.png"); addTexture("Asteroid2", "assets/asteroid_2.png"); addTexture("Asteroid3", "assets/asteroid_3.png"); addTexture("Asteroid4", "assets/asteroid_4.png"); /*Bullets*/ addTexture("Bullet", "assets/bullet.png"); /*Items*/ addTexture("Health", "assets/health.png"); }
//! loads a Texture ITexture* CNullDriver::getTexture(IReadFile* file) { ITexture* texture = 0; if (file) { texture = findTexture(file->getFileName()); if (texture) return texture; texture = loadTextureFromFile(file); if (texture) { addTexture(texture); texture->releaseRef(); // drop it because we created it, one grab too much } if (!texture) Printer::log("Could not load texture", file->getFileName(), ELL_WARNING); } return texture; }
void FontAtlas::reinit() { if (_currentPageData) { delete []_currentPageData; _currentPageData = nullptr; } auto texture = new (std::nothrow) Texture2D; _currentPageDataSize = CacheTextureWidth * CacheTextureHeight; auto outlineSize = _fontFreeType->getOutlineSize(); if(outlineSize > 0) { _lineHeight += 2 * outlineSize; _currentPageDataSize *= 2; } _currentPageData = new (std::nothrow) unsigned char[_currentPageDataSize]; memset(_currentPageData, 0, _currentPageDataSize); auto pixelFormat = outlineSize > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8; texture->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) ); addTexture(texture,0); texture->release(); }
bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format) { if (size.width() > m_maxTextureSize || size.height() > m_maxTextureSize) return false; TextureMap::iterator it = m_textures.find(token); if (it != m_textures.end()) { ASSERT(it->second.size != size || it->second.format != format); removeTexture(token, it->second); } size_t memoryRequiredBytes = memoryUseBytes(size, format); if (memoryRequiredBytes > m_maxMemoryLimitBytes) return false; reduceMemoryToLimit(m_maxMemoryLimitBytes - memoryRequiredBytes); if (m_memoryUseBytes + memoryRequiredBytes > m_maxMemoryLimitBytes) return false; TextureInfo info; info.size = size; info.format = format; info.textureId = 0; info.isProtected = true; #ifndef NDEBUG info.allocator = 0; #endif addTexture(token, info); return true; }
int main() { // Load frames std::cout << "Loading frames" << std::endl; auto frames = Frame3D::loadFrames("../3dframes/"); // Merge clouds std::cout << "Merge clouds" << std::endl; pcl::PointCloud<pcl::PointNormal> mergedCloud; pcl::PointCloud<pcl::PointNormal>::Ptr mergedCloudPtr(&mergedCloud); mergePointClouds(frames, mergedCloud); // Construct mesh std::cout << "Construct Mesh" << std::endl; auto mesh = constructMesh (mergedCloudPtr); // Add texture to point cloud std::cout << "Add texture" << std::endl; addTexture(mesh, frames); // Visualize mesh std::cout << "Visualise mesh" << std::endl; visualiseMesh(mesh); return 1; }
int TextureManager::getTextureID( const char* name, bool reportFail ) { if (!name) { DEBUG2("Could not get texture ID; no provided name\n"); return -1; } std::string texName = name; // see if we have the texture TextureNameMap::iterator it = textureNames.find(texName); if (it != textureNames.end()) { return it->second.id; } else { // we don't have it so try and load it FileTextureInit file; file.filter = OpenGLTexture::LinearMipmapLinear; file.name = texName; ImageInfo info; OpenGLTexture *image = loadTexture(file, reportFail); if (!image) { DEBUG2("Image not found or unloadable: %s\n", name); return -1; } return addTexture(name, image); } return -1; }
AnimatedTexture::AnimatedTexture(GLuint textureID) { addTexture(textureID); currentIndex = 0; lastTime = glfwGetTime(); changeDelay.push_back(1.0); }
void updateTextures() { for(auto it = loadedTextures.begin(); it != loadedTextures.end(); ++it) { const TextureData *data = it->second; bool xmlUpdated = false; bool modelUpdated = false; // Get Current TimeStamps { struct stat textureAttr; stat(data->textureFilename.c_str(), &textureAttr); time_t modelLastUpdated = textureAttr.st_mtime; if(modelLastUpdated != data->textureTimeStamp) { modelUpdated = true; } struct stat xmlAttr; stat(data->xmlFileName.c_str(), &xmlAttr); time_t xmlLastUpdated = xmlAttr.st_mtime; if(xmlLastUpdated != data->xmlTimeStamp) { xmlUpdated = true; } } // Update data if(modelUpdated || xmlUpdated) { CaffApp::TextureLoaderXMLFile updateTextureSettings(data->xmlFileName); addTexture(updateTextureSettings); } } } // updateTextures
AnimatedTexture::AnimatedTexture(const char * textureName) { addTexture(textureName); currentIndex = 0; lastTime = glfwGetTime(); changeDelay.push_back(1.0); }
PingPongFbo::PingPongFbo( const std::vector<ci::Surface32f>& surfaces ) : mCurrentFbo(0) { if( surfaces.empty() ) return; int i = 0; mTextureSize = surfaces[0].getSize(); for( const ci::Surface32f& s : surfaces) { mAttachments.push_back(GL_COLOR_ATTACHMENT0_EXT + i); addTexture(s); i++; } int max =ci::gl::Fbo::getMaxAttachments(); std::cout << "Maximum supported number of texture attachments: " << max << std::endl; assert(surfaces.size() < max); ci::gl::Fbo::Format format; format.enableDepthBuffer(false); format.enableColorBuffer(true, mAttachments.size()); format.setMinFilter( GL_NEAREST ); format.setMagFilter( GL_NEAREST ); format.setColorInternalFormat( GL_RGBA32F_ARB ); mFbos[0] = ci::gl::Fbo( mTextureSize.x, mTextureSize.y, format ); mFbos[1] = ci::gl::Fbo( mTextureSize.x, mTextureSize.y, format ); reset(); }
PathTexture* PathCache::getArc(float width, float height, float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) { PathDescription entry(kShapeArc, paint); entry.shape.arc.mWidth = width; entry.shape.arc.mHeight = height; entry.shape.arc.mStartAngle = startAngle; entry.shape.arc.mSweepAngle = sweepAngle; entry.shape.arc.mUseCenter = useCenter; PathTexture* texture = get(entry); if (!texture) { SkPath path; SkRect r; r.set(0.0f, 0.0f, width, height); if (useCenter) { path.moveTo(r.centerX(), r.centerY()); } path.arcTo(r, startAngle, sweepAngle, !useCenter); if (useCenter) { path.close(); } texture = addTexture(entry, &path, paint); } return texture; }
/** Add the texture and use it for a single non-animated sprite. */ s32 STKModifiedSpriteBank::addTextureAsSprite(video::ITexture* texture) { assert( m_magic_number == 0xCAFEC001 ); if ( !texture ) return -1; addTexture(texture); u32 textureIndex = getTextureCount() - 1; u32 rectangleIndex = Rectangles.size(); Rectangles.push_back( core::rect<s32>(0,0, texture->getOriginalSize().Width, texture->getOriginalSize().Height) ); SGUISprite sprite; sprite.frameTime = 0; SGUISpriteFrame frame; frame.textureNumber = textureIndex; frame.rectNumber = rectangleIndex; sprite.Frames.push_back( frame ); Sprites.push_back( sprite ); return Sprites.size() - 1; } // addTextureAsSprite
bool TextureAtlas::load(const glm::uvec2& atlasSize) { destroy(); // Check if size is ok and load texture if (16 <= atlasSize.x && 16 <= atlasSize.y && m_texture.load(atlasSize, Texture::Format::RGBA_UB_8, Texture::Flag::DisallowMipmapGeneration)) { // Initialize packer m_packer->nodes.resize(atlasSize.x); m_packer->origin = glm::uvec2(0); // Initialize target - NOTE: num_nodes >= width stbrp_init_target(&m_packer->context, atlasSize.x, atlasSize.y, m_packer->nodes.data(), m_packer->nodes.size()); Image defaultImg; // Create default glyph (2x2 white square in the corner) std::array<unsigned char, 16> data; data.fill(255); defaultImg.load(glm::uvec2(2), 4, data.data()); return addTexture(defaultImg) == 0; } return false; }
void ResourceManager::addTextureMaterialSprite( const std::string& id, resource_group::ResourceGroup resourceGroup, const std::string& shader, const glm::vec4& colour, const std::string& texturePath, unsigned frameRate, bool repeat, unsigned begin, unsigned end, int layer, const glm::vec2& size, const glm::vec2& texSize, const glm::vec2& texOffset, unsigned textureFlags, unsigned materialFlags ) { // texture addTexture( id, resourceGroup, texturePath, frameRate, repeat, begin, end, textureFlags ); // material addMaterial( id, resourceGroup, shader, colour, id, materialFlags ); // sprite addSprite( id, resourceGroup, layer, id, size, texSize, texOffset ); }
Astro::Astro(std::string nombre, float radio, float posX, float posY, float posZ, float vRotEje, float vTras){ this->radio= radio; esfera= new Esfera(0.0f, 0.0f, 0.0f, radio, nombre); addRama(posX, posY, posZ, vTras, vRotEje); addTexture(nombre); }
void ResourceManager::addTextureMaterialGeometryMesh( const std::string& id, resource_group::ResourceGroup resourceGroup, const std::string& shader, const glm::vec4& colour, const std::string& texturePath, unsigned frameRate, bool repeat, unsigned begin, unsigned end, const std::string& geometryPath, int layer, unsigned textureFlags, unsigned materialFlags ) { // texture addTexture( id, resourceGroup, texturePath, frameRate, repeat, begin, end, textureFlags ); // material addMaterial( id, resourceGroup, shader, colour, id, materialFlags ); // geometry addGeometry( id, resourceGroup, geometryPath ); // mesh addMesh( id, resourceGroup, layer, id, id ); }
unsigned TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format, bool* newTexture) { if (size.width() > m_maxTextureSize || size.height() > m_maxTextureSize) return 0; TextureMap::iterator it = m_textures.find(token); if (it != m_textures.end()) { ASSERT(it->second.size != size || it->second.format != format); removeTexture(token, it->second); } size_t memoryRequiredBytes = memoryUseBytes(size, format); if (memoryRequiredBytes > m_memoryLimitBytes || !reduceMemoryToLimit(m_memoryLimitBytes - memoryRequiredBytes)) return 0; unsigned textureId = m_context->createTexture(); GLC(m_context.get(), textureId = m_context->createTexture()); GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId)); // Do basic linear filtering on resize. GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE. GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); GLC(m_context.get(), m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE)); TextureInfo info; info.size = size; info.format = format; info.textureId = textureId; info.isProtected = true; addTexture(token, info); return textureId; }
void QtSE::projectTreeContextMenu( QPoint point ) { CProjectTreeItem *item = (CProjectTreeItem*)projectTree->itemAt( point ); if( item ) { QMenu *menu = new QMenu(); menu->setAttribute( Qt::WA_DeleteOnClose , true ); switch( item->getPartType() ) { case CProjectTreeItem::stage: menu->addAction( "Add Stage" , this , SLOT(addStage()) ); break; case CProjectTreeItem::framebuffer: menu->addAction( "Add Framebuffer" , this , SLOT(addFramebuffer()) ); break; case CProjectTreeItem::shader: menu->addAction( "Add Shader" , this , SLOT(addShader()) ); break; case CProjectTreeItem::texture: menu->addAction( "Add Texture" , this , SLOT(addTexture()) ); break; case CProjectTreeItem::model: menu->addAction( "Add Model" , this , SLOT(addModel()) ); break; default: delete menu; return; } menu->popup( QCursor::pos() , NULL ); } }
Material::Material(float specular_intensity, float specular_exponent, const std::string& diffuse_texture, const std::string& normal_texture, const std::string& disp_texture, float disp_scale, float disp_offset) { _materials.push_back(this); addFloat(MATERIAL_SPECULAR_INTENSITY, specular_intensity); addFloat(MATERIAL_SPECULAR_EXPONENT, specular_exponent); addFloat(MATERIAL_DISP_SCALE, disp_scale); addFloat(MATERIAL_DISP_BIAS, disp_scale / 2.0f * (disp_offset - 1.0f)); addTexture(MATERIAL_DIFFUSE_TEXTURE, Texture(diffuse_texture)); addTexture(MATERIAL_NORMAL_TEXTURE, Texture(normal_texture)); addTexture(MATERIAL_DISP_TEXTURE, Texture(disp_texture)); }
int BitmapHandler::getTextureURL(const std::string &name) { int width, height; int tex = _findTexture(name, width, height); if(tex == 0 ) { tex = loadTextureURL( (char*)name.c_str(), width, height ); addTexture(name, tex, width, height); } return tex; }
std::shared_ptr<Model> Model::createTerrain(std::shared_ptr<ShaderProgram> prog) { auto m = Model::fromMeshes(Mesh::createTerrain(), prog); m->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); auto rotated = glm::rotate(m->model_matrix, glm::radians(90.f), glm::vec3(-1.f, 0.f, 0.f)); auto scaled = glm::scale(rotated, glm::vec3(Settings::TerrainScaleFactor)); m->setMatrix(scaled); auto texture = Texture::fromFile(Settings::BaseGrassTexture, prog); m->addTexture(texture); auto leave = Texture::fromFile(Settings::LeavesTexture, prog, true); m->addTexture(leave); auto extra_texture = Texture::fromFile(Settings::ExtraGrassTexture, prog); m->setSwapTexture(extra_texture); return m; }
FontAtlas::FontAtlas(Font &theFont) : _font(&theFont) , _fontFreeType(nullptr) , _iconv(nullptr) , _currentPageData(nullptr) , _fontAscender(0) //, _rendererRecreatedListener(nullptr) , _antialiasEnabled(true) , _currLineHeight(0) { _font->retain(); _fontFreeType = dynamic_cast<FontFreeType*>(_font); if (_fontFreeType) { _lineHeight = _font->getFontMaxHeight(); _fontAscender = _fontFreeType->getFontAscender(); auto texture = new (std::nothrow) Texture2D; _currentPage = 0; _currentPageOrigX = 0; _currentPageOrigY = 0; _letterEdgeExtend = 2; _letterPadding = 0; if (_fontFreeType->isDistanceFieldEnabled()) { _letterPadding += 2 * FontFreeType::DistanceMapSpread; } _currentPageDataSize = CacheTextureWidth * CacheTextureHeight; auto outlineSize = _fontFreeType->getOutlineSize(); if(outlineSize > 0) { _lineHeight += 2 * outlineSize; _currentPageDataSize *= 2; } _currentPageData = new unsigned char[_currentPageDataSize]; memset(_currentPageData, 0, _currentPageDataSize); auto pixelFormat = outlineSize > 0 ? CCTexture2DPixelFormat::kCCTexture2DPixelFormat_AI88 : CCTexture2DPixelFormat::kCCTexture2DPixelFormat_A8; texture->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) ); addTexture(texture,0); texture->release(); #if CC_ENABLE_CACHE_TEXTURE_DATA auto eventDispatcher = Director::getInstance()->getEventDispatcher(); _rendererRecreatedListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(FontAtlas::listenRendererRecreated, this)); eventDispatcher->addEventListenerWithFixedPriority(_rendererRecreatedListener, 1); #endif } }
TextureID Renderer::addTexture(const char *fileName, unsigned int flags){ Image *img = new Image(); if (img->loadImage(fileName, byteOrderRGBA, (flags & TEX_NOMIPMAPPING)? MIPMAP_NONE : (flags & TEX_NORMALMAP)? MIPMAP_ALLOCATE : MIPMAP_CREATE)){ return addTexture(img, flags); } else { addToLog(String("Couldn't load \"") + fileName + "\""); delete img; return TEXTURE_NONE; } }
int BitmapHandler::getTextureFile(const std::string &name, bool useCache) { int width, height; int tex = _findTexture(name, width, height); if(tex == 0 ) { int width, height; tex = loadTextureFile((char *) name.c_str(), width, height, TEX_MODE_DEFAULT, useCache); addTexture(name, tex, width, height); } return tex; }
PathTexture* PathCache::get(SkPath* path, SkPaint* paint) { const SkPath* sourcePath = path->getSourcePath(); if (sourcePath && sourcePath->getGenerationID() == path->getGenerationID()) { path = const_cast<SkPath*>(sourcePath); } PathCacheEntry entry(path, paint); PathTexture* texture = mCache.get(entry); float left, top, offset; uint32_t width, height; if (!texture) { texture = addTexture(entry, path, paint); } else if (path->getGenerationID() != texture->generation) { mCache.remove(entry); texture = addTexture(entry, path, paint); } return texture; }
//! Creates a texture from a loaded IImage. ITexture* CNullDriver::addTexture(const path& name, IImage* image, void* mipmapData) { if ( 0 == name.size() || !image) return 0; ITexture* t = createDeviceDependentTexture(image, name, mipmapData); if (t) { addTexture(t); t->releaseRef(); } return t; }