コード例 #1
0
ファイル: Graphics.cpp プロジェクト: jjiezheng/mutiny
void Graphics::drawMeshNow(Mesh* mesh, Matrix4x4 matrix, int materialIndex)
{
  Material* material;

  material = Application::getInternal()->currentMaterial;
  material->setMatrix("in_Model", matrix);

  drawMeshNow(mesh, materialIndex);
}
コード例 #2
0
ファイル: Graphics.cpp プロジェクト: citruslee/mutiny
void Graphics::drawTextureBatch(std::vector<Rect> rects, arc<Texture> texture, std::vector<Rect> sourceRects, arc<Material> material)
{
  arc<RenderTexture> currentRenderTexture;

  std::vector<Vector3> vertices;
  std::vector<Vector2> uv;
  std::vector<Color> colors;
  std::vector<int> triangles;

  if(material.get() == NULL)
  {
    // TODO: Use a unique material with MVP set
    material = Graphics::defaultMaterial;
    //material = Material::guiMaterial;
    material->setMatrix("in_Projection", Matrix4x4::ortho(0, Screen::getWidth(), Screen::getHeight(), 0, -1, 1));
    material->setMatrix("in_View", Matrix4x4::getIdentity());
    material->setMatrix("in_Model", Matrix4x4::getIdentity());
  }

  if(texture.get() == NULL)
  {
    Debug::logWarning("Texture is null");
    return;
  }

  for(int i = 0; i < rects.size(); i++)
  {
    float x = (float)rects.at(i).x;
    float y = (float)rects.at(i).y;
    float xw = (float)rects.at(i).x + (float)rects.at(i).width;
    float yh = (float)rects.at(i).y + (float)rects.at(i).height;

    triangles.push_back((i*6) + 0);
    triangles.push_back((i*6) + 1);
    triangles.push_back((i*6) + 2);
    triangles.push_back((i*6) + 3);
    triangles.push_back((i*6) + 4);
    triangles.push_back((i*6) + 5);

    vertices.push_back(Vector3(x, y, 0));
    vertices.push_back(Vector3(x, yh, 0));
    vertices.push_back(Vector3(xw, yh));
    vertices.push_back(Vector3(xw, yh));
    vertices.push_back(Vector3(xw, y));
    vertices.push_back(Vector3(x, y));

    uv.push_back(Vector2(sourceRects.at(i).x, sourceRects.at(i).y));
    uv.push_back(Vector2(sourceRects.at(i).x, sourceRects.at(i).height));
    uv.push_back(Vector2(sourceRects.at(i).width, sourceRects.at(i).height));
    uv.push_back(Vector2(sourceRects.at(i).width, sourceRects.at(i).height));
    uv.push_back(Vector2(sourceRects.at(i).width, sourceRects.at(i).y));
    uv.push_back(Vector2(sourceRects.at(i).x, sourceRects.at(i).y));
  }

  arc<Mesh> mesh = arc<Mesh>::alloc();
  mesh->setVertices(vertices);
  mesh->setUv(uv);
  //mesh.setColors(colors);

  mesh->setTriangles(triangles, 0);
  material->setMainTexture(texture);

  currentRenderTexture = RenderTexture::getActive();
  RenderTexture::setActive(Graphics::renderTarget);

  glDisable(GL_DEPTH_TEST);
  glCullFace(GL_BACK);

  for(int i = 0; i < material->getPassCount(); i++)
  {
    material->setPass(i, material);
    // HACK: A matrix is required to be passed into drawMeshNow.
    drawMeshNow(mesh, material->getMatrix("in_Model"), 0);
  }

  glCullFace(GL_FRONT);
  glEnable(GL_DEPTH_TEST);

  RenderTexture::setActive(currentRenderTexture);
}
コード例 #3
0
ファイル: Graphics.cpp プロジェクト: jjiezheng/mutiny
// if material is null, a default material with internal-GUITexture.shader is used.
void Graphics::drawTexture(Rect rect, Texture* texture, Rect sourceRect, Material* material)
{
  RenderTexture* currentRenderTexture = NULL;

  std::vector<Vector3> vertices;
  std::vector<Vector2> uv;
  std::vector<Color> colors;
  std::vector<int> triangles;

  float x = (float)rect.x;
  float y = (float)rect.y;
  float xw = (float)rect.x + (float)rect.width;
  float yh = (float)rect.y + (float)rect.height;

  if(material == NULL)
  {
    // TODO: Use a unique material with MVP set
    material = Application::getInternal()->graphicsDefaultMaterial;
    material->setMatrix("in_Projection", Matrix4x4::ortho(0, Screen::getWidth(), Screen::getHeight(), 0, -1, 1));
    material->setMatrix("in_View", Matrix4x4::getIdentity());
    material->setMatrix("in_Model", Matrix4x4::getIdentity());
  }

  if(texture == NULL)
  {
    Debug::logWarning("Texture is null");
    return;
  }

  triangles.push_back(0);
  triangles.push_back(1);
  triangles.push_back(2);
  triangles.push_back(3);
  triangles.push_back(4);
  triangles.push_back(5);

  vertices.push_back(Vector3(x, y, 0));
  vertices.push_back(Vector3(x, yh, 0));
  vertices.push_back(Vector3(xw, yh));
  vertices.push_back(Vector3(xw, yh));
  vertices.push_back(Vector3(xw, y));
  vertices.push_back(Vector3(x, y));

  uv.push_back(Vector2(sourceRect.x, sourceRect.y));
  uv.push_back(Vector2(sourceRect.x, sourceRect.height));
  uv.push_back(Vector2(sourceRect.width, sourceRect.height));
  uv.push_back(Vector2(sourceRect.width, sourceRect.height));
  uv.push_back(Vector2(sourceRect.width, sourceRect.y));
  uv.push_back(Vector2(sourceRect.x, sourceRect.y));

  Mesh mesh;
  mesh.setVertices(vertices);
  mesh.setUv(uv);
  //mesh.setColors(colors);

  mesh.setTriangles(triangles, 0);

  material->setMainTexture(texture);
  material->setPass(0);

  currentRenderTexture = RenderTexture::getActive();
  RenderTexture::setActive(Application::getInternal()->graphicsRenderTarget);

  glDisable(GL_DEPTH_TEST);
  glCullFace(GL_BACK);
  drawMeshNow(&mesh, 0);
  glCullFace(GL_FRONT);
  glEnable(GL_DEPTH_TEST);

  RenderTexture::setActive(currentRenderTexture);
}