void SubrectQuad::setSubrect(const glm::ivec2& subrectStart, const glm::ivec2& subrectEnd)
    {
        mSubrectStart = subrectStart;
        mSubrectEnd = subrectEnd;

        updateTexCoords();
    }
Beispiel #2
0
void Sprite::setTextureRect(const Rect &rect) {
	if (rect != mTextureRect) {
		mTextureRect = rect;
		updatePositions();
		updateTexCoords();
	}
}
Beispiel #3
0
void Shape::update()
{
    // Get the total number of points of the shape
    std::size_t count = getPointCount();
    if (count < 3)
    {
        m_vertices.resize(0);
        m_outlineVertices.resize(0);
        return;
    }

    m_vertices.resize(count + 2); // + 2 for center and repeated first point

    // Position
    for (std::size_t i = 0; i < count; ++i)
        m_vertices[i + 1].position = getPoint(i);
    m_vertices[count + 1].position = m_vertices[1].position;

    // Update the bounding rectangle
    m_vertices[0] = m_vertices[1]; // so that the result of getBounds() is correct
    m_insideBounds = m_vertices.getBounds();

    // Compute the center and make it the first vertex
    m_vertices[0].position.x = m_insideBounds.left + m_insideBounds.width / 2;
    m_vertices[0].position.y = m_insideBounds.top + m_insideBounds.height / 2;

    // Color
    updateFillColors();

    // Texture coordinates
    updateTexCoords();

    // Outline
    updateOutline();
}
Beispiel #4
0
inline void vertex_buffer_object<Ta, Te>::update()
{
    updateVertices();
    updateNormals();
    updateColors();
    updateTexCoords();
    updateElements();
}
Beispiel #5
0
 void Sprite::setTextureRect(const IntRect& rectangle)
 {
     if (rectangle != m_textureRect)
     {
         m_textureRect = rectangle;
         updateTexCoords();
     }
 }
Beispiel #6
0
		void ISimpleNode::updateGeometry()
		{
			updateGeometrySimpleNode();

			// Color
			updateFillColors();

			// Texture coordinates
			updateTexCoords();
		}
