Exemple #1
0
  void DrawGLFont::setColor( int &i, string message )
  {
    i++;
    i++;
    stringstream ss;
    while( message[i] != ')' )
    {
      ss << message[i];
      i++;
    }

    int k = atoi( ss.str().c_str() );
    TColor color = retrieveColor( k );
    glColor3f( color.r, color.g, color.b );

  }
Exemple #2
0
  void DrawGLFont::drawString( string message )
  {
    // We don't want to mess with the original matrix
    glPushMatrix();

    string massage = "";
    int index = 0;
    int colorindex = 0;

    for(unsigned int i = 0; i < message.size(); i++ )
    {
      if( message[i] == '$' )
      {
        i++;
        colors[colorindex++].index = index;
      }
      massage += message[i];
      index++;
    }

    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, textureId );
    TColor color(0,0,0);
    if( colors.size() > 0 )
    {
      color = retrieveColor( 0 );
      glColor3f( color.r, color.g, color.b );
    }

    switch( alignment )
    {
      case align_right:
        drawAlignedRight( massage );
        break;
      case align_center:
        drawAlignedCenter( massage );
        break;
      default:
        drawAlignedLeft( massage );
        break;
    }

    glPopMatrix();

  }
Exemple #3
0
HRESULT CFont::DrawText(CDirectxScope& pDevice, ID3D10Device1* pD3Device, LPCTSTR szText, UINT uiLen, const RECT& rect, const D3DXCOLOR& color)
{
	SIZE size;
	size.cx = rect.right - rect.left;
	size.cy = rect.bottom - rect.top;

	const ID3D10ShaderResourceViewPtr* bitmapView = NULL;
	HRESULT hR = retrieveBitmap(szText, uiLen, size, pD3Device, bitmapView);
	if(FAILED(hR)) return hR;
	ASSERT(bitmapView);

	const ID3D10BufferPtr* pVertex = NULL;
	hR = retrieveVertex(rect, pDevice, pVertex);
	if(FAILED(hR)) return hR;
	ASSERT(pVertex);

	const ID3D10BufferPtr* pColor = NULL;
	hR = retrieveColor(color, pD3Device, pColor);
	if(FAILED(hR)) return hR;
	ASSERT(pColor);

	return pDevice.drawMonoBitmap(pD3Device, *bitmapView, *pVertex, *pColor);
}
Exemple #4
0
void ResourcePool::processMesh(string config)
{
	Branch meshBranch = TextTree::FileToRead(config);

	for (vector<Branch>::iterator branch = meshBranch.childBranches.begin(); branch != meshBranch.childBranches.end(); ++branch)
	{
		string meshName = branch->branchName;
		Color meshColor;

		enum MISC_VARIABLE
		{
			VAR_LENGTH,
			VAR_WIDTH,
			VAR_HEIGHT,
			VAR_RADIUS,
			VAR_INNER_RADIUS,
			VAR_OUTER_RADIUS,
			VAR_SLICES,
			VAR_STACKS,
			VAR_ANIM_TIME,
			MAX_VAR,
		};

		float meshVar[MAX_VAR];
		for (int i = 0; i < MAX_VAR; ++i)
		{
			meshVar[i] = 1.0f;
		}

		string meshVarNames[MAX_VAR] =
		{
			"Length",
			"Width",
			"Height",
			"Radius",
			"InnerRadius",
			"OuterRadius",
			"Slices",
			"Stacks",
		};

		// default 2D mesh variables
		int meshPosX = 0;
		int meshPosY = 0;

		int meshTextRow = 0;
		int meshTextCol = 0;

		// Spirte Animation
		int meshSpriteRow = 0;
		int meshSpriteCol = 0;

		// Tile sheet
		int meshTileRow = 0;
		int meshTileCol = 0;

		string directory = "";
		string meshType = "";

		unsigned textureID = 0;

		for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri)
		{
			Attribute tempAttri = *attri;
			string attriName = tempAttri.name;
			string attriValue = tempAttri.value;

			if (attriName == "ColorValue")
			{
				Vector3 tempColor;

				stringToVector(attriValue, tempColor);

				meshColor.Set(tempColor.x, tempColor.y, tempColor.z);
			}

			if (attriName == "ColorName")
			{
				meshColor = retrieveColor(attriValue);
			}

			else if (attriName == "Type")
			{
				meshType = attriValue;
			}

			else if (attriName == "Texture")
			{ 
				textureID = this->retrieveTexture(attriValue);
			}

			else if (attriName == "Directory")
			{
				directory = attriValue;
			}

			else if (attriName == "SpriteRow")
			{
				meshSpriteRow = stoi(attriValue);
			}

			else if (attriName == "SpriteCol")
			{
				meshSpriteCol = stoi(attriValue);
			}

			else if (attriName == "TextRow")
			{
				meshTextRow = stoi(attriValue);
			}

			else if (attriName == "TextCol")
			{
				meshTextCol = stoi(attriValue);
			}

			else if (attriName == "PosX")
			{
				meshPosX = stoi(attriValue);
			}

			else if (attriName == "PosY")
			{
				meshPosY = stoi(attriValue);
			}

			else if (attriName == "TileRow")
			{
				meshTileRow = stoi(attriValue);
			}

			else if (attriName == "TileCol")
			{
				meshTileCol = stoi(attriValue);
			}

			else
			{
				for (int k = 0; k < MAX_VAR; ++k)
				{
					if (attriName == meshVarNames[k])
					{
						meshVar[k] = stof(attriValue);
						break;
					}
				}
			}
		}

		// process data, generate mesh using meshbuilder
		Mesh* mesh = NULL;

		if (meshType == "Axis")
		{
			mesh = MeshBuilder::GenerateAxes(meshName, meshVar[VAR_LENGTH], meshVar[VAR_HEIGHT], meshVar[VAR_WIDTH]);
		}

		else if (meshType == "Ray")
		{
			mesh = MeshBuilder::GenerateRay(meshName, meshVar[VAR_LENGTH]);
		}

		else if (meshType == "Quad")
		{
			mesh = MeshBuilder::GenerateQuad(meshName, meshColor, meshVar[VAR_LENGTH], meshVar[VAR_WIDTH]);
		}

		else if (meshType == "Cube")
		{
			mesh = MeshBuilder::GenerateCube(meshName, meshColor, meshVar[VAR_LENGTH]);
		}

		else if (meshType == "Circle")
		{
			mesh = MeshBuilder::GenerateCircle(meshName, meshColor, (unsigned)meshVar[VAR_SLICES], meshVar[VAR_RADIUS]);
		}

		else if (meshType == "DebugQuad")
		{
			mesh = MeshBuilder::GenerateDebugQuad(meshName, meshColor, meshVar[VAR_LENGTH]);
		}

		else if (meshType == "DebugCircle")
		{
			mesh = MeshBuilder::GenerateDebugCircle(meshName, meshColor, (unsigned)meshVar[VAR_SLICES], meshVar[VAR_RADIUS]);
		}

		else if (meshType == "DebugCube")
		{
			mesh = MeshBuilder::GenerateDebugCube(meshName, meshColor, meshVar[VAR_LENGTH]);
		}

		else if (meshType == "Sphere")
		{
			mesh = MeshBuilder::GenerateSphere(meshName, meshColor, (unsigned)meshVar[VAR_STACKS], (unsigned)meshVar[VAR_SLICES], meshVar[VAR_RADIUS]);
		}

		else if (meshType == "Skyplane")
		{
			mesh = MeshBuilder::GenerateSkyPlane(meshName, meshColor, (unsigned)meshVar[VAR_SLICES], (float)meshVar[VAR_INNER_RADIUS], (float)meshVar[VAR_OUTER_RADIUS], (float)meshTileRow, (float)meshTileCol);
		}

		else if (meshType == "Terrain")
		{
			HEIGHTMAP tempHeightmap;
			tempHeightmap.name = meshName;
			mesh = MeshBuilder::GenerateTerrain(meshName, directory, tempHeightmap.heightMap);

			if (this->addHeightmap(tempHeightmap.name, tempHeightmap))
			{
				std::cout << "Successfully added new heightmap!" << std::endl;
			}
		}

		else if (meshType == "Obj")
		{
			mesh = MeshBuilder::GenerateOBJ(meshName, directory);
		}

		else if (meshType == "Text")
		{
			mesh = MeshBuilder::GenerateText(meshName, meshTextRow, meshTextCol);
		}

		else if (meshType == "2D")
		{
			mesh = MeshBuilder::Generate2DMesh(meshName, meshColor, (int)meshVar[VAR_WIDTH], (int)meshVar[VAR_HEIGHT]);
		}

		else if (meshType == "SpriteAnimation")
		{
			mesh = MeshBuilder::GenerateSpriteAnimation(meshName, meshSpriteRow, meshSpriteCol);

			SpriteAnimation *sa = dynamic_cast<SpriteAnimation*>(mesh);

			Branch tempBranch = *branch;
			// handle animations variables
			for (vector<Branch>::iterator childbranch = tempBranch.childBranches.begin(); childbranch != tempBranch.childBranches.end(); ++childbranch)
			{
				int id = 0;
				int startFrame = 0;
				int endFrame = 0;
				bool repeat = false;
				bool pause = false;
				float animationTime = 0.f;

				for (vector<Attribute>::iterator childAttri = childbranch->attributes.begin(); childAttri != childbranch->attributes.end(); ++childAttri)
				{
					Attribute tempAttri = *childAttri;
					string attriName = tempAttri.name;
					string attriValue = tempAttri.value;

					if (attriName == "ID")
					{
						id = stoi(attriValue);
					}

					else if (attriName == "StartFrame")
					{
						startFrame = stoi(attriValue);
					}

					else if (attriName == "EndFrame")
					{
						endFrame = stoi(attriValue);
					}

					else if (attriName == "Repeat")
					{
						stringToBool(attriValue, repeat);
					}

					else if (attriName == "Pause")
					{
						stringToBool(attriValue, pause);
					}

					else if (attriName == "AnimationTime")
					{
						animationTime = stof(attriValue);
					}
				}

				if (sa)
				{
					Animation* anime = new Animation();
					anime->Set(id, startFrame, endFrame, repeat, pause, animationTime);
					sa->animations.push_back(anime);
				}
			}

			//sort (sa->animations.begin(), sa->animations.end());
		}

		else if (meshType == "TileSheet")
		{
			mesh = MeshBuilder::GenerateTileSheet(meshName, meshTileRow, meshTileCol);
		}

		// push back mesh
		if (mesh != NULL)
		{
			if (textureID != 0)
			{
				mesh->textureID = textureID;
			}

			if (addMesh(branch->branchName, mesh))
			{
				std::cout << "Successfully added new mesh!" << std::endl;
			}
		}
	}
}
Exemple #5
0
void AssimpScene::setupVAOs(
    OpenGLFunctions & gl
,   const aiScene * scene)
{
    assert(scene);

    // For each mesh
    for (unsigned int m = 0; m < scene->mNumMeshes; ++m)
    {
        const aiMesh * mesh = scene->mMeshes[m];

        // create array with faces
        // have to convert from Assimp format to array
        std::vector<unsigned int> indices(mesh->mNumFaces * 3);

        for (unsigned int f = 0, i = 0; f < mesh->mNumFaces; ++f, i += 3)
        {
            const aiFace * face = &mesh->mFaces[f];
            indices[i + 0] = face->mIndices[0];
            indices[i + 1] = face->mIndices[1];
            indices[i + 2] = face->mIndices[2];
        }

        AssimpMesh * amesh = new AssimpMesh();
        amesh->faces = mesh->mNumFaces;

        amesh->vao.create();
        amesh->vao.bind();

        // create buffers

        amesh->indices = new QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);
        amesh->indices->create();
        amesh->indices->setUsagePattern(QOpenGLBuffer::StaticDraw);
        amesh->indices->bind();
        amesh->indices->allocate(indices.data(), indices.size() * sizeof(unsigned int));

        if (mesh->HasPositions())
        {
            amesh->vertices = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
            amesh->vertices->create();
            amesh->vertices->setUsagePattern(QOpenGLBuffer::StaticDraw);
            amesh->vertices->bind();
            amesh->vertices->allocate(mesh->mVertices, mesh->mNumVertices * sizeof(float) * 3);

            gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, nullptr);
            gl.glEnableVertexAttribArray(0);
        }
        if (mesh->HasNormals())
        {
            amesh->normals = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
            amesh->normals->create();
            amesh->normals->setUsagePattern(QOpenGLBuffer::StaticDraw);
            amesh->normals->bind();
            amesh->normals->allocate(mesh->mNormals, mesh->mNumVertices * sizeof(float) * 3);

            gl.glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, sizeof(float) * 3, nullptr);
            gl.glEnableVertexAttribArray(1);
        }
        if (mesh->HasTextureCoords(0))
        {
            float * texcs = new float[2 * mesh->mNumVertices];
            for (unsigned int t = 0; t < mesh->mNumVertices; ++t)
            {
                texcs[t * 2 + 0] = mesh->mTextureCoords[0][t].x;
                texcs[t * 2 + 1] = mesh->mTextureCoords[0][t].y;
            }

            amesh->texcs= new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
            amesh->texcs->create();
            amesh->texcs->setUsagePattern(QOpenGLBuffer::StaticDraw);
            amesh->texcs->bind();
            amesh->texcs->allocate(texcs, mesh->mNumVertices * sizeof(float) * 2);

            gl.glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, nullptr);
            gl.glEnableVertexAttribArray(2);
        }

        amesh->vao.release();

        AssimpMaterial & material(amesh->material);

        // create material uniform buffer
        aiMaterial * mtl = scene->mMaterials[mesh->mMaterialIndex];

        // support single texture on diffuse channel only for now... TODO

        aiString path;
        if (AI_SUCCESS == mtl->GetTexture(aiTextureType_DIFFUSE, 0, &path))
        {
            material.texture = FileAssociatedTexture::getOrCreate2D(QString(path.C_Str()), gl);
            material.texCount = 1;
        }
        else
            material.texCount = 0;

        retrieveColor(mtl, AI_MATKEY_COLOR_DIFFUSE, material.diffuse, 0.8f, 0.8f, 0.8f, 1.0f);
        retrieveColor(mtl, AI_MATKEY_COLOR_AMBIENT, material.ambient, 0.2f, 0.2f, 0.2f, 1.0f);
        retrieveColor(mtl, AI_MATKEY_COLOR_SPECULAR, material.specular, 0.0f, 0.0f, 0.0f, 1.0f);
        retrieveColor(mtl, AI_MATKEY_COLOR_EMISSIVE, material.emissive, 0.0f, 0.0f, 0.0f, 1.0f);

        material.shininess = 0.f;
        unsigned int max;
        aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &material.shininess, &max);

        m_meshes.push_back(amesh);
    }
}
Exemple #6
0
 void ImageSource::retrieve(cv::Mat &color, cv::Mat &gray) {
     retrieveColor(color);
     cv::cvtColor(color, gray, CV_RGB2GRAY);
 }