int register_graphics::loadTexture(lua_State *L) { texture2D* tex = checkTexture(L, 1); luaL_checkstring(L, 2); const char* path = lua_tostring(L, 2); tex->create(path); return 1; }
int register_graphics::deleteTexture(lua_State *L) { texture2D* f = checkTexture(L, 1); if (f != NULL){ SAFE_DELETE(f); }else{ LOG("can not delete texture because it is null!"); return 0; } return 1; }
void ResourceManualFont::initialise() { if (mVectorPairCodeCoord.empty()) return; std::sort(mVectorPairCodeCoord.begin(), mVectorPairCodeCoord.end()); const IntSize& size = texture_utility::getTextureSize(mSource); float aspect = (float)size.width / (float)size.height; Char code = mVectorPairCodeCoord.front().code; size_t count = mVectorPairCodeCoord.size(); size_t first = 0; for (size_t pos = 1; pos < count; ++pos) { // диапазон оборвался if (code + 1 != mVectorPairCodeCoord[pos].code) { addRange(mVectorPairCodeCoord, first, pos - 1, size.width, size.height, aspect); code = mVectorPairCodeCoord[pos].code; first = pos; } else { code ++; } } addRange(mVectorPairCodeCoord, first, count - 1, size.width, size.height, aspect); // уничтожаем буфер VectorPairCodeCoord tmp; std::swap(tmp, mVectorPairCodeCoord); checkTexture(); }
// =================================================================== uint CTextureCache::loadTexture(const std::string& filename, uint newTextureID){ uint textureID; SDL_Surface* loadedImageTmp = 0; SDL_Surface* loadedImage = 0; //std::cout << "[CTextureManager::loadTexture] RUTA TEXTURA: " << filename << "\n"; uint existingID =checkTexture(filename); if( existingID != (uint)-1) return existingID; loadedImageTmp = IMG_Load(filename.c_str()); if(!loadedImageTmp){ #ifdef _DEBUG cerr<<"Error en la carga de la imagen:"<<filename<<" motivo: "<<SDL_GetError()<<"\n"; #endif return 0; } //std::cout << "[CTextureManager::loadTexture] Leo la imagen\n"; //loadedImage = rotozoomSurfaceXY(loadedImageTmp, 0, 1, -1, 0); loadedImage = loadedImageTmp; /* if(!loadedImage){ #ifdef _DEBUG cerr<<"Error en la carga de la imagen: "<<SDL_GetError() << "\n"; #endif return 0; } */ textureID = getNewTextureID(newTextureID); //std::cout << "[CTextureManager::loadTexture] ID textura: "<<textureID<<"\n"; glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Obtenemos el numero de canales de la surface SDL GLint nOfColors = loadedImage->format->BytesPerPixel; GLenum texture_format; switch(nOfColors){ case 3: // No tiene canal alpha if (loadedImage->format->Rmask == 0x000000ff) texture_format = GL_RGB; else texture_format = GL_BGR; break; case 4: // Tiene canal alpha if (loadedImage->format->Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; break; default: texture_format = GL_RGBA; } gluBuild2DMipmaps( GL_TEXTURE_2D, nOfColors, loadedImage->w, loadedImage->h, texture_format, GL_UNSIGNED_BYTE, loadedImage->pixels ); SDL_FreeSurface(loadedImage); //SDL_FreeSurface(loadedImageTmp); // Si no ha sido posible asignarse una textura, se habra otorgado el ID 0 if(!textureID) return 0; _textureIDs[filename] = textureID; //std::cout << "[CTextureManager::loadTexture] Llego al final\n"; return textureID; }
int register_graphics::unBindTexture(lua_State *L) { texture2D* tex = checkTexture(L, 1); tex->unbind(); return 1; }