Beispiel #7
0
void DrawContext::drawTexturedRect(const Rect& rect, const TexturePtr& tex, const Color& col, bool flipX, bool flipY)
{
  updateTexCoords(flipX, flipY);
  bgquad->transform = Matrix::translate(rect.x, rect.y) * Matrix::scale(rect.width, rect.height);
  bgquad->material->color = col.premultiplied();
  bgquad->material->shader = textureShader;
  bgquad->material->limitTextures(1);
  bgquad->material->setTexture(0, tex);
  bgquad->material->blendPremultiplied();
  glContext->draw(bgquad);
}
Beispiel #8
0
void DrawContext::updateTexCoords(bool flipX, bool flipY)
{
  // disabled flip state caching and comparison since it would clash with image drawing when
  // state wasn't set 
//  if((_flipX != flipX) || (_flipY != flipY))
//  {
    _flipX = flipX;
    _flipY = flipY;
    updateTexCoords();
//  }
}
Beispiel #9
0
DrawContext::DrawContext(Context* ctx)
{
  glContext = ctx;
  
  _textBuffer = new TextBuffer;
  
  // load some common shaders
  colorShader = Application::instance()->resourceManager->shader("resources/glsl/color");
  textureShader = Application::instance()->resourceManager->shader("resources/glsl/texture");
  
  // create buffers for efficient quad drawing. Vertex and index buffers are reused as often as possible
  BufferLayout layout;
  layout.add(ET_vec2_f32, UT_position);
  layout.add(ET_vec2_f32, UT_texcoord0);
  bgquad = Mesh::create(layout, ET_u16);
  bgquad->resetSize(4, 6);
  bgquad->indexBuffer->drawMode = GL_TRIANGLES;
  
  bgquad->set(0, UT_position, Vec2(0,0));
  bgquad->set(1, UT_position, Vec2(1,0));
  bgquad->set(2, UT_position, Vec2(1,1));
  bgquad->set(3, UT_position, Vec2(0,1));
  
  bgquad->set(0,UT_texcoord0, Vec2(0,0));
  bgquad->set(1,UT_texcoord0, Vec2(1,0));
  bgquad->set(2,UT_texcoord0, Vec2(1,1));
  bgquad->set(3,UT_texcoord0, Vec2(0,1));
  
  bgquad->set(0, UT_index, (u16)0);
  bgquad->set(1, UT_index, (u16)1);
  bgquad->set(2, UT_index, (u16)2);
  bgquad->set(3, UT_index, (u16)2);
  bgquad->set(4, UT_index, (u16)3);
  bgquad->set(5, UT_index, (u16)0);
  
  bgquad->material->shader = colorShader;
  bgquad->material->color = whiteColor;
  bgquad->material->blendPremultiplied();
  
  textMesh.reset(new TextMesh);
  textMesh->material->shader = textureShader;
  textMesh->material->color = whiteColor;
  
  _flipX = false;
  _flipY = false;
  updateTexCoords();
  
  ninePatch.reset(new NinePatch);
  ninePatch->flip = true;
  ninePatch->material->shader = textureShader;
  ninePatch->material->blendPremultiplied();
}
Beispiel #10
0
void Sprite::setTextureRect(const IntRect& rectangle)
{
    if (rectangle != m_textureRect)
    {
        m_textureRect = rectangle;
        updatePositions();
        updateTexCoords();

        // Update the vertex buffer if it is being used
        if (VertexBuffer::isAvailable())
            m_verticesBuffer.update(m_vertices);
    }
}
Beispiel #11
0
void NinePatch::update(const TexturePtr& tex,
                      const Vec2& inSize,
                      float l,
                      float r,
                      float t,
                      float b)
{
  size = inSize;
  left = l;
  right = r;
  top = t;
  bottom = b;
  material->setTexture(0, tex);

  updateVertices();
  updateTexCoords();  
}
Beispiel #12
0
void TextRenderer::DrawStringAlpha(int x, int y, int textSize, const string &text, float rTop, float gTop, float bTop, float rBot, float gBot, float bBot, float alpha)
{
	GLFuncs* g = GLFuncs::GetInstance();
    int xPos;
    int charPos;
	char currentChar;

	charPos = 0;
	xPos = x;

	if (this->_texture == NULL) {
		this->_texture = TextureMgr::GetInstance()->LoadTexture("data/font.png");
		if(this->_texture == NULL) {
			Log::Out << "TextRenderer::DrawStringAlpha: Couldn't load font!" << endl;
			return;
		}
	}

	if (g->CanUseShaders()) {
		if (this->_program == NULL) {
			vector<string> vertexShaders = { "data/shaders/Default.150.vertex" };
			vector<string> fragmentShaders = { "data/shaders/TexturedColored.150.fragment" };
			this->_program = new Program(vertexShaders, fragmentShaders);
			this->_program->Textures.push_back(this->_texture);
		}

		this->_program->Use();
		this->_program->BindTextures();
		this->_program->SetUniform("MVP", g->MVP);
	}
	else {
		g->SetTexture(0, this->_texture->texture);
	}

	GLfloat color_buffer_data[] = {
		rTop, gTop, bTop, alpha,
		rTop, gTop, bTop, alpha,
		rBot, gBot, bBot, alpha,
		rBot, gBot, bBot, alpha
	};

	while(text[charPos] != 0)
	{
		float tx1, tx2, ty1, ty2;

		currentChar = text[charPos++];

		updateTexCoords(currentChar, &tx1, &ty1, &tx2, &ty2);

		GLfloat vertex_buffer_data[] = {
			(float)xPos, (float)y, 0.0f,
			(float)xPos + textSize, (float)y, 0.0f,
			(float)xPos + textSize, (float)y + textSize, 0.0f,
			(float)xPos, (float)y + textSize, 0.0f
		};

		GLfloat uv_buffer_data[] = {
			tx1, ty1,
			tx2, ty1,
			tx2, ty2,
			tx1, ty2
		};

		g->BlitVerts(vertex_buffer_data, sizeof(vertex_buffer_data), uv_buffer_data, sizeof(uv_buffer_data), color_buffer_data, sizeof(color_buffer_data));
		
		xPos += textSize;
	}
}
void ParticleSystemQuad::setTotalParticles(int tp)
{
    // If we are setting the total number of particles to a number higher
    // than what is allocated, we need to allocate new arrays
    if( tp > _allocatedParticles )
    {
        // Allocate new memory
        size_t quadsSize = sizeof(_quads[0]) * tp * 1;
        size_t indicesSize = sizeof(_indices[0]) * tp * 6 * 1;

        _particleData.release();
        if (!_particleData.init(tp))
        {
            CCLOG("Particle system: not enough memory");
            return;
        }
        V3F_C4B_T2F_Quad* quadsNew = (V3F_C4B_T2F_Quad*)realloc(_quads, quadsSize);
        GLushort* indicesNew = (GLushort*)realloc(_indices, indicesSize);

        if (quadsNew && indicesNew)
        {
            // Assign pointers
            _quads = quadsNew;
            _indices = indicesNew;

            // Clear the memory
            memset(_quads, 0, quadsSize);
            memset(_indices, 0, indicesSize);

            _allocatedParticles = tp;
        }
        else
        {
            // Out of memory, failed to resize some array
            if (quadsNew) _quads = quadsNew;
            if (indicesNew) _indices = indicesNew;

            CCLOG("Particle system: out of memory");
            return;
        }

        _totalParticles = tp;

        // Init particles
        if (_batchNode)
        {
            for (int i = 0; i < _totalParticles; i++)
            {
                _particleData.atlasIndex[i] = i;
            }
        }

        initIndices();
        if (Configuration::getInstance()->supportsShareableVAO())
        {
            setupVBOandVAO();
        }
        else
        {
            setupVBO();
        }

        // fixed http://www.cocos2d-x.org/issues/3990
        // Updates texture coords.
        updateTexCoords();
    }
    else
    {
        _totalParticles = tp;
    }

    // fixed issue #5762
    // reset the emission rate
    setEmissionRate(_totalParticles / _life);

    resetSystem();
}
Beispiel #14
0
void Shape::setTextureRect(const IntRect& rect)
{
    m_textureRect = rect;
    updateTexCoords();
}
Beispiel #15
0
void GCheckbox::mouseClick(int x, int y) {
	*value_ptr = !(*value_ptr);
	updateTexCoords();
	flagChanged();
}
Beispiel #16
0
void GCheckbox::load(GINI* ini) {
	*value_ptr = ini->getBool(clean_name, false);
	updateTexCoords();
}
 void SubrectQuad::setTexture(const Texture& texture)
 {
     Quad::setTexture(texture);
     updateTexCoords();
 }
