void SurveyMapEntity::updateIcon()
{
	// check if static only icon
	String imageFile = "icon_" + mType + "_" + entityStates[mState] + ".dds";

	if (mIsStatic)
	{
		imageFile = "icon_" + mType + ".dds";
	}

	// set image texture to load it into memory, so TextureManager::getByName will have it loaded if files exist
	mIcon->setImageTexture(imageFile);

	TexturePtr texture = (TexturePtr)(TextureManager::getSingleton().getByName(imageFile));
	if (texture.isNull())
	{
		imageFile = "icon_missing.dds";
		texture = (TexturePtr)(TextureManager::getSingleton().getByName(imageFile));
	}

	if (!texture.isNull())
	{
		mIconSize.width  = (int)texture->getWidth();
		mIconSize.height = (int)texture->getHeight();
		mIcon->setSize(mIconSize);
	}
	
	if (mIconRotating)
	{
		mIconRotating->setCenter(MyGUI::IntPoint(mIcon->getWidth()/2, mIcon->getHeight()/2));
		mIconRotating->setAngle(mRotation);
	}
}
// -------------------------------------------------------------------------
OgreBulletGuiListener::OgreBulletGuiListener(OgreBulletListener *listener, Ogre::RenderWindow *win) :
    mListener(listener),
    mWindow(win),
    mMouseOverlay(0),
    mMousePanel(0)
{	
        
    /******************* CREATE Cursor Overlay ***************************/
    mMouseOverlay = (Overlay*)OverlayManager::getSingleton().getByName("GuiOverlay");
    if (mMouseOverlay)
    {
        mMousePanel = OverlayManager::getSingleton().getOverlayElement ("GUIMouse");
    }
    else
    {
        mMouseOverlay = OverlayManager::getSingletonPtr()->create("GuiOverlay");
        mMouseOverlay->setZOrder(600);
        mMousePanel = (Ogre::OverlayElement *)
            OverlayManager::getSingletonPtr()->createOverlayElement("Panel", "GUIMouse");
        mMousePanel->setMaterialName("OgreBulletDemos/TargetSights");

        TexturePtr mouseTex = TextureManager::getSingleton().load("target.png", "Bullet");
        mMousePanel->setWidth (mouseTex->getWidth() / (float)win->getWidth());
        mMousePanel->setHeight (mouseTex->getHeight() / (float)win->getHeight());

        Ogre::OverlayContainer		*mouseContainer = (Ogre::OverlayContainer*) 
            OverlayManager::getSingletonPtr()->createOverlayElement("Panel", "GUIContainer");
        mMouseOverlay->add2D(mouseContainer);
        mouseContainer->addChild(mMousePanel);
    }

    mMouseOverlay->show(); 
    TexturePtr mouseTex = TextureManager::getSingleton().load("target.png", "Bullet");
    mMouseCursorHalfWidth = (Real(mouseTex->getWidth()) / mWindow->getWidth()) * 0.5;
    mMouseCursorHalfHeight = (Real(mouseTex->getHeight())  / mWindow->getHeight ()) * 0.5;

    /******************* CREATE GUI ***************************/
    mGui = new BetaGUI::GUI("OgreBulletGui", "BlueHighway", 14, win);
    OverlayContainer* mouseCursor = mGui->createMousePointer(Vector2(32, 32), "bgui.pointer");
    mouseCursor->hide();

    mGui->injectMouse(mWindow->getWidth() * 0.5, mWindow->getHeight() * 0.5, false);

}
Esempio n. 3
0
    //-----------------------------------------------------------------------
    std::pair< size_t, size_t > TextureUnitState::getTextureDimensions( unsigned int frame ) const
    {
		
		TexturePtr tex = _getTexturePtr(frame);
	    if (tex.isNull())
		    OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find texture " + mFrames[ frame ],
		    "TextureUnitState::getTextureDimensions" );

		return std::pair< size_t, size_t >( tex->getWidth(), tex->getHeight() );
    }
Esempio n. 4
0
    //-----------------------------------------------------------------------
    std::pair< size_t, size_t > TextureUnitState::getTextureDimensions( unsigned int frame ) const
    {
        
        TexturePtr tex = _getTexturePtr(frame);
        if (!tex)
            OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find texture " + StringConverter::toString(frame),
            "TextureUnitState::getTextureDimensions" );

        return std::pair< size_t, size_t >( tex->getWidth(), tex->getHeight() );
    }
