Texture Mapping
I''m trying to manually texture map a quad. I set it''s upper left, upper right, lower left, and lower right corners to have coordinates of a texture. It works, but something wierd happens. My texture seems to be split in half and the sides switch. This might not makes sense, so I made picture showing what is happening. www.psidimension.com/problem.gif The left picture is the bitmap I give it, and the right is what openGL displays. Any ideas?
glBegin(GL_POLYGON);
glTexCoord2f(1,1); glVertex3f(m_ptUL.m_fX, m_ptUL.m_fY, m_ptUL.m_fZ);
glTexCoord2f(1,0.0); glVertex3f(m_ptLR.m_fX, m_ptUL.m_fY, m_ptUL.m_fZ);
glTexCoord2f(0.0,1); glVertex3f(m_ptLR.m_fX, m_ptLR.m_fY, m_ptUL.m_fZ);
glTexCoord2f(0.0,0.0); glVertex3f(m_ptUL.m_fX, m_ptLR.m_fY, m_ptUL.m_fZ);
glEnd();
glTexCoord2f(1,1); glVertex3f(m_ptUL.m_fX, m_ptUL.m_fY, m_ptUL.m_fZ);
glTexCoord2f(1,0.0); glVertex3f(m_ptLR.m_fX, m_ptUL.m_fY, m_ptUL.m_fZ);
glTexCoord2f(0.0,1); glVertex3f(m_ptLR.m_fX, m_ptLR.m_fY, m_ptUL.m_fZ);
glTexCoord2f(0.0,0.0); glVertex3f(m_ptUL.m_fX, m_ptLR.m_fY, m_ptUL.m_fZ);
glEnd();
This really doesn't help me, since i can't know wich of your vertices is the bottom left one, the top left one etc ...
so :
your bottom left vertex should have those tex coord : (0,0)
bottom right : (1,0)
top right : (1,1)
top left (0,1)
Is this what you do ?
[edited by - Sphax on July 6, 2003 5:37:38 AM]
so :
your bottom left vertex should have those tex coord : (0,0)
bottom right : (1,0)
top right : (1,1)
top left (0,1)
Is this what you do ?
[edited by - Sphax on July 6, 2003 5:37:38 AM]
It doesn''t matter. Post your texture loading code and your texture size, it must be a power of 2 if you aren''t using gluBuild2DMipMaps().
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
Sorry, heres the code I use to initiate the texture:
FILE *fp;
int nMemory;
PSI_BITMAP_IMAGE pbiTexture;
fp = fopen(szPath, "rb");
fread(&pbiTexture.bmfHeader, 1, 14, fp);
fread(&pbiTexture.bmiHeader, 1, 40, fp);
if (pbiTexture.bmiHeader.biSizeImage == 0)
{
nMemory = pbiTexture.bmiHeader.biWidth * pbiTexture.bmiHeader.biHeight * 4;
}
else
{
nMemory = pbiTexture.bmiHeader.biSizeImage;
}
pbiTexture.image_data= new GLubyte[nMemory];
fread(pbiTexture.image_data , 1, nMemory, fp);
fclose(fp);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &m_nTexture);
glBindTexture(GL_TEXTURE_2D, m_nTexture);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pbiTexture.bmiHeader.biWidth, pbiTexture.bmiHeader.biHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, pbiTexture.image_data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
delete[] pbiTexture.image_data;
FILE *fp;
int nMemory;
PSI_BITMAP_IMAGE pbiTexture;
fp = fopen(szPath, "rb");
fread(&pbiTexture.bmfHeader, 1, 14, fp);
fread(&pbiTexture.bmiHeader, 1, 40, fp);
if (pbiTexture.bmiHeader.biSizeImage == 0)
{
nMemory = pbiTexture.bmiHeader.biWidth * pbiTexture.bmiHeader.biHeight * 4;
}
else
{
nMemory = pbiTexture.bmiHeader.biSizeImage;
}
pbiTexture.image_data= new GLubyte[nMemory];
fread(pbiTexture.image_data , 1, nMemory, fp);
fclose(fp);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &m_nTexture);
glBindTexture(GL_TEXTURE_2D, m_nTexture);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pbiTexture.bmiHeader.biWidth, pbiTexture.bmiHeader.biHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, pbiTexture.image_data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
delete[] pbiTexture.image_data;
Long time since used opengl.
Looks like your texture coordinates are wrong and your texture is repeating?
Looks like your texture coordinates are wrong and your texture is repeating?
What texture size do you use?
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
right now its 47x43, but I could change it to a size with more round dimensions (45x45 or 50x50) if I need to.
Change it to 64x64
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement