Archived

This topic is now archived and is closed to further replies.

Drawing padded texture correctly

This topic is 5040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I cannot draw my Image that is 506x480 that is padded as a texture to 512x512 correcly. glBegin(GL_QUADS); glTexCoord2f (0, 0); glVertex3f (-1.0f, -1.0f, 0); glTexCoord2f (1, 512/abmp.W); glVertex3f (1.0f, -1.0f, 0); glTexCoord2f (1, 512/abmp.H); glVertex3f (1.0f, 1.0f, 0); glTexCoord2f (0, 1); glVertex3f (-1.0f, 1.0f, 0); glEnd (); [edited by - aewarnick on February 22, 2004 10:09:41 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by aewarnick
I cannot draw my Image that is 506x480 that is padded as a texture to 512x512 correcly.

glBegin(GL_QUADS);
glTexCoord2f (0, 0); glVertex3f (-1.0f, -1.0f, 0);
glTexCoord2f (1, 512/abmp.W); glVertex3f (1.0f, -1.0f, 0);
glTexCoord2f (1, 512/abmp.H); glVertex3f (1.0f, 1.0f, 0);
glTexCoord2f (0, 1); glVertex3f (-1.0f, 1.0f, 0);
glEnd ();

[edited by - aewarnick on February 22, 2004 10:09:41 AM]


Hmmm... It looks like you are not calculating your tex coords correctly in the last three lines:

glTexCoord2f(1,512/abmp.W) should maybe be glTexCoord2f(512/abmp.W, 0)
glTexCoord2f(1, 512/abmp.H) should maybe be glTexCoord2f(512/abmp.W, 512/abmp.H)
glTexCoord2f(0, 1) should maybe be glTexCoord2f(0, 512/abmp.H)

That is, as long as your texture is padded on the right and on the bottom. If this is the case, you don''t ever want to use 1 as one of your coordinates, for this designates the right or bottom edge of a texture, which will include your padding area. 512/W and 512/H designate the edge of the non-padded area, and should be used in place of 1 instead. Also, make sure you don''t swap W and H coordinates, as you did in the second line (glTexCoord2f(1, 512/W)). You want this to be the width of the texture, in the "x" direction (first coordinate of the pair) rather than in the "y" direction (second coordinate).



Golem
Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller

Share this post


Link to post
Share on other sites
quote:
Original post by VertexNormal
you don't ever want to use 1 as one of your coordinates, for this designates the right or bottom edge of a texture, which will include your padding area.
You're right about not using 1, but in OpenGL, 1 is used for the right and top, not right and bottom.

Assuming that your image is padded on the right and on the top, your texture coordinates should look like this:
glTexCoord2f (0, 0); glVertex3f (-1.0f, -1.0f, 0);
glTexCoord2f ((float)abmp.W/512, 0); glVertex3f (1.0f, -1.0f, 0);
glTexCoord2f ((float)abmp.W/512, (float)abmp.H/512); glVertex3f (1.0f, 1.0f, 0);
glTexCoord2f (0, (float)abmp.H/512); glVertex3f (-1.0f, 1.0f, 0);

If it is padded on the right and bottom, they should be:
glTexCoord2f (0, (float)(512-abmp.H)/512); glVertex3f (-1.0f, -1.0f, 0);
glTexCoord2f ((float)abmp.W/512, (float)(512-abmp.H)/512); glVertex3f (1.0f, -1.0f, 0);
glTexCoord2f ((float)abmp.W/512, 1); glVertex3f (1.0f, 1.0f, 0);
glTexCoord2f (0, 1); glVertex3f (-1.0f, 1.0f, 0);

Share this post


Link to post
Share on other sites
I have another problem with the same thing but didn't want to post about it until I tried 1 million time to fix it. It is the creation of the bits for the gl texture.
Here is the code that creates the bits:
void SetglBits()
{
int paddingOffs= (512-W)*4;
this->glBits=new BYTE[512*4*512];
::memset(glBits, 255, 512*4*512);
BYTE* pSrc= (BYTE*)pBits; //RGB bitmap bits
BYTE* pDest= glBits; //ARGB texture bits

for(int y= 0; y < H; y++)
{
for(int x= 0; x < W; x++)
{
*pDest++= *(pSrc+2);
*pDest++= *(pSrc+1);
*pDest++= *pSrc;

pSrc+=3;
pDest++;
}
pDest+=paddingOffs;
}

This code works perfectly if the image is 512x512. But if the image is less than 512x512 it is cati-cornered, striped with black and white lines, but has the padding in the correct places which is the right of the image and the bottom. It is not split up anywhere else. That is what doesn't make sense.

Does the code above look like it would create a good texture for opengl?

[edited by - aewarnick on February 22, 2004 4:30:02 PM]

[edited by - aewarnick on February 22, 2004 4:30:28 PM]

[edited by - aewarnick on February 22, 2004 4:32:07 PM]

Share this post


Link to post
Share on other sites