Esempio n. 5
0
GlTexture getGlTexture(const TexturePtr& outputTexture)
{
	GlTexture glTexture;
	glTexture.width = outputTexture->getWidth();
	glTexture.height = outputTexture->getHeight();
	glTexture.depth = outputTexture->getDepth();
	glTexture.target = toGlTargetType(outputTexture->getType());
	glTexture.textureId = outputTexture->_getGlTextureId();
	return glTexture;
}
Esempio n. 6
0
void UINode::renderImage (const TexturePtr& texture, int x, int y, int w, int h, float alpha) const
{
	if (!texture || !texture->isValid())
		return;

	if (w == -1)
		w = texture->getWidth();
	if (h == -1)
		h = texture->getHeight();

	_frontend->renderImage(texture.get(), x, y, w, h, 0, alpha);
}
Esempio n. 7
0
 TextureRegion::TextureRegion(TexturePtr texture)
 :_leftX(0),
 _topY(0),
 _texRef(texture),
 _width(texture->getWidth()),
 _height(texture->getHeight()),
 _isRotated(false)
 {        
     this->_u1 = 0.0;
     this->_u2 = 1.0;
     this->_v1 = 0.0;
     this->_v2 = 1.0;
 }
void SaveImage(TexturePtr TextureToSave, String filename)
{
    HardwarePixelBufferSharedPtr readbuffer;
    readbuffer = TextureToSave->getBuffer(0, 0);
    readbuffer->lock(HardwareBuffer::HBL_NORMAL );
    const PixelBox &readrefpb = readbuffer->getCurrentLock();
    uchar *readrefdata = static_cast<uchar*>(readrefpb.data);

    Image img;
    img = img.loadDynamicImage (readrefdata, TextureToSave->getWidth(),
                                TextureToSave->getHeight(), TextureToSave->getFormat());
    img.save(filename);

    readbuffer->unlock();
}
void DashBoard::windowResized()
{
    if (!mainWidget) return;
    mainWidget->setPosition(0, 0);
    if (textureLayer)
    {
        // texture layers are independent from the screen size, but rather from the layer texture size
        TexturePtr tex = TextureManager::getSingleton().getByName("RTTTexture1");
        if (!tex.isNull())
            mainWidget->setSize(tex->getWidth(), tex->getHeight());
    } else
    {
        MyGUI::IntSize screenSize = MyGUI::RenderManager::getInstance().getViewSize();
        mainWidget->setSize(screenSize);
    }
}
Esempio n. 10
0
 TextureRegion::TextureRegion(TexturePtr texture, unsigned int leftX, unsigned int topY, unsigned int width, unsigned int height)
 :_leftX(leftX),
 _topY(topY),
 _width(width),
 _height(height),
 _isRotated(false),
 _texRef(nullptr)
 {
     _texRef = texture;
     int tWidth = texture->getWidth();
     int tHeight = texture->getHeight();
     
     this->_u1 = (float)leftX / tWidth;
     this->_u2 = (float)(leftX + _width) / tWidth;
     this->_v1 = (float)topY / tHeight;
     this->_v2 = (float)(topY + _height) / tHeight;
 }
