Page 1 of 1

[not a bug] bug in COpenGLDriver::draw2DImage( ... )

Posted: Wed Nov 14, 2007 11:20 pm
by radubolovan
I saw the code in function:

Code: Select all

void COpenGLDriver::draw2DImage(const video::ITexture* texture,
				const core::position2d<s32>& pos,
				const core::rect<s32>& sourceRect,
				const core::rect<s32>* clipRect, SColor color,
				bool useAlphaChannelOfTexture)
And there are some lines of code:

Code: Select all

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));
Shouldn't be:

Code: Select all

glTexCoord2f(0, 0);
glVertex2f(GLfloat(poss.UpperLeftCorner.X), GLfloat(poss.UpperLeftCorner.Y));

glTexCoord2f(1, 0);
glVertex2f(GLfloat(poss.LowerRightCorner.X), GLfloat(poss.UpperLeftCorner.Y));

glTexCoord2f(1, 1);
glVertex2f(GLfloat(poss.LowerRightCorner.X), GLfloat(poss.LowerRightCorner.Y));

glTexCoord2f(0, 1);
glVertex2f(GLfloat(poss.UpperLeftCorner.X), GLfloat(poss.LowerRightCorner.Y));
???

With code <1>, if the tcoords is bigger then the rect of the texture, the texture doesn't grow/stretch, but multiplies itself into that rect :lol:
With code <2> it works just fine.

But I don't know if this is a bug or if that was the design of that function ...

Posted: Thu Nov 15, 2007 6:55 am
by hybrid
No, that is intended because you can specify a position and a source rectangle together with a clipping rectangle. All this may lead to a smaller part of the image being drawn, hence we need texture coords which are between 0 and 1.

Posted: Thu Nov 15, 2007 10:02 am
by radubolovan
I see!
And what should I do if I want to draw an image in a rectangle for example:
1) tex is 50x50 pixels
2) rectangle is 100x100 pixels
3) I want the texture to be drawn having 100x100 pixels.
I've tried that with that function and I saw nothing but my texture drawn having 50x50 pixels and the rest 'till 100x100 is transparent
(Sorry for my english language :( )

Posted: Fri Nov 16, 2007 1:24 am
by bitplane
use the other draw2dimage method, the one that takes a destination rect rather than a position-

Code: Select all

IVideoDriver:: draw2DImage (video::ITexture *texture, 
    const core::rect< s32 > &destRect, 
    const core::rect< s32 > &sourceRect, 
    const core::rect< s32 > *clipRect=0, 
    video::SColor *colors=0, 
    bool useAlphaChannelOfTexture=false)