int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(600, 600); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); loadTextureFromFile(filename1, 1); loadTextureFromFile(filename2, 2); loadTextureFromFile(filename3, 3); loadTextureFromFile(filename4, 4); loadTextureFromFile(filename5, 5); loadTextureFromFile(filename6, 6); loadTextureFromFile(filename7, 7); loadTextureFromFile(filename8, 8); loadTextureFromFile(filename9, 9); loadTextureFromFile(filename10, 10); glutDisplayFunc(drawScene); glutMouseFunc(mouse); glutSpecialFunc(SpecialFunc); glutReshapeFunc(resizeWindow); glutKeyboardFunc(keyboard); glutIdleFunc(idleFunc); glutMainLoop(); return 0; }
static HRESULT CreateShaders(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dContext) { HRESULT hr; CHAR path[MAX_PATH] = "Data/Shaders/TerrainTessellation/TerrainTessellation.fx"; ID3DXBuffer* pShader = NULL; const DWORD flags = 0; ID3DXBuffer* pErrors = NULL; /*if (D3DXCompileShaderFromFile(path, NULL, NULL, NULL, "fx_5_0", flags, &pShader, &pErrors, NULL) != S_OK) { const char* pTxt = (char *)pErrors->GetBufferPointer(); MessageBoxA(NULL, pTxt, "Compilation errors", MB_OK); return hr; } if (D3DX11CreateEffectFromMemory(pShader->GetBufferPointer(), pShader->GetBufferSize(), 0, pd3dDevice, &g_pTerrainEffect) != S_OK) { MessageBoxA(NULL, "Failed to create terrain effect", "Effect load error", MB_OK); return hr; }*/ if (FAILED(LoadEffectFromFile(pd3dDevice, path, &g_pTerrainEffect))) { MessageBoxA(NULL, "Failed to create terrain effect", "Effect load error", MB_OK); return hr; } // Obtain techniques g_pTesselationTechnique = g_pTerrainEffect->GetTechniqueByName("TesselationTechnique"); // Obtain miscellaneous variables g_HeightMapVar = g_pTerrainEffect->GetVariableByName("g_CoarseHeightMap")->AsShaderResource(); g_GradientMapVar = g_pTerrainEffect->GetVariableByName("g_CoarseGradientMap")->AsShaderResource(); g_pEyePosVar = g_pTerrainEffect->GetVariableByName("g_EyePos")->AsVector(); g_pViewDirVar = g_pTerrainEffect->GetVariableByName("g_ViewDir")->AsVector(); g_pFractalOctavesTVar = g_pTerrainEffect->GetVariableByName("g_FractalOctaves")->AsVector(); g_pUVOffsetTVar = g_pTerrainEffect->GetVariableByName("g_TextureWorldOffset")->AsVector(); g_pViewportVar = g_pTerrainEffect->GetVariableByName( "Viewport" )->AsVector(); g_pTriSizeVar = g_pTerrainEffect->GetVariableByName("g_tessellatedTriWidth")->AsScalar(); g_pTileSizeVar = g_pTerrainEffect->GetVariableByName("g_tileSize")->AsScalar(); g_DebugShowPatchesVar = g_pTerrainEffect->GetVariableByName("g_DebugShowPatches")->AsScalar(); g_DebugShowTilesVar = g_pTerrainEffect->GetVariableByName("g_DebugShowTiles")->AsScalar(); g_WireAlphaVar = g_pTerrainEffect->GetVariableByName("g_WireAlpha")->AsScalar(); g_WireWidthVar = g_pTerrainEffect->GetVariableByName("g_WireWidth")->AsScalar(); g_DetailNoiseVar = g_pTerrainEffect->GetVariableByName("g_DetailNoiseScale")->AsScalar(); g_DetailUVVar = g_pTerrainEffect->GetVariableByName("g_DetailUVScale")->AsVector(); g_SampleSpacingVar = g_pTerrainEffect->GetVariableByName("g_CoarseSampleSpacing")->AsScalar(); loadTextureFromFile("Data/TerrainTessellation/LunarSurface1.dds", "g_TerrainColourTexture1", pd3dDevice, g_pTerrainEffect); loadTextureFromFile("Data/TerrainTessellation/LunarMicroDetail1.dds", "g_TerrainColourTexture2", pd3dDevice, g_pTerrainEffect); loadTextureFromFile("Data/TerrainTessellation/GaussianNoise256.jpg", "g_NoiseTexture", pd3dDevice, g_pTerrainEffect); loadTextureFromFile("Data/TerrainTessellation/fBm5Octaves.dds", "g_DetailNoiseTexture", pd3dDevice, g_pTerrainEffect); loadTextureFromFile("Data/TerrainTessellation/fBm5OctavesGrad.dds", "g_DetailNoiseGradTexture", pd3dDevice, g_pTerrainEffect); return S_OK; }
static void loadShelterGraphics(GraphicsData *graphicsData){ graphicsData->shelter.graphic[SUMMER_INDEX] =loadTextureFromFile("images/tree1.bmp",graphicsData,1); graphicsData->shelter.graphic[AUTUMN_INDEX] = loadTextureFromFile("images/treeAutumn1.bmp",graphicsData, 1); graphicsData->shelter.graphic[WINTER_INDEX] = loadTextureFromFile("images/treeWinter.bmp",graphicsData, 1); graphicsData->treeStumpTexture = loadTextureFromFile("images/stump.bmp",graphicsData, 1); }
void init_textures(){ loadTextureFromFile("wall2.jpg", 0); loadTextureFromFile("piso2.jpg", 1); loadTextureFromFile("ar_condicionado.jpg", 2); loadTextureFromFile("tecido_cadeira.jgp", 3); loadTextureFromFile("teclado_hp.jpg", 4); loadTextureFromFile("tela.png", 5); loadTextureFromFile("cpu.png", 6); loadTextureFromFile("mouse.png", 7); loadTextureFromFile("porta-lisa.jpg", 8); }
GraphicsData createGraphicsData(void){ GraphicsData graphicsData; graphicsData.window = SDL_CreateWindow(PROGRAM_NAME,25,25, X_SIZE_OF_SCREEN, Y_SIZE_OF_SCREEN, SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE); graphicsData.renderer = SDL_CreateRenderer(graphicsData.window,-1, SDL_RENDERER_TARGETTEXTURE|SDL_RENDERER_PRESENTVSYNC); graphicsData.mainMenuImage = loadTextureFromFile("images/mainMenuImage.bmp", &graphicsData, 0); /* initialise navigationOffset values */ graphicsData.navigationOffset.x = X_INITIAL_SCREEN_OFFSET; /*setting initial x offset to center of world*/ graphicsData.navigationOffset.y = Y_INITIAL_SCREEN_OFFSET; /*setting initial y offset ot center of world*/ graphicsData.fonts[0] = TTF_OpenFont("font/Oxygen-Regular.ttf",16); graphicsData.fonts[1] = TTF_OpenFont("font/Oxygen-Regular.ttf",12); graphicsData.trackingMode = 0; loadBeeGraphics(&graphicsData); loadUIGraphics(&graphicsData); loadWeatherGraphics(&graphicsData); loadHiveGraphics(&graphicsData); loadSpiderGraphics(&graphicsData); loadIceCreamGraphics(&graphicsData); loadShelterGraphics(&graphicsData); loadNodeGraphics(&graphicsData); loadGrass(&graphicsData); return graphicsData; }
//adds texture to texture manager - IS GLuint TextureManager::getTexture(const std::string &name) { GLuint textureID = 0; //get the name, strip out path and extension, leave only have name of texture long lastSlashPos = name.find_last_of('/'); long dotPos = name.find_last_of('.'); std::string nameID = name.substr(lastSlashPos + 1, dotPos - 1); auto iter = m_LoadedTexturesMap.find(nameID); if (iter != m_LoadedTexturesMap.end()) { textureID = iter->second; } else { //load texture textureID = loadTextureFromFile(name); m_LoadedTexturesVector.push_back(textureID); m_LoadedTexturesMap[nameID] = textureID; } return textureID; }
//! 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 Material::loadDiffuseMap(const string& filename) { m_DiffuseMap = loadTextureFromFile(filename); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenerateMipmap(GL_TEXTURE_2D); }
void Material::loadSpecularTexture(const string &filename) { m_SpecularTexture = loadTextureFromFile(filename); glBindTexture(GL_TEXTURE_2D, m_SpecularTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glGenerateMipmap(GL_TEXTURE_2D); }
DxTexture* TextureCache::loadTextureFromFile(const std::string& filename, const Color4B& colorKey) { auto ite = m_pTextureArray->find(filename); if (ite != m_pTextureArray->end()) { DxTexture* temp = ite->second; DxTexture* texture = new DxTexture(); texture->m_contentSize = texture->m_textureSize = temp->m_textureSize; texture->m_pTexture = temp->m_pTexture; return texture; } LPDIRECT3DDEVICE9 pDevice = Director::getInstance()->getDxDevice()->getIDirect3DDevice9(); LPDIRECT3DTEXTURE9 pTexture(nullptr); D3DXIMAGE_INFO info; if (S_OK != D3DXCreateTextureFromFileEx( pDevice, filename.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, D3DPOOL_DEFAULT, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_RGBA( colorKey.r, colorKey.g, colorKey.b, colorKey.a), &info, NULL, &pTexture)) { return nullptr; } if (!pTexture) { return nullptr; } int width = info.Width; int height = info.Height; if (width <= 0 || height <= 0) { return nullptr; } DxTexture* texture = new DxTexture(); texture->m_contentSize = texture->m_textureSize = Size(width, height); texture->m_pTexture = pTexture; m_pTextureArray->insert(std::make_pair(filename, texture)); return loadTextureFromFile(filename, colorKey); }
static void loadUIGraphics(GraphicsData *graphicsData){ graphicsData->uiEle.graphic[SCROLLHANDLE_GRAPHIC] = loadTextureFromFile("images/UI/scrollhandle.bmp",graphicsData, 1); graphicsData->uiEle.graphic[CROSSBOX_GRAPHIC] = loadTextureFromFile("images/UI/crossbox.bmp",graphicsData, 1); graphicsData->uiEle.graphic[COMPILEBOX_GRAPHIC] = loadTextureFromFile("images/UI/compilebox.bmp",graphicsData, 1); graphicsData->uiEle.graphic[STOP_GRAPHIC] = loadTextureFromFile("images/UI/stop.bmp",graphicsData, 1); graphicsData->uiEle.graphic[BLOCK_GRAPHIC] = loadTextureFromFile("images/UI/block.bmp",graphicsData, 1); graphicsData->uiEle.graphic[HIVECELL_GRAPHIC] = loadTextureFromFile("images/UI/hivecell.bmp",graphicsData, 1); graphicsData->uiEle.graphic[HIVECELLMASK_GRAPHIC] = loadTextureFromFile("images/UI/hivecellmask.bmp",graphicsData, 1); }
//! loads a Texture ITexture* CNullDriver::getTexture(const path& filename) { // Identify textures by their absolute filenames if possible. const path absolutePath = FileSystem->getAbsolutePath(filename); ITexture* texture = findTexture(absolutePath); if (texture) return texture; // Then try the raw filename, which might be in an Archive texture = findTexture(filename); if (texture) return texture; // Now try to open the file using the complete path. IReadFile* file = FileSystem->createAndOpenFile(absolutePath); if (!file) { // Try to open it using the raw filename. file = FileSystem->createAndOpenFile(filename); } if (file) { // Re-check name for actual archive names texture = findTexture(file->getFileName()); if (texture) { file->releaseRef(); return texture; } texture = loadTextureFromFile(file); file->releaseRef(); if (texture) { addTexture(texture); texture->releaseRef(); // drop it because we created it, one grab too much } else Printer::log("Could not load texture", filename, ELL_ERROR); return texture; } else { Printer::log("Could not open file of texture", filename, ELL_WARNING); return 0; } }
void ProcTexTerrainRender::CreateShaders() { LoadEffectFromFile(D3D11Dev(), "data/shaders/terrascape.fx", &TerrainEffect); loadTextureFromFile("data/ambient.jpg", "occlusionTexture", D3D11Dev(), TerrainEffect); loadTextureFromFile("data/shadow.jpg", "shadowTexture", D3D11Dev(), TerrainEffect); loadTextureFromFile("data/noise16.png", "texNoiseMap0", D3D11Dev(), TerrainEffect); loadTextureFromFile("data/displace16.png", "texNoiseMap0", D3D11Dev(), TerrainEffect); HeightMapTex16 = new D3D11Texture2D; HeightMapTex16->Initialize(D3D11Dev(), heightMapXFull-1, heightMapXFull-1, DXGI_FORMAT_R16G16_UNORM); WORD *heightMapDouble = new WORD[ (heightMapXFull-1)*(heightMapXFull-1)*2 ]; int i,j; for ( j = 0; j < (heightMapXFull-1); j++ ) for ( i = 0; i < (heightMapXFull-1); i++ ) { WORD h = HeightMap16Full[ i + (heightMapXFull-2-j) * heightMapXFull ]; WORD h2 = HeightMap16Full[ i + 1 + (heightMapXFull-2-j) * heightMapXFull ]; heightMapDouble[ (i + j * (heightMapXFull-1)) * 2 + 0 ] = h; heightMapDouble[ (i + j * (heightMapXFull-1)) * 2 + 1 ] = h2; } uint32 pitch; WORD*data = (WORD*)HeightMapTex16->Map(D3D11Context(), 0, pitch); memcpy(data, heightMapDouble, (heightMapXFull-1)*(heightMapXFull-1)*2 * sizeof(WORD)); HeightMapTex16->Unmap(D3D11Context(), 0); delete heightMapDouble; // interpolation look-up textures if ( generateBiCubicWeights( D3D11Dev() ) ) return; // create chunk lod quadtree createQLOD( D3D11Dev(), heightMapX, HeightMap16, HeightMapTex16 ); }
static void loadWeatherGraphics(GraphicsData *graphicsData){ graphicsData->rainy.graphic[0] = loadTextureFromFile("images/rain/rain1.bmp", graphicsData, 1); graphicsData->rainy.graphic[1] = loadTextureFromFile("images/rain/rain2.bmp", graphicsData, 1); graphicsData->rainy.graphic[2] = loadTextureFromFile("images/rain/rain3.bmp", graphicsData, 1); graphicsData->rainy.graphic[3] = loadTextureFromFile("images/rain/rain4.bmp", graphicsData, 1); graphicsData->rainy.graphic[4] = loadTextureFromFile("images/rain/rain5.bmp", graphicsData, 1); graphicsData->rainy.graphic[5] = loadTextureFromFile("images/rain/rain6.bmp", graphicsData, 1); }
static void loadBeeGraphics(GraphicsData *graphicsData){ graphicsData->bee.graphic[BEE_FLAP_GRAPHIC_1] = loadTextureFromFile("images/bee.bmp", graphicsData, 1); graphicsData->bee.graphic[BEE_FLAP_GRAPHIC_2] = loadTextureFromFile("images/bee2.bmp",graphicsData, 1); graphicsData->bee.graphic[BEE_FLAP_GRAPHIC_1 + CARRYING_FLOWER_INDEX_OFFSET] = loadTextureFromFile("images/beeWithFlower.bmp", graphicsData, 1); graphicsData->bee.graphic[BEE_FLAP_GRAPHIC_2 + CARRYING_FLOWER_INDEX_OFFSET] = loadTextureFromFile("images/beeWithFlower2.bmp",graphicsData, 1); graphicsData->bee.graphic[BEE_FLAP_GRAPHIC_1 + CARRYING_ICECREAM_INDEX_OFFSET] = loadTextureFromFile("images/beeWithIcecream.bmp", graphicsData, 1); graphicsData->bee.graphic[BEE_FLAP_GRAPHIC_2 + CARRYING_ICECREAM_INDEX_OFFSET] = loadTextureFromFile("images/beeWithIcecream2.bmp",graphicsData, 1); }
static void loadSpiderGraphics(GraphicsData *graphicsData){ /*roamingSpider graphics*/ graphicsData->roamingArachnid.graphic[SPIDER] = loadTextureFromFile("images/spider.bmp", graphicsData, 1); graphicsData->roamingArachnid.graphic[SPIDER2] = loadTextureFromFile("images/spider2.bmp", graphicsData, 1); graphicsData->roamingArachnid.graphic[SPIDER15] = loadTextureFromFile("images/spider15.bmp", graphicsData, 1); graphicsData->roamingArachnid.graphic[SPIDER15b] = loadTextureFromFile("images/spider15.bmp", graphicsData, 1); graphicsData->roamingArachnid.graphic[SPIDER_DEAD] = loadTextureFromFile("images/spider_dead2.bmp", graphicsData, 1); graphicsData->roamingArachnid.graphic[SPIDER_FIGHTING] = loadTextureFromFile("images/spiderFighting.bmp", graphicsData, 1); }
static void loadIceCreamGraphics(GraphicsData *graphicsData){ graphicsData->person.graphic[WITH_ICE_CREAM_STRIDE1] = loadTextureFromFile("images/person/withIceCream1.bmp", graphicsData, 1); graphicsData->person.graphic[WITH_ICE_CREAM_STRIDE2] = loadTextureFromFile("images/person/withIceCream2.bmp", graphicsData, 1); graphicsData->person.graphic[WITH_ICE_CREAM_STRIDE1 + NO_ICECREAM_INDEX_OFFSET] = loadTextureFromFile("images/person/withoutIceCream1.bmp", graphicsData, 1); graphicsData->person.graphic[WITH_ICE_CREAM_STRIDE2 + NO_ICECREAM_INDEX_OFFSET] = loadTextureFromFile("images/person/withoutIceCream2.bmp", graphicsData, 1); graphicsData->droppedIceCreamTexture = loadTextureFromFile("images/person/droppedIceCream.bmp", graphicsData, 1); graphicsData->meltedIceCreamTexture = loadTextureFromFile("images/person/meltedIceCream.bmp", graphicsData, 1); }
ResourceManager::ResourceManager() { if(instance){ qDebug() << "Only one instance of TextureManager allowed"; return; } //load the textures textures = new std::vector<GLuint>; textures->push_back(loadTextureFromFile(":/Images/font.png")); //init colour array gradientColours = new std::vector<const Util::Color*>; float per; for (int i = 0 ; i < NUM_GRADIENT_COLOURS ; i++){ //(gradiant from blue -> green -> red, like UI mockup) per = i/(float)NUM_GRADIENT_COLOURS; //hard one-liner is hard //still a little buggy gradientColours->push_back(new Util::Color( (per <= .1) ? ((255/2.0)-(per/.1)*(255/2.0)) : ((per < .5) ? (0) : ((per <= .7) ? (((per-.5)/.2)*255) : (255))), (per <= .1) ? (0) : ((per <= .3) ? (((per-.1)/(.2))*255) : ((per <= .7) ? (255) : (per <=.9) ? (255-((per-.7)/(.2))*255) : (0))), (per <= .3) ? (255) : (per <= .5) ? (255-((per-.3)/(.2))*255) : (0) )); } //init static colours basicColours = new std::vector<const Util::Color*>(); basicColours->push_back(new Util::Color (255, 255, 255)); basicColours->push_back(new Util::Color(255, 255, 0)); basicColours->push_back(new Util::Color(255, 0, 0)); basicColours->push_back(new Util::Color(0, 255, 0)); basicColours->push_back(new Util::Color(0, 0, 255)); basicColours->push_back(new Util::Color (255, 132, 0)); basicColours->push_back(new Util::Color(0, 190, 255)); basicColours->push_back(new Util::Color (255, 0, 150)); basicColours->push_back(new Util::Color(160, 0, 200)); basicColours->push_back(new Util::Color(0, 0, 0)); //set up self reference instance = this; }
static HRESULT CreateDeformEffect(ID3D11Device* pd3dDevice) { HRESULT hr; CHAR path[MAX_PATH] = "Data/Shaders/TerrainTessellation/Deformation.fx"; ID3DXBuffer* pShader = NULL; //if (FAILED (hr = DXUTFindDXSDKMediaFileCch(path, MAX_PATH, L"Deformation.fx"))) { // MessageBox (NULL, L"Deformation.fx cannot be found.", L"Error", MB_OK); // return hr; //} ID3DXBuffer* pErrors = NULL; ////if (D3DXCompileShaderFromFile(path, NULL, NULL, NULL, "fx_5_0", 0, &pShader, &pErrors, NULL) != S_OK) //{ // MessageBoxA(NULL, (char *)pErrors->GetBufferPointer(), "Compilation errors", MB_OK); // return hr; //} //if (D3DX11CreateEffectFromMemory(pShader->GetBufferPointer(), pShader->GetBufferSize(), 0, pd3dDevice, &g_pDeformEffect) != S_OK) //{ // MessageBoxA(NULL, "Failed to create deformation effect", "Effect load error", MB_OK); // return hr; //} LoadEffectFromFile(pd3dDevice, path, &g_pDeformEffect); // Obtain techniques g_pInitializationTechnique = g_pDeformEffect->GetTechniqueByName("InitializationTechnique"); g_pGradientTechnique = g_pDeformEffect->GetTechniqueByName("GradientTechnique"); // Obtain miscellaneous variables g_pFractalOctavesDVar = g_pDeformEffect->GetVariableByName("g_FractalOctaves")->AsVector(); g_pUVOffsetDVar = g_pDeformEffect->GetVariableByName("g_TextureWorldOffset")->AsVector(); g_InputTexVar = g_pDeformEffect->GetVariableByName("g_InputTexture")->AsShaderResource(); loadTextureFromFile("Data/TerrainTessellation/GaussianNoise256.jpg", "g_NoiseTexture", pd3dDevice, g_pDeformEffect); return S_OK; }
Texture::Texture(string filepath) { loadTextureFromFile(filepath, GL_LINEAR, true); }
static void loadGrass(GraphicsData *graphicsData){ graphicsData->grass.graphic[SUMMER_INDEX] = loadTextureFromFile("images/grass/grass4.bmp",graphicsData, 0); graphicsData->grass.graphic[AUTUMN_INDEX] = loadTextureFromFile("images/grass/autumnGrass4.bmp", graphicsData, 0); }
// Imports the textures for the icons void Disc::prepare_graphics(void){ if (!texture_loaded_){ tex_[0] = loadTextureFromFile( "graphics/input.bmp" ); tex_[1] = loadTextureFromFile( "graphics/sine.bmp" ); tex_[2] = loadTextureFromFile( "graphics/square.bmp" ); tex_[3] = loadTextureFromFile( "graphics/triangle.bmp" ); tex_[4] = loadTextureFromFile( "graphics/saw.bmp" ); tex_[5] = loadTextureFromFile( "graphics/bitcrusher.bmp" ); tex_[6] = loadTextureFromFile( "graphics/chorus.bmp" ); tex_[7] = loadTextureFromFile( "graphics/delay.bmp" ); tex_[8] = loadTextureFromFile( "graphics/distortion.bmp" ); tex_[9] = loadTextureFromFile( "graphics/filter.bmp" ); tex_[10] = loadTextureFromFile( "graphics/granular.bmp" ); tex_[11] = loadTextureFromFile( "graphics/looper.bmp" ); tex_[12] = loadTextureFromFile( "graphics/ringmod.bmp" ); tex_[13] = loadTextureFromFile( "graphics/reverb.bmp" ); tex_[14] = loadTextureFromFile( "graphics/tremolo.bmp" ); tex_[15] = loadTextureFromFile( "graphics/looper_rec.bmp" ); tex_[16] = loadTextureFromFile( "graphics/looper_1.bmp" ); tex_[17] = loadTextureFromFile( "graphics/looper_2.bmp" ); tex_[18] = loadTextureFromFile( "graphics/looper_3.bmp" ); tex_[19] = loadTextureFromFile( "graphics/looper_4.bmp" ); tex_[20] = loadTextureFromFile( "graphics/looper_5.bmp" ); tex_[21] = loadTextureFromFile( "graphics/looper_6.bmp" ); tex_[22] = loadTextureFromFile( "graphics/looper_7.bmp" ); texture_loaded_ = true; } }
int geTextureDlg::find_textures(rendererGL10* renderer, const char *dirname, geGUIBase* dlg, std::vector<geGUIBase*>& textureThumbList) { DIR *dir; char buffer[PATH_MAX + 2]; char *p = buffer; const char *src; char *end = &buffer[PATH_MAX]; int ok; /* Copy directory name to buffer */ src = dirname; while (p < end && *src != '\0') { *p++ = *src++; } *p = '\0'; /* Open directory stream */ dir = opendir (dirname); if (dir != NULL) { struct dirent *ent; /* Print all files and directories within the directory */ while ((ent = readdir (dir)) != NULL) { char *q = p; char c; /* Get final character of directory name */ if (buffer < q) { c = q[-1]; } else { c = ':'; } /* Append directory separator if not already there */ if (c != ':' && c != '/' && c != '\\') { *q++ = '/'; } /* Append file name */ src = ent->d_name; while (q < end && *src != '\0') { *q++ = *src++; } *q = '\0'; /* Decide what to do with the directory entry */ switch (ent->d_type) { case DT_REG: { if(util::GE_IS_EXTENSION(buffer, ".png") || util::GE_IS_EXTENSION(buffer, ".PNG") || util::GE_IS_EXTENSION(buffer, ".tga") || util::GE_IS_EXTENSION(buffer, ".TGA") || util::GE_IS_EXTENSION(buffer, ".bmp") || util::GE_IS_EXTENSION(buffer, ".BMP") || util::GE_IS_EXTENSION(buffer, ".ico") || util::GE_IS_EXTENSION(buffer, ".ICO") || util::GE_IS_EXTENSION(buffer, ".jpeg") || util::GE_IS_EXTENSION(buffer, ".JPEG") || util::GE_IS_EXTENSION(buffer, ".pcx") || util::GE_IS_EXTENSION(buffer, ".PCX") || util::GE_IS_EXTENSION(buffer, ".tif") || util::GE_IS_EXTENSION(buffer, ".TIF") || util::GE_IS_EXTENSION(buffer, ".psd") || util::GE_IS_EXTENSION(buffer, ".PSD") || util::GE_IS_EXTENSION(buffer, ".gif") || util::GE_IS_EXTENSION(buffer, ".GIF") || util::GE_IS_EXTENSION(buffer, ".hdr") || util::GE_IS_EXTENSION(buffer, ".HDR") ) { gxTexture* texture= loadTextureFromFile(*monoWrapper::mono_engine_getWorld(0)->getTextureManager(), buffer); geTextureThumbnail* thumbnail = new geTextureThumbnail(m_pFontManager); thumbnail->create(renderer, dlg, texture, 260, 10, 70, 70); m_vTextureThumbs.push_back(thumbnail); } } break; case DT_DIR: // /* Scan sub-directory recursively */ if (strcmp (ent->d_name, ".") != 0 && strcmp (ent->d_name, "..") != 0) { find_textures (renderer, buffer, dlg, textureThumbList); } break; default: /* Do not device entries */ /*NOP*/; } } closedir (dir); ok = 1; } else { /* Could not open directory */ printf ("Cannot open directory %s\n", dirname); ok = 0; } return ok; }
static void loadHiveGraphics(GraphicsData *graphicsData){ graphicsData->hiveTexture = loadTextureFromFile("images/beehive.bmp", graphicsData, 1); }
textureClass resourceManagerClass::LoadTexture(const GLchar *file, GLboolean alpha, std::string name) { Textures[name] = loadTextureFromFile(file, alpha); return Textures[name]; }
static void loadNodeGraphics(GraphicsData *graphicsData){ graphicsData->nodeTexture[0] = loadTextureFromFile("images/blueFlower.bmp",graphicsData, 1); graphicsData->nodeTexture[1] = loadTextureFromFile("images/redFlower.bmp",graphicsData, 1); graphicsData->nodeTexture[2] = loadTextureFromFile("images/yellowFlower.bmp",graphicsData, 1); }
Texture ResourceManager::loadTexture(const GLchar* file, GLboolean alpha, std::string name) { if (textures.count(name) == 0) { textures[name] = loadTextureFromFile(file, alpha); } return textures[name]; }
Texture2D ResourceManager::LoadTexture(const GLchar *file, GLboolean alpha, GLboolean repeat, std::string name) { Textures[name] = loadTextureFromFile(file, alpha, repeat); return Textures[name]; }
GAE_BOOL GAE_Texture_load(GAE_Texture_t* texture, const GAE_BOOL retainData) { GAE_GL_Texture_t* platform = (GAE_GL_Texture_t*)texture->platform; GAE_File_t* file = texture->file; GAE_FILE_STATUS openStatus; GAE_FILE_READ_STATUS readStatus; if (GL_INVALID_VALUE != platform->id) { /*Application::getInstance()->getLogger()->log("Texture already loaded: " + mFile->getFilePath() + "\n", Logger::LOG_TYPE_ERROR);*/ return GAE_FALSE; } switch (texture->type) { case GAE_TEXTURE_TYPE_FILE: { if (0 == file->buffer) { GAE_File_open(texture->file, GAE_FILE_OPEN_READ, GAE_FILE_BINARY, &openStatus); if (GAE_FILE_ERROR == openStatus) { GAE_File_close(texture->file, GAE_FILE_CLOSE_DELETE_DATA, NULL); /*Application::getInstance()->getLogger()->log("Failed to open Texture: " + mFile->getFilePath() + "\n", Logger::LOG_TYPE_ERROR);*/ return GAE_FALSE; } GAE_File_read(texture->file, GAE_FILE_READ_ALL, &readStatus); if (GAE_FILE_READ_ERROR == readStatus) { GAE_File_close(texture->file, GAE_FILE_CLOSE_DELETE_DATA, NULL); /*Application::getInstance()->getLogger()->log("Failed to read Texture: " + mFile->getFilePath() + "\n", Logger::LOG_TYPE_ERROR);*/ return GAE_FALSE; } } platform->id = loadTextureFromFile(texture); if (GL_INVALID_VALUE == platform->id) { /*Application::getInstance()->getLogger()->log("Texture loading error: '" + mFile->getFilePath() + "' " + toString(mWidth) + ", " + toString(mHeight) + " : " + toString(channels) + " - " + std::string(SOIL_last_result()) + "\n", Logger::LOG_TYPE_ERROR);*/ GAE_File_close(texture->file, GAE_FILE_CLOSE_DELETE_DATA, NULL); return GAE_FALSE; } retainData ? GAE_File_close(texture->file, GAE_FILE_CLOSE_RETAIN_DATA, &openStatus) : GAE_File_close(texture->file, GAE_FILE_CLOSE_DELETE_DATA, &openStatus); if (GAE_FILE_ERROR == openStatus) { /*Application::getInstance()->getLogger()->log("Failed to close Texture: " + mFile->getFilePath() + "\n", Logger::LOG_TYPE_ERROR);*/ return GAE_FALSE; } break; } case GAE_TEXTURE_TYPE_BUFFER: { platform->id = loadTextureFromBuffer(texture); if (GAE_FALSE == retainData) GAE_File_delete(texture->file); if (GL_INVALID_VALUE == platform->id) { /*Application::getInstance()->getLogger()->log("Texture creation error: " + std::string(SOIL_last_result()) + "\n", Logger::LOG_TYPE_ERROR);*/ return GAE_FALSE; } break; } } switch (platform->filter) { case GAE_GL_TEXTURE_FILTER_NONE: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); break; case GAE_GL_TEXTURE_FILTER_BILINEAR: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); break; case GAE_GL_TEXTURE_FILTER_TRILINEAR: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); break; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return GAE_TRUE; }
void terrainInit(const char *texture_path) { terrain_current = loadTextureFromFile(texture_path); if(!terrain_current) terrain_current = &terrain; //Use default, included texture else puts("External texture loaded!"); int fields_x = 16; int fields_y = 16; int field_width = terrain_current->width / fields_x; int field_height = terrain_current->height / fields_y; //Give grass and leaves color const RGB green = { 0.5f, 0.8f, 0.3f }; makeColor(green, *terrain_current, 0, 0, field_width, field_height); makeColor(green, *terrain_current, 5 * field_width, 3 * field_height, field_width, field_height); makeColor(green, *terrain_current, 4 * field_width, 3 * field_height, field_width, field_height); //Also redstone drawTexture(*terrain_current, *terrain_current, 4 * field_width, 10 * field_height, field_width, field_height, 4 * field_width, 11 * field_height, field_width, field_height); const RGB red = { 0.9f, 0.1f, 0.1f }; makeColor(red, *terrain_current, 4 * field_width, 11 * field_height, field_width, field_height); //And redstone switches drawTexture(*terrain_current, *terrain_current, 0 * field_width, 6 * field_height, field_width, field_height, 0 * field_width, 7 * field_height, field_width, field_height); const RGB red_tint = { 1.0f, 0.8f, 0.8f }; makeColor(red_tint, *terrain_current, 0 * field_width, 7 * field_height, field_width, field_height); if(terrain_current->width == 256 && terrain_current->height == 256) terrain_resized = terrain_current; else terrain_resized = resizeTexture(*terrain_current, 256, 256); for(int y = 0; y < fields_y; y++) for(int x = 0; x < fields_x; x++) { //+1 and -2 to work around GLFix inaccuracies resulting in rounding errors TerrainAtlasEntry tea = terrain_atlas[x][y] = {textureArea(x * field_width + 1, y * field_height + 1, field_width - 2, field_height - 2), textureArea(x * 16, y * 16, 16, 16) }; BLOCK_TEXTURE bt = texture_atlas[y][x]; if(bt.sides == 0) continue; if(bt.sides & BLOCK_BOTTOM_BIT) block_textures[bt.block][BLOCK_BOTTOM] = tea; if(bt.sides & BLOCK_TOP_BIT) block_textures[bt.block][BLOCK_TOP] = tea; if(bt.sides & BLOCK_LEFT_BIT) block_textures[bt.block][BLOCK_LEFT] = tea; if(bt.sides & BLOCK_RIGHT_BIT) block_textures[bt.block][BLOCK_RIGHT] = tea; if(bt.sides & BLOCK_FRONT_BIT) block_textures[bt.block][BLOCK_FRONT] = tea; if(bt.sides & BLOCK_BACK_BIT) block_textures[bt.block][BLOCK_BACK] = tea; } //Slight hack, you can't assign a texture to multiple blocks block_textures[BLOCK_GRASS][BLOCK_BOTTOM] = block_textures[BLOCK_DIRT][BLOCK_BOTTOM]; //Prerender four times the same texture to speed up drawing, see terrain.h const BLOCK_TEXTURE quad_textures[] = { ALL(BLOCK_DIRT), SID(BLOCK_GRASS), TOP(BLOCK_GRASS), ALL(BLOCK_STONE), ALL(BLOCK_SAND), SID(BLOCK_WOOD), ALL(BLOCK_PLANKS_NORMAL), ALL(BLOCK_LEAVES) }; terrain_quad = newTexture(field_width * 2 * (sizeof(quad_textures)/sizeof(*quad_textures)), field_height * 2); for(BLOCK b = 0; b <= BLOCK_NORMAL_LAST; b++) for(uint8_t s = 0; s <= BLOCK_SIDE_LAST; s++) quad_block_textures[b][s].has_quad = false; unsigned int x = 0; for(BLOCK_TEXTURE bt : quad_textures) { TextureAtlasEntry *tae = nullptr; if(bt.sides & BLOCK_BOTTOM_BIT) tae = &block_textures[bt.block][BLOCK_BOTTOM].current; if(bt.sides & BLOCK_TOP_BIT) tae = &block_textures[bt.block][BLOCK_TOP].current; if(bt.sides & BLOCK_LEFT_BIT) tae = &block_textures[bt.block][BLOCK_LEFT].current; if(bt.sides & BLOCK_RIGHT_BIT) tae = &block_textures[bt.block][BLOCK_RIGHT].current; if(bt.sides & BLOCK_FRONT_BIT) tae = &block_textures[bt.block][BLOCK_FRONT].current; if(bt.sides & BLOCK_BACK_BIT) tae = &block_textures[bt.block][BLOCK_BACK].current; if(!tae) { printf("Block %d has no texture!\n", bt.block); continue; } //- 1 to reverse the workaround above. Yes, I hate myself for this. drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x, 0, field_width, field_height); drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x + field_width, 0, field_width, field_height); drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x+ field_width, field_height, field_width, field_height); drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x, field_height, field_width, field_height); //Get an average color of the block RGB sum; for(unsigned int tex_x = tae->left - 1; tex_x <= tae->right; ++tex_x) for(unsigned int tex_y = tae->top - 1; tex_y <= tae->bottom; ++tex_y) { RGB rgb = rgbColor(terrain_current->bitmap[tex_x + tex_y*terrain_current->width]); sum.r += rgb.r; sum.g += rgb.g; sum.b += rgb.b; } int pixels = field_width * field_height; sum.r /= pixels; sum.g /= pixels; sum.b /= pixels; const COLOR darker = colorRGB(sum.r / GLFix(1.5f), sum.g / GLFix(1.5f), sum.b / GLFix(1.5f)); //And add the workaround here again.. TerrainQuadEntry tqe = { true, textureArea(x + 1, 1, field_width * 2 - 2, field_height * 2 - 2), colorRGB(sum), darker }; if(bt.sides & BLOCK_BOTTOM_BIT) quad_block_textures[bt.block][BLOCK_BOTTOM] = tqe; if(bt.sides & BLOCK_TOP_BIT) quad_block_textures[bt.block][BLOCK_TOP] = tqe; if(bt.sides & BLOCK_LEFT_BIT) quad_block_textures[bt.block][BLOCK_LEFT] = tqe; if(bt.sides & BLOCK_RIGHT_BIT) quad_block_textures[bt.block][BLOCK_RIGHT] = tqe; if(bt.sides & BLOCK_FRONT_BIT) quad_block_textures[bt.block][BLOCK_FRONT] = tqe; if(bt.sides & BLOCK_BACK_BIT) quad_block_textures[bt.block][BLOCK_BACK] = tqe; x += field_width * 2; } //Part 2 of the hack above quad_block_textures[BLOCK_GRASS][BLOCK_BOTTOM] = quad_block_textures[BLOCK_DIRT][BLOCK_BOTTOM]; if(lcd_type() == SCR_320x240_4) { greyscaleTexture(*terrain_current); greyscaleTexture(*terrain_resized); greyscaleTexture(*terrain_quad); } //Resize the glass texture to 32x32 const TextureAtlasEntry &glass_tex = block_textures[BLOCK_GLASS][BLOCK_FRONT].current; glass_big = newTexture(32, 32); drawTexture(*terrain_current, *glass_big, glass_tex.left - 1, glass_tex.top - 1, field_width, field_height, 0, 0, 32, 32); }