Esempio n. 11
0
	//! Implementation of VolumeRenderableMaterialFactory
	MaterialPtr createMaterial(const SparseVolumeMaterialConfig& config) const
	{
		TexturePtr densityTexture = getGridForRole(config.leafAtlases, GridTextureRole_Diffuse);
		assert(densityTexture);

		TexturePtr normalTexture = getGridForRole(config.leafAtlases, GridTextureRole_Normal);
		TexturePtr temperatureTexture = getGridForRole(config.leafAtlases, GridTextureRole_Temperature);

		MaterialPtr material(new Material);

		glm::vec3 densityTextureSize(densityTexture->getWidth(), densityTexture->getHeight(), densityTexture->getDepth());

		// Main technique
		{
			TechniquePtr technique(new Technique(m_volumeShader));
			{
				Vec3ShaderParameterPtr boxModelSizeParameter(new Vec3ShaderParameter("volumeSize_modelSpace", config.boxSize));
				technique->addCustomShaderParameter(boxModelSizeParameter);

				Vec3ShaderParameterPtr oneOnVolumeTextureSizeParameter(new Vec3ShaderParameter("oneOnVolumeTextureSize", 1.0f / densityTextureSize));
				technique->addCustomShaderParameter(oneOnVolumeTextureSizeParameter);

				technique->setAlphaBlendingMode(AlphaBlendingMode_PreMultiplied);

				int maxLeafCountPerInternalNode = config.maxLeafCountPerInternalNodeDimension * config.maxLeafCountPerInternalNodeDimension * config.maxLeafCountPerInternalNodeDimension;

				technique->addCustomShaderParameter(ShaderParameterPtr(new IntShaderParameter("firstInternalNodeIndex", config.firstInternalNodeIndex)));
				technique->addCustomShaderParameter(ShaderParameterPtr(new IntShaderParameter("maxLeafCountPerInternalNode", maxLeafCountPerInternalNode)));
				technique->addCustomShaderParameter(ShaderParameterPtr(new IVec3ShaderParameter("maxLeafCountPerAtlasDimension", config.maxLeafCountPerAtlasDimension)));
				technique->addCustomShaderParameter(ShaderParameterPtr(new IntShaderParameter("maxLeafCountPerInternalNodeDimension", config.maxLeafCountPerInternalNodeDimension)));
				
				float thresholdAlpha = m_transparent ? 0.001 : 0.2;
				technique->addCustomShaderParameter(ShaderParameterPtr(new FloatShaderParameter("thresholdAlpha", thresholdAlpha)));

				float opacityMultiplier = m_transparent ? m_opacityMultiplier : 200.0;
				technique->addCustomShaderParameter(ShaderParameterPtr(new FloatShaderParameter("opacityMultiplier", opacityMultiplier)));

				{
					TextureUnit unit(densityTexture, "albedoSampler");
					technique->addTextureUnit(unit);
				}

				if (normalTexture)
				{
					TextureUnit unit(normalTexture, "normalSampler");
					technique->addTextureUnit(unit);
				}

				if (temperatureTexture)
				{
					TextureUnit unit(temperatureTexture, "temperatureSampler");
					technique->addTextureUnit(unit);
				}

				TextureUnit unit(m_temperatureRampTexture, "temperatureRampSampler");
				technique->addTextureUnit(unit);

				{
					TextureUnit unit(config.nodeIndirectionTexture, "nodeIndirectionSampler");
					technique->addTextureUnit(unit);
				}
			}

			material->setTechnique(technique);
		}

		return material;
	}
