Пример #1
0
Mesh* HUDImageRenderer::createMesh(const G3MRenderContext* rc) {
  _creatingMesh = false;

  if (_mesh != NULL) {
    delete _mesh;
    _mesh = NULL;
  }

  const IStringUtils* su = IStringUtils::instance();
  const std::string textureName = "HUDImageRenderer" + su->toString(_instanceID) + "/" + su->toString(_changeCounter++);

  const TextureIDReference* texId = rc->getTexturesHandler()->getTextureIDReference(_image,
                                                                       GLFormat::rgba(),
                                                                       textureName,
                                                                       false);
  
  delete _image;
  _image = NULL;

  if (texId == NULL) {
    rc->getLogger()->logError("Can't upload texture to GPU");
    return NULL;
  }


  const Camera* camera = rc->getCurrentCamera();

  const double halfWidth  = camera->getWidth()  / 2.0;
  const double halfHeight = camera->getHeight() / 2.0;

  FloatBufferBuilderFromCartesian3D vertices = FloatBufferBuilderFromCartesian3D::builderWithoutCenter();
  vertices.add(-halfWidth,  halfHeight, 0);
  vertices.add(-halfWidth, -halfHeight, 0);
  vertices.add( halfWidth,  halfHeight, 0);
  vertices.add( halfWidth, -halfHeight, 0);

  DirectMesh* mesh = new DirectMesh(GLPrimitive::triangleStrip(),
                                    true,
                                    vertices.getCenter(),
                                    vertices.create(),
                                    1,
                                    1);

  FloatBufferBuilderFromCartesian2D texCoords;
  texCoords.add(0, 0);
  texCoords.add(0, 1);
  texCoords.add(1, 0);
  texCoords.add(1, 1);

  TextureMapping* textureMapping = new SimpleTextureMapping(texId,
                                                            texCoords.create(),
                                                            true,
                                                            true);

  return new TexturedMesh(mesh, true,
                          textureMapping, true,
                          true);
}
Пример #2
0
Mesh* HUDRenderer::ShownImage::createMesh(const G3MRenderContext* rc) const {
  //TEXTURED
#ifdef C_CODE
  const TextureIDReference* texId = NULL;
#endif
#ifdef JAVA_CODE
  TextureIDReference texId = null;
#endif

  _factory = rc->getFactory();

  texId = rc->getTexturesHandler()->getTextureIDReference(_image,
                                                   GLFormat::rgba(),
                                                   _name,
                                                   false);

  if (texId == NULL) {
    rc->getLogger()->logError("Can't upload texture to GPU");
    return NULL;
  }

  const int viewportWidth  = rc->getCurrentCamera()->getWidth();
  const int viewportHeight = rc->getCurrentCamera()->getHeight();

  const Vector3D halfViewportAndPosition(viewportWidth  / 2 - _position._x,
                                         viewportHeight / 2 - _position._y,
                                         0);

  const double w = _size._x;
  const double h = _size._y;

  FloatBufferBuilderFromCartesian3D vertices = FloatBufferBuilderFromCartesian3D::builderWithoutCenter();
  vertices.add(Vector3D(0, h, 0).sub(halfViewportAndPosition));
  vertices.add(Vector3D(0, 0, 0).sub(halfViewportAndPosition));
  vertices.add(Vector3D(w, h, 0).sub(halfViewportAndPosition));
  vertices.add(Vector3D(w, 0, 0).sub(halfViewportAndPosition));

  FloatBufferBuilderFromCartesian2D texCoords;
  texCoords.add(0, 0);
  texCoords.add(0, 1);
  texCoords.add(1, 0);
  texCoords.add(1, 1);

  DirectMesh *im = new DirectMesh(GLPrimitive::triangleStrip(),
                                  true,
                                  vertices.getCenter(),
                                  vertices.create(),
                                  1,
                                  1);

  TextureMapping* texMap = new SimpleTextureMapping(texId,
                                                    texCoords.create(),
                                                    true,
                                                    false);

  return new TexturedMesh(im, true, texMap, true, true);
}
Пример #3
0
bool BusyQuadRenderer::initMesh(const G3MRenderContext* rc) {
  //TEXTURED
#ifdef C_CODE
  const IGLTextureId* texId = NULL;
#endif
#ifdef JAVA_CODE
  IGLTextureId texId = null;
#endif
//  IImage* image = rc->getFactory()->createImageFromFileName(_textureFilename);

  texId = rc->getTexturesHandler()->getGLTextureId(_image,
                                                   GLFormat::rgba(),
                                                   "BusyQuadRenderer-Texture",
                                                   false);

  rc->getFactory()->deleteImage(_image);
  _image = NULL;

  if (texId == NULL) {
    rc->getLogger()->logError("Can't upload texture to GPU");
    return false;
  }

  const double halfWidth = _size._x / 2;
  const double hadfHeight = _size._y / 2;
  FloatBufferBuilderFromCartesian3D vertices(CenterStrategy::noCenter(), Vector3D::zero());
  vertices.add(-halfWidth, +hadfHeight, 0);
  vertices.add(-halfWidth, -hadfHeight, 0);
  vertices.add(+halfWidth, +hadfHeight, 0);
  vertices.add(+halfWidth, -hadfHeight, 0);

  FloatBufferBuilderFromCartesian2D texCoords;
  texCoords.add(0, 0);
  texCoords.add(0, 1);
  texCoords.add(1, 0);
  texCoords.add(1, 1);

  DirectMesh *im = new DirectMesh(GLPrimitive::triangleStrip(),
                                  true,
                                  vertices.getCenter(),
                                  vertices.create(),
                                  1,
                                  1);

  TextureMapping* texMap = new SimpleTextureMapping(texId,
                                                    texCoords.create(),
                                                    true,
                                                    false);

  _quadMesh = new TexturedMesh(im, true, texMap, true, true);

  return true;
}
Пример #4
0
IFloatBuffer* GL::getBillboardTexCoord() {
//  if (_verbose) {
//    ILogger::instance()->logInfo("GL::getBillboardTexCoord()");
//  }

  if (_billboardTexCoord == NULL) {
    FloatBufferBuilderFromCartesian2D texCoor;
    texCoor.add(1,1);
    texCoor.add(1,0);
    texCoor.add(0,1);
    texCoor.add(0,0);
    _billboardTexCoord = texCoor.create();
  }

  return _billboardTexCoord;
}