void BillboardParticleSystem::setTotalParticles(int tp)
{
    // If we are setting the total number of particles to a number higher
    // than what is allocated, we need to allocate new arrays
    if( tp > _allocatedParticles )
    {
        // Allocate new memory
        size_t particlesSize = tp * sizeof(tParticle);
        size_t quadsSize = sizeof(_quads[0]) * tp * 1;
        size_t indicesSize = sizeof(_indices[0]) * tp * 6 * 1;

        sBillboardParticle* particlesNew = (sBillboardParticle*)realloc(_particles, particlesSize);
        V3F_C4B_T2F_Quad* quadsNew = (V3F_C4B_T2F_Quad*)realloc(_quads, quadsSize);
        GLushort* indicesNew = (GLushort*)realloc(_indices, indicesSize);

        if (particlesNew && quadsNew && indicesNew)
        {
            // Assign pointers
            _particles = particlesNew;
            _quads = quadsNew;
            _indices = indicesNew;

            // Clear the memory
            memset(_particles, 0, particlesSize);
            memset(_quads, 0, quadsSize);
            memset(_indices, 0, indicesSize);

            _allocatedParticles = tp;
        }
        else
        {
            // Out of memory, failed to resize some array
            if (particlesNew) _particles = particlesNew;
            if (quadsNew) _quads = quadsNew;
            if (indicesNew) _indices = indicesNew;

            CCLOG("Particle system: out of memory");
            return;
        }

        _totalParticles = tp;

        initIndices();
        if (Configuration::getInstance()->supportsShareableVAO())
        {
            setupVBOandVAO();
        }
        else
        {
            setupVBO();
        }

        // fixed http://www.cocos2d-x.org/issues/3990
        // Updates texture coords.
        updateTexCoords();
    }
    else
    {
        _totalParticles = tp;
    }

    // fixed issue #5762
    // reset the emission rate
    setEmissionRate(_totalParticles / _life);

    resetSystem();
}
Beispiel #19
0
		void ISimpleNode::setTextureRect(const Rects32& rect)
		{
			m_textureRect = rect;
			updateTexCoords();
		}