本文整理汇总了C++中Texture2D类的典型用法代码示例。如果您正苦于以下问题:C++ Texture2D类的具体用法?C++ Texture2D怎么用?C++ Texture2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Texture2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}