void TextureToolWindow::updateControls(String texName)
{
    try
    {
        bool exists = TextureManager::getSingleton().resourceExists(texName);
        if (!exists)
        {
            mTxt->setCaption(convertToMyGUIString("Texture not found:\n" + texName));
            mBtnSavePNG->setEnabled(false);
            return;
        }

        TexturePtr tex = TextureManager::getSingleton().getByName(texName);
        if (tex.isNull())
        {
            mTxt->setCaption(convertToMyGUIString("Error loading texture:\n" + texName));
            mBtnSavePNG->setEnabled(false);
            return;
        }

        String str = "#aa0000" + texName + "#000000\n";
        str += "#00aa00res: #000000" + TOSTRING(tex->getWidth()) + " x " + TOSTRING(tex->getHeight()) + " pixels\n";
        str += "#00aa00size: #000000" + formatBytes(tex->getSize()) + "\n";
        str += "#00aa00format: #000000" + PixelUtil::getFormatName(tex->getFormat()) + "\n";
        if (tex->getNumFaces() > 1)
            str += "#00aa00faces: #000000" + TOSTRING(tex->getNumFaces()) + "\n";
        if (tex->getFSAA() > 0)
            str += "#00aa00FSAA: #000000" + TOSTRING(tex->getFSAA()) + "\n";
        if (tex->getNumMipmaps() > 0)
            str += "#00aa00mipmaps: #000000" + TOSTRING(tex->getNumMipmaps()) + "\n";

        String typeStr = "";
        switch (tex->getTextureType())
        {
        case TEX_TYPE_1D: typeStr = "1D";
            break;
        case TEX_TYPE_2D: typeStr = "2D";
            break;
        case TEX_TYPE_3D: typeStr = "3D";
            break;
        case TEX_TYPE_CUBE_MAP: typeStr = "Cube Map";
            break;
        }
        str += "#00aa00type: #000000" + typeStr + "\n";

        String usageStr = "";
        if (tex->getUsage() & TU_STATIC)
            usageStr += "static,\n";
        if (tex->getUsage() & TU_DYNAMIC)
            usageStr += "dynamic,\n";
        if (tex->getUsage() & TU_WRITE_ONLY)
            usageStr += "write only,\n";
        if (tex->getUsage() & TU_STATIC_WRITE_ONLY)
            usageStr += "static write only,\n";
        if (tex->getUsage() & TU_DYNAMIC_WRITE_ONLY)
            usageStr += "dynamic write only,\n";
        if (tex->getUsage() & TU_DYNAMIC_WRITE_ONLY_DISCARDABLE)
            usageStr += "dynamic write only discardable,\n";
        if (tex->getUsage() & TU_AUTOMIPMAP)
            usageStr += "automipmap,\n";
        if (tex->getUsage() & TU_RENDERTARGET)
            usageStr += "rendertarget,\n";
        if (tex->getUsage() & TU_DEFAULT)
            usageStr += "default\n";

        str += "#00aa00usage: #000000" + usageStr + "\n";
        if (tex->getDepth() > 1)
            str += "#00aa00depth: #000000" + TOSTRING(tex->getDepth()) + "\n";

        mTxt->setCaption(convertToMyGUIString(str));
        mImage->setImageTexture(texName);
        mBtnSavePNG->setEnabled(true);
    }
    catch (Exception& e)
    {
        UTFString str = "Exception while opening texture:" + e.getFullDescription();
        RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, str, "error.png");
    }
}
void WriteToTexture(const String &str, TexturePtr destTexture, Image::Box destRectangle, Font* font, const ColourValue &color, char justify,  bool wordwrap)
{
    using namespace Ogre;

    if (destTexture->getHeight() < destRectangle.bottom)
        destRectangle.bottom = destTexture->getHeight();
    if (destTexture->getWidth() < destRectangle.right)
        destRectangle.right = destTexture->getWidth();

    if (!font->isLoaded())
        font->load();

    TexturePtr fontTexture = (TexturePtr) TextureManager::getSingleton().getByName(font->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName());

    HardwarePixelBufferSharedPtr fontBuffer = fontTexture->getBuffer();
    HardwarePixelBufferSharedPtr destBuffer = destTexture->getBuffer();

    PixelBox destPb = destBuffer->lock(destRectangle,HardwareBuffer::HBL_NORMAL);

    // The font texture buffer was created write only...so we cannot read it back :o). One solution is to copy the buffer  instead of locking it. (Maybe there is a way to create a font texture which is not write_only ?)

    // create a buffer
    size_t nBuffSize = fontBuffer->getSizeInBytes();
    unsigned char* buffer = (unsigned char*)calloc(nBuffSize, sizeof(unsigned char));

    // create pixel box using the copy of the buffer
    PixelBox fontPb(fontBuffer->getWidth(), fontBuffer->getHeight(),fontBuffer->getDepth(), fontBuffer->getFormat(), buffer);
    fontBuffer->blitToMemory(fontPb);

    unsigned char* fontData = static_cast<unsigned char*>( fontPb.data );
    unsigned char* destData = static_cast<unsigned char*>( destPb.data );

    const size_t fontPixelSize = PixelUtil::getNumElemBytes(fontPb.format);
    const size_t destPixelSize = PixelUtil::getNumElemBytes(destPb.format);

    const size_t fontRowPitchBytes = fontPb.rowPitch * fontPixelSize;
    const size_t destRowPitchBytes = destPb.rowPitch * destPixelSize;

    Box *GlyphTexCoords;
    GlyphTexCoords = new Box[str.size()];

    Font::UVRect glypheTexRect;
    size_t charheight = 0;
    size_t charwidth = 0;

    for (unsigned int i = 0; i < str.size(); i++)
    {
        if ((str[i] != '\t') && (str[i] != '\n') && (str[i] != ' '))
        {
            glypheTexRect = font->getGlyphTexCoords(str[i]);
            GlyphTexCoords[i].left = glypheTexRect.left * fontTexture->getSrcWidth();
            GlyphTexCoords[i].top = glypheTexRect.top * fontTexture->getSrcHeight();
            GlyphTexCoords[i].right = glypheTexRect.right * fontTexture->getSrcWidth();
            GlyphTexCoords[i].bottom = glypheTexRect.bottom * fontTexture->getSrcHeight();

            if (GlyphTexCoords[i].getHeight() > charheight)
                charheight = GlyphTexCoords[i].getHeight();
            if (GlyphTexCoords[i].getWidth() > charwidth)
                charwidth = GlyphTexCoords[i].getWidth();
        }

    }

    size_t cursorX = 0;
    size_t cursorY = 0;
    size_t lineend = destRectangle.getWidth();
    bool carriagreturn = true;
    for (unsigned int strindex = 0; strindex < str.size(); strindex++)
    {
        switch(str[strindex])
        {
        case ' ':
            cursorX += charwidth;
            break;
        case '\t':
            cursorX += charwidth * 3;
            break;
        case '\n':
            cursorY += charheight;
            carriagreturn = true;
            break;
        default:
        {
            //wrapping
            if ((cursorX + GlyphTexCoords[strindex].getWidth()> lineend) && !carriagreturn )
            {
                cursorY += charheight;
                carriagreturn = true;
            }

            //justify
            if (carriagreturn)
            {
                size_t l = strindex;
                size_t textwidth = 0;
                size_t wordwidth = 0;

                while( (l < str.size() ) && (str[l] != '\n'))
                {
                    wordwidth = 0;

                    switch (str[l])
                    {
                    case ' ':
                        wordwidth = charwidth;
                        ++l;
                        break;
                    case '\t':
                        wordwidth = charwidth *3;
                        ++l;
                        break;
                    case '\n':
                        l = str.size();
                    }

                    if (wordwrap)
                        while((l < str.size()) && (str[l] != ' ') && (str[l] != '\t') && (str[l] != '\n'))
                        {
                            wordwidth += GlyphTexCoords[l].getWidth();
                            ++l;
                        }
                    else
                    {
                        wordwidth += GlyphTexCoords[l].getWidth();
                        l++;
                    }

                    if ((textwidth + wordwidth) <= destRectangle.getWidth())
                        textwidth += (wordwidth);
                    else
                        break;
                }

                if ((textwidth == 0) && (wordwidth > destRectangle.getWidth()))
                    textwidth = destRectangle.getWidth();

                switch (justify)
                {
                case 'c':
                    cursorX = (destRectangle.getWidth() - textwidth)/2;
                    lineend = destRectangle.getWidth() - cursorX;
                    break;

                case 'r':
                    cursorX = (destRectangle.getWidth() - textwidth);
                    lineend = destRectangle.getWidth();
                    break;

                default:
                    cursorX = 0;
                    lineend = textwidth;
                    break;
                }

                carriagreturn = false;
            }

            //abort - net enough space to draw
            if ((cursorY + charheight) > destRectangle.getHeight())
                goto stop;

            //draw pixel by pixel
            for (size_t i = 0; i < GlyphTexCoords[strindex].getHeight(); i++ )
                for (size_t j = 0; j < GlyphTexCoords[strindex].getWidth(); j++)
                {
                    float alpha =  color.a * (fontData[(i + GlyphTexCoords[strindex].top) * fontRowPitchBytes + (j + GlyphTexCoords[strindex].left) * fontPixelSize +1 ] / 255.0);
                    float invalpha = 1.0 - alpha;
                    size_t offset = (i + cursorY) * destRowPitchBytes + (j + cursorX) * destPixelSize;
                    ColourValue pix;
                    PixelUtil::unpackColour(&pix,destPb.format,&destData[offset]);
                    pix = (pix * invalpha) + (color * alpha);
                    PixelUtil::packColour(pix,destPb.format,&destData[offset]);
                }

            cursorX += GlyphTexCoords[strindex].getWidth();
        }//default
        }//switch
    }//for

stop:
    delete[] GlyphTexCoords;

    destBuffer->unlock();

    // Free the memory allocated for the buffer
    free(buffer);
    buffer = 0;
}