Пример #1
0
void GraphicsBase::draw()
{
	if (indices.empty())
		return;

	if (isWhite_ == false)
	{
		glPushColor();
		glMultColor(r_, g_, b_, a_);
	}

	if (data)
	{
		oglEnable(GL_TEXTURE_2D);

        oglBindTexture(GL_TEXTURE_2D, data->id());

		oglEnableClientState(GL_VERTEX_ARRAY);
		oglEnableClientState(GL_TEXTURE_COORD_ARRAY);

		glVertexPointer(2, GL_FLOAT, 0, &vertices[0]);
		glTexCoordPointer(2, GL_FLOAT, 0, &texcoords[0]);

		oglDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

		oglDisableClientState(GL_VERTEX_ARRAY);
		oglDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}
	else
	{
		oglDisable(GL_TEXTURE_2D);

		oglEnableClientState(GL_VERTEX_ARRAY);

		glVertexPointer(2, GL_FLOAT, 0, &vertices[0]);

		oglDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

		oglDisableClientState(GL_VERTEX_ARRAY);
	}

	if (isWhite_ == false)
	{
		glPopColor();
	}
}
Пример #2
0
void GraphicsBase::draw(ShaderProgram *shp, VertexBuffer<unsigned short> *commonIndices)
{
	if (!commonIndices)
		commonIndices = &indices;
	if (commonIndices->empty())
		return;

	if (isWhite_ == false)
	{
		glPushColor();
		glMultColor(r_, g_, b_, a_);
	}

	if (data)
	{
        ShaderEngine::Engine->bindTexture(0,data->id());
        if (!shp) shp=ShaderProgram::stdTexture;
        shp->setData(ShaderProgram::DataVertex,ShaderProgram::DFLOAT,2,&vertices[0],vertices.size(),vertices.modified,&vertices.bufferCache);
        shp->setData(ShaderProgram::DataTexture,ShaderProgram::DFLOAT,2,&texcoords[0],texcoords.size(),texcoords.modified,&texcoords.bufferCache);
		shp->drawElements(mode, commonIndices->size(), ShaderProgram::DUSHORT, &((*commonIndices)[0]), commonIndices->modified, &commonIndices->bufferCache);
		vertices.modified = false;
		texcoords.modified = false;
		commonIndices->modified = false;
	}
	else
	{
        if (!shp) shp=ShaderProgram::stdBasic;
        shp->setData(ShaderProgram::DataVertex,ShaderProgram::DFLOAT,2,&vertices[0],vertices.size(),vertices.modified,&vertices.bufferCache);
		shp->drawElements(mode, commonIndices->size(), ShaderProgram::DUSHORT, &((*commonIndices)[0]), commonIndices->modified, &commonIndices->bufferCache);
		vertices.modified = false;
		commonIndices->modified = false;
	}

	if (isWhite_ == false)
	{
		glPopColor();
	}
}