本文整理汇总了C++中Texture2D类的典型用法代码示例。如果您正苦于以下问题:C++ Texture2D类的具体用法?C++ Texture2D怎么用?C++ Texture2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Texture2D类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CCASSERT
Texture2D* TextureCache::addImage(Image *image, const std::string &key)
{
CCASSERT(image != nullptr, "TextureCache: image MUST not be nil");
Texture2D * texture = nullptr;
do
{
auto it = _textures.find(key);
if( it != _textures.end() ) {
texture = it->second;
break;
}
// prevents overloading the autorelease pool
texture = new (std::nothrow) Texture2D();
texture->initWithImage(image);
if(texture)
{
_textures.insert( std::make_pair(key, texture) );
texture->retain();
texture->autorelease();
}
else
{
CCLOG("cocos2d: Couldn't add UIImage in TextureCache");
}
} while (0);
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTextureMgr::addImage(texture, image);
#endif
return texture;
}
开发者ID:RyunosukeOno,项目名称:rayjack,代码行数:38,代码来源:CCTextureCache.cpp
示例2: getGifFrameName
// get CCSpriteFrame from cache or create with Bitmap's data
SpriteFrame* CacheGif::getGifSpriteFrame(Bitmap* bm, int index)
{
std::string gifFrameName = getGifFrameName(index);
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(gifFrameName.c_str());
if(spriteFrame != NULL)
{
return spriteFrame;
}
do
{
Texture2D* texture = createTexture(bm,index,true);
CC_BREAK_IF(! texture);
spriteFrame = SpriteFrame::createWithTexture(texture, Rect(0,0,texture->getContentSize().width, texture->getContentSize().height));
CC_BREAK_IF(! spriteFrame);
SpriteFrameCache::getInstance()->addSpriteFrame(spriteFrame, gifFrameName.c_str());
} while (0);
return spriteFrame;
}
开发者ID:ChisatoKilo,项目名称:gif-for-cocos2dx-3.x,代码行数:24,代码来源:CacheGif.cpp
示例3: FKAssert
bool Sprite::initWithFile(const std::string& filename)
{
FKAssert(filename.size()>0, "Invalid filename for sprite");
Texture2D *texture = new Texture2D();
FKLOG("create image here");
Image* image = dynamic_cast<Image*>(ResourceManager::thisManager()->createResource(filename.c_str(),ResourceManager::IMAGE_NAME));
image->load(false);
texture->initWithImage(image);
if (texture)
{
Rect rect = RectZero;
rect.size = texture->getContentSize();
FKLOG("Sprite size:w %f,h %f",rect.size.width,rect.size.height);
return initWithTexture(texture, rect);
}
// don't release here.
// when load texture failed, it's better to get a "transparent" sprite then a crashed program
// this->release();
return false;
}
开发者ID:sainthsu,项目名称:Flakor,代码行数:23,代码来源:Sprite.cpp
示例4: dim
FrameBufferObject::FrameBufferObject(glm::uvec2 dim, const std::vector<Texture2D*>& textures, Texture2D* depthTexture) :
dim(dim), textures(textures), depthTexture(depthTexture) {
LOG_INFO << "create fbo: " << dim.x << " " << dim.y << std::endl;
glGenFramebuffers(1, &fb);
glBindFramebuffer(GL_FRAMEBUFFER, fb);
LOG_GL_ERRORS();
LOG_DEBUG << "attach textures" << std::endl;
// attach
assert(textures.size() <= 15);
for (unsigned i = 0; i < textures.size(); ++i) {
Texture2D* tex = textures[i];
assert (dim.x == tex->getWidth() && dim.y == tex->getHeight());
LOG_DEBUG << "attach color texture " << i << std::endl;
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_TEXTURE_2D, tex->textureId, 0);
}
if(textures.size() <= 0) {
// instruct openGL that we won't bind a color texture with the currently binded FBO
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
}
if (depthTexture != NULL) {
assert (dim.x == depthTexture->getWidth() && dim.y == depthTexture->getHeight());
LOG_DEBUG << "attach depth texture" << std::endl;
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture->textureId, 0);
}
LOG_DEBUG << "check errors" << std::endl;
checkError();
LOG_DEBUG << "checked errors" << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE);
LOG_GL_ERRORS();
}
开发者ID:MeleeCampz,项目名称:ParticleEngine,代码行数:37,代码来源:FrameBufferObject.cpp
示例5: Size
bool GroundBuilding::init(Layer *gameScene_, b2World *gameWorld_, Point pos)
{
gLayer = gameScene_;
gWorld = gameWorld_;
startPos = pos;
cocos2d::Texture2D::TexParams params = {GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT};
Texture2D* wallTexture = Director::getInstance()->getTextureCache()->addImage("testbuilding_wall.png");
wallTexture->setTexParameters(params);
wallTextureSize = Size(wallTexture->getPixelsWide(), wallTexture->getPixelsHigh());
Texture2D* viewTexture = Director::getInstance()->getTextureCache()->addImage("testbuilding_view.png");
viewTexture->setTexParameters(params);
viewTextureSize = Size(viewTexture->getPixelsWide(), viewTexture->getPixelsHigh());
Texture2D* terrainTexture = Director::getInstance()->getTextureCache()->addImage("terrain.png");
terrainTexture->setTexParameters(params);
Vector2dVector empty;
wall = PRFilledPolygon::filledPolygonWithPointsAndTexture(empty, wallTexture);
higherFrontView = PRFilledPolygon::filledPolygonWithPointsAndTexture(empty, viewTexture);
terrain = PRFilledPolygon::filledPolygonWithPointsAndTexture(empty, terrainTexture);
gLayer->addChild(wall, 2);
gLayer->addChild(terrain,2);
gLayer->addChild(higherFrontView, 60);
setVertices(pos);
return true;
}
开发者ID:gouri34,项目名称:heist,代码行数:37,代码来源:GroundBuilding.cpp
示例6: assertion
Texture2D *ResourceManager::LoadTextureFromDDS (const std::string &filename)
{
assertion(false, "current not do this.");
return 0;
FILE* inFile;
inFile = fopen(filename.c_str(), "rb");
if (!inFile)
{
assertion(false, "Failed to open file %s\n", filename.c_str());
return 0;
}
DDSHeader header;
int numRead = (int)fread(&header, sizeof(header), 1, inFile);
PX2_UNUSED(numRead);
int width = 0;
int height = 0;
int minmap = 1;
Texture::Format format;
GetDescInfo(header, width, height, minmap, format);
Texture2D *texture = new Texture2D(format, width, height, minmap);
fread(texture->GetData(0), texture->GetNumTotalBytes(), 1, inFile);
if (fclose(inFile) != 0)
{
assertion(false, "Failed to read or close file %s\n",
filename.c_str());
return 0;
}
return texture;
}
开发者ID:manyxu,项目名称:Phoenix3D_2.0,代码行数:37,代码来源:PX2ResourceManager.cpp
示例7: ccNextPOT
bool GridBase::initWithSize(const cocos2d::Size &gridSize, const cocos2d::Rect &rect)
{
Director *director = Director::getInstance();
Size s = director->getWinSizeInPixels();
auto POTWide = ccNextPOT((unsigned int)s.width);
auto POTHigh = ccNextPOT((unsigned int)s.height);
// we only use rgba8888
Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
auto dataLen = POTWide * POTHigh * 4;
void *data = calloc(dataLen, 1);
if (! data)
{
CCLOG("cocos2d: Grid: not enough memory.");
this->release();
return false;
}
Texture2D *texture = new (std::nothrow) Texture2D();
texture->initWithData(data, dataLen, format, POTWide, POTHigh, s);
free(data);
if (! texture)
{
CCLOG("cocos2d: Grid: error creating texture");
return false;
}
initWithSize(gridSize, texture, false, rect);
texture->release();
return true;
}
开发者ID:1005491398,项目名称:Threes,代码行数:37,代码来源:CCGrid.cpp
示例8: makeDepthTexture
Texture2D* makeDepthTexture(int width, int height, GLenum internalFormat)
{
Texture2D *depthTex = new Texture2D;
depthTex->setTextureSize(width, height);
depthTex->setSourceFormat(GL_DEPTH_COMPONENT);
depthTex->setSourceType(GL_FLOAT);
depthTex->setInternalFormat(internalFormat);
depthTex->setFilter(Texture2D::MIN_FILTER, Texture2D::NEAREST);
depthTex->setFilter(Texture2D::MAG_FILTER, Texture2D::NEAREST);
depthTex->setWrap(Texture::WRAP_S, Texture::CLAMP_TO_EDGE);
depthTex->setWrap(Texture::WRAP_T, Texture::CLAMP_TO_EDGE);
return depthTex;
}
开发者ID:AndreyIstomin,项目名称:osg,代码行数:13,代码来源:osgfpdepth.cpp
示例9: ccNextPOT
bool GridBase::initWithSize(const Size& gridSize)
{
Director *pDirector = Director::getInstance();
Size s = pDirector->getWinSizeInPixels();
unsigned long POTWide = ccNextPOT((unsigned int)s.width);
unsigned long POTHigh = ccNextPOT((unsigned int)s.height);
// we only use rgba8888
Texture2DPixelFormat format = kTexture2DPixelFormat_RGBA8888;
void *data = calloc((int)(POTWide * POTHigh * 4), 1);
if (! data)
{
CCLOG("cocos2d: Grid: not enough memory.");
this->release();
return false;
}
Texture2D *pTexture = new Texture2D();
pTexture->initWithData(data, format, POTWide, POTHigh, s);
free(data);
if (! pTexture)
{
CCLOG("cocos2d: Grid: error creating texture");
return false;
}
initWithSize(gridSize, pTexture, false);
pTexture->release();
return true;
}
开发者ID:Ben-Cortina,项目名称:GameBox,代码行数:36,代码来源:CCGrid.cpp
示例10: draw_rect_textured
void gfx::draw_rect_textured(float px, float py, float pw, float ph, const Color &pc, const Texture2D &pt)
{
float x2 = px + pw,
y2 = py + ph;
pt.bind();
draw_fill(0, px, py, 0.0f, 0.0f);
draw_fill(1, x2, py, 1.0f, 0.0f);
draw_fill(2, px, y2, 0.0f, 1.0f);
draw_fill(3, x2, y2, 1.0f, 1.0f);
draw_fill(0, pc);
draw_fill(1, pc);
draw_fill(2, pc);
draw_fill(3, pc);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
开发者ID:dtbinh,项目名称:faemiyah-demoscene_2010-08_gamedev_orbital_bombardment,代码行数:15,代码来源:surface.cpp
示例11:
void Urho3DQtApplication::CreateLogo()
{
// Get logo texture
ResourceCache* cache = GetSubsystem<ResourceCache>();
Texture2D* logoTexture = cache->GetResource<Texture2D>("Textures/LogoLarge.png");
if (!logoTexture)
return;
// Create logo sprite and add to the UI layout
UI* ui = GetSubsystem<UI>();
logoSprite_ = ui->GetRoot()->CreateChild<Sprite>();
// Set logo sprite texture
logoSprite_->SetTexture(logoTexture);
int textureWidth = logoTexture->GetWidth();
int textureHeight = logoTexture->GetHeight();
// Set logo sprite scale
logoSprite_->SetScale(256.0f / textureWidth);
// Set logo sprite size
logoSprite_->SetSize(textureWidth, textureHeight);
// Set logo sprite hot spot
logoSprite_->SetHotSpot(0, textureHeight);
// Set logo sprite alignment
logoSprite_->SetAlignment(HA_LEFT, VA_BOTTOM);
// Make logo not fully opaque to show the scene underneath
logoSprite_->SetOpacity(0.75f);
// Set a low priority for the logo so that other UI elements can be drawn on top
logoSprite_->SetPriority(-100);
}
开发者ID:StrongCod3r,项目名称:Urho3D_and_Qt5_with_CMAKE,代码行数:36,代码来源:Urho3DQtApplication.cpp
示例12: CCLOG
bool Sprite::initWithFile(const std::string& filename)
{
if (filename.empty())
{
CCLOG("Call Sprite::initWithFile with blank resource filename.");
return false;
}
_fileName = filename;
_fileType = 0;
Texture2D *texture = _director->getTextureCache()->addImage(filename);
if (texture)
{
Rect rect = Rect::ZERO;
rect.size = texture->getContentSize();
return initWithTexture(texture, rect);
}
// don't release here.
// when load texture failed, it's better to get a "transparent" sprite then a crashed program
// this->release();
return false;
}
开发者ID:boruis,项目名称:cocos2dx-lite,代码行数:24,代码来源:CCSprite.cpp
示例13: ReajustUV
/*-----------------------------------------------------------*/
static void ReajustUV(CinematicBitmap* cb) {
C_UV* uvs = cb->grid.uvs;
for(std::vector<C_INDEXED>::iterator mat = cb->grid.mats.begin(); mat != cb->grid.mats.end(); ++mat)
{
Texture2D* tex = mat->tex;
if (!tex)
return;
int w, h;
w = tex->getStoredSize().x;
h = tex->getStoredSize().y;
if ((w != (int)mat->bitmapw) || (h != (int)mat->bitmaph))
{
float dx = (.999999f * (float)mat->bitmapw) / ((float)w);
float dy = (.999999f * (float)mat->bitmaph) / ((float)h);
int nb2 = mat->nbvertexs;
while (nb2--)
{
uvs->uv.x *= dx;
uvs->uv.y *= dy;
uvs++;
}
}
else
{
uvs += mat->nbvertexs;
}
}
}
开发者ID:DaveMachine,项目名称:ArxLibertatis,代码行数:37,代码来源:CinematicTexture.cpp
示例14: Texture2D
Texture2D* VideoTextureCache::addImageWidthData(const char *filename, int frame, const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const Size& contentSize)
{
ostringstream keystream;
keystream << filename << "_" << frame;
string key = keystream.str();
Texture2D * texture = NULL;
texture = (Texture2D*)m_pTextures->at(key);
if(!texture) {
texture = new Texture2D();
if( texture &&
texture->initWithData(data, dataLen, pixelFormat, pixelsWide, pixelsHigh, contentSize) ) {
m_pTextures->insert(key, texture);
texture->release();
} else {
CCLOG("cocos2d: Couldn't create texture for file:%s in CCVideoTextureCache", key.c_str());
}
} else {
CCLOG("追加画像データ - %s", key.c_str());
}
return texture;
}
开发者ID:TeamLS,项目名称:6chefs2,代码行数:24,代码来源:VideoTextureCache.cpp
示例15: Init
void PhysXTerrain::Init()
{
Model<VertexPosNormTanTex>* pModel = Content->LoadTerrain(m_Path);
Texture2D* pTexTemp = Content->LoadTexture2D(m_Path, true);
vector<NxHeightFieldSample> samples;
samples.reserve(pTexTemp->GetWidth() * pTexTemp->GetHeight());
for_each(pModel->GetModelMeshes()[0]->GetVertices().cbegin(), pModel->GetModelMeshes()[0]->GetVertices().cend(),
[&](const VertexPosNormTanTex& vpnt)
{
NxHeightFieldSample s;
s.height = static_cast<NxI16>(vpnt.position.Y * NX_MAX_I16);
s.tessFlag = 0;
//s.materialIndex0 = 0;
//s.materialIndex1 = 0;
//s.unused = 0;
samples.push_back(s);
});
NxHeightFieldDesc desc;
desc.convexEdgeThreshold = 0;
desc.nbColumns = pTexTemp->GetWidth();
desc.nbRows = pTexTemp->GetHeight();
desc.samples = &samples[0];
desc.sampleStride = sizeof(NxHeightFieldSample);
desc.thickness = -1.0f;
NxHeightField* pHeightField = m_pPhysX->GetSDK()->createHeightField(desc);
ASSERT(pHeightField != 0, "heightfield creation failed");
delete m_pHeightShapeDesc;
m_pHeightShapeDesc = new NxHeightFieldShapeDesc();
m_pHeightShapeDesc->heightField = pHeightField;
m_pHeightShapeDesc->heightScale = m_HeightScale / NX_MAX_I16;
m_pHeightShapeDesc->rowScale = m_PlanarScale / max(pTexTemp->GetWidth(), pTexTemp->GetHeight());
m_pHeightShapeDesc->columnScale = m_PlanarScale / max(pTexTemp->GetWidth(), pTexTemp->GetHeight());
m_pHeightShapeDesc->materialIndexHighBits = 0;
m_pHeightShapeDesc->holeMaterial = 0;
}
开发者ID:BillyKim,项目名称:jello-man,代码行数:41,代码来源:PhysXTerrain.cpp
示例16: drawDebugMaterialTexture
static void drawDebugMaterialTexture(Vec2f & textpos, const std::string & type,
const Texture2D & t, Color color) {
const std::string & name = t.getFileName().string();
std::ostringstream oss;
oss << "(" << t.GetFormat() << ", " << t.getSize().x << "×" << t.getSize().y;
if(t.getStoredSize() != t.getSize()) {
oss << " [" << t.getStoredSize().x << "×" << t.getStoredSize().y << "]";
}
if(t.hasMipmaps()) {
oss << " + mip";
}
oss << ")";
std::string format = oss.str();
float type_s = hFontDebug->getTextSize(type).x + 10;
float name_s = hFontDebug->getTextSize(name).x + 10;
float format_s = hFontDebug->getTextSize(format).x;
Vec2i pos = Vec2i(textpos);
pos.x -= (type_s + name_s + format_s) * 0.5f;
if(pos.x < g_size.left + 5) {
pos.x = g_size.left + 5;
} else if(pos.x + type_s + name_s + format_s > g_size.right - 5) {
pos.x = g_size.right - 5 - (type_s + name_s + format_s);
}
hFontDebug->draw(pos + Vec2i_ONE, type, Color::black);
hFontDebug->draw(pos, type, color);
pos.x += type_s;
hFontDebug->draw(pos + Vec2i_ONE, name, Color::black);
hFontDebug->draw(pos, name, Color::white);
pos.x += name_s;
hFontDebug->draw(pos + Vec2i_ONE, format, Color::black);
hFontDebug->draw(pos, format, Color::gray(0.7f));
textpos.y += hFontDebug->getLineHeight();
}
开发者ID:grimtraveller,项目名称:ArxLibertatis,代码行数:41,代码来源:DrawDebug.cpp
示例17: stbi_load
Resource* ResourceManager::LoadTexture2D(std::string filepath)
{
Image image;
int width, height, components;
image.data = stbi_load(filepath.c_str(), &width, &height, &components, 0);
image.width = width;
image.height = height;
image.components = components;
// This may not work as intended
if (image.data == NULL)
{
#ifdef DEBUG
Debug::LogError("[ResourceManager] Texture2D could not be loaded.");
#endif
return 0;
}
Texture2D* texture = new Texture2D(image);
texture->IncreaseReferenceCount();
resourceCollection[filepath] = texture;
return dynamic_cast<Resource*>(texture);
}
开发者ID:ariabonczek,项目名称:LuminaEngine_OLD,代码行数:24,代码来源:ResourceManager.cpp
示例18: addTexture
int FrameBuffer::addTexture( Texture2D& target , bool beManaged )
{
int idx = mTextures.size();
Info info;
info.handle = target.mHandle;
info.idx = 0;
info.bManaged = ( beManaged ) ? target.mbManaged : false;
if ( info.bManaged )
target.release();
mTextures.push_back( info );
setTextureInternal( idx , info , GL_TEXTURE_2D );
return idx;
}
开发者ID:uvbs,项目名称:GameProject,代码行数:16,代码来源:GLCommon.cpp
示例19:
void Batch2D::SetTexture(Texture2D& tex, glm::vec4* sourceRect){
if (texture){
//if texture is different from previous
if (texture->GetHandle() != tex.GetHandle()){
//draw all stored sprites
Flush();
//set texture handle
texture = &tex;
//bind texture to texture unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture->GetHandle());
}
//else: if texture is same as previous, do not bind
}
//no previous texture
else{
//set texture handle
texture = &tex;
//bind texture to texture unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture->GetHandle());
}
//set sourceDim and sourceTexCoords(normalized) based on sourceRect and texture
if (sourceRect == nullptr){
sourceDim = glm::vec2(texture->GetWidth(), texture->GetHeight());
sourceTexCoords[0] = glm::vec2(0.f, 0.f);
sourceTexCoords[1] = glm::vec2(1.f, 0.f);
sourceTexCoords[2] = glm::vec2(0.f, 1.f);
sourceTexCoords[3] = glm::vec2(1.f, 1.f);
}
else{
sourceDim = glm::vec2(sourceRect->z, sourceRect->w);
glm::float32 w = 1.f / texture->GetWidth();
glm::float32 h = 1.f / texture->GetHeight();
sourceTexCoords[0] = glm::vec2(sourceRect->x * w, sourceRect->y * h);
sourceTexCoords[1] = glm::vec2(sourceRect->z * w, sourceRect->y * h);
sourceTexCoords[2] = glm::vec2(sourceRect->x * w, sourceRect->w * h);
sourceTexCoords[3] = glm::vec2(sourceRect->z * w, sourceRect->w * h);
}
}
开发者ID:mattmason03,项目名称:rts,代码行数:47,代码来源:Batch2D.cpp
示例20: Texture2D
void FilteredSpriteWithMulti::update(float delta) {
if (_filterIdxCompound < 0) {
return;
}
if (_filterIdxCompound >= _pFilters.size()) {
//finish
_filterIdxCompound = -1;
Texture2D *texture = nullptr;
texture = new Texture2D();
texture->autorelease();
Image *pNewImage = _pRenderTextureCompound->newImage(true);
texture->initWithImage(pNewImage);
delete pNewImage;
initWithTexture(texture);
_pFilterSpiteCompound->release();
_pFilterSpiteCompound = nullptr;
return;
}
_pRenderTextureCompound->begin();
Filter* __filter = static_cast<Filter*>(_pFilters.at(_filterIdxCompound));
if (nullptr != _pFilterSpiteCompound) {
_pFilterSpiteCompound->release();
_pFilterSpiteCompound = nullptr;
}
if (_filterIdxCompound == 0)
{
_pFilterSpiteCompound = _pTexture ?
FilteredSpriteWithOne::createWithTexture(_pTexture) :
FilteredSpriteWithOne::createWithSpriteFrame(_pFrame);
}
else
{
Texture2D *texture = nullptr;
texture = new Texture2D();
texture->autorelease();
Image * pNewImage = _pRenderTextureCompound->newImage(true);
texture->initWithImage(pNewImage);
delete pNewImage;
_pFilterSpiteCompound = FilteredSpriteWithOne::createWithTexture(texture);
}
_pFilterSpiteCompound->retain();
_pFilterSpiteCompound->setFilter(__filter);
_pFilterSpiteCompound->setAnchorPoint(Vec2(0, 0));
_pFilterSpiteCompound->visit();
_pRenderTextureCompound->end();
_filterIdxCompound++;
}
开发者ID:1284949699,项目名称:Quick-Cocos2dx-Community,代码行数:53,代码来源:CCFilteredSprite.cpp
注:本文中的Texture2D类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论