Page 1 of 1

draw2DImage - without clipping

Posted: Tue Feb 25, 2014 3:23 am
by AlfAlien
draw2DImage() in COpenGLDriver class will render image relative to screen coordinates (so even if camera moves the image will kind of move with it). I want the image to be rendered only at it's specific position (call it absolute position) - so when camera moves the image will scroll out and then disappear. I tried to modify draw2DImage() method. It compiles but it renders nothing.

Code: Select all

 
void COpenGLDriver::draw2DImageAbsoluteCoordinates(const video::ITexture* texture, const core::position2d<s32>& pos)
{
        //1st -> must specify coordinates for vertices and UVs
    const core::dimension2d<u32>& textureSize = texture->getOriginalSize();
    const core::rect<f32> tcoords(0, 1, 1, 0); // rect has only upper left and lower right corners that we must specify
    const core::rect<s32> poss(pos.X, pos.Y, pos.X + textureSize.Width, pos.Y + textureSize.Height); // texture position
        
        // all the code below wasn't modified
    disableTextures(1);
    if (!setActiveTexture(0, texture))
        return;
 
    glBegin (GL_QUADS);
 
    glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
    glVertex2f(GLfloat(poss.UpperLeftCorner.X), GLfloat(poss.UpperLeftCorner.Y));
 
    glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
    glVertex2f(GLfloat(poss.LowerRightCorner.X), GLfloat(poss.UpperLeftCorner.Y));
 
    glTexCoord2f(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
    glVertex2f(GLfloat(poss.LowerRightCorner.X), GLfloat(poss.LowerRightCorner.Y));
 
    glTexCoord2f(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
    glVertex2f(GLfloat(poss.UpperLeftCorner.X), GLfloat(poss.LowerRightCorner.Y));
 
    glEnd();
}
 
Please, help!

Re: draw2DImage - without clipping

Posted: Tue Feb 25, 2014 6:46 pm
by horvatha4
Maybe this is a better solution/class for you: irr::scene::IBillboardSceneNode

Re: draw2DImage - without clipping

Posted: Wed Feb 26, 2014 6:13 am
by AlfAlien
Yes, I already use it, but this seems to be the most straightforward approach.