Advertisement

Lesson 06 : Problem when using u, v superior to 1.0f

Started by June 22, 2014 05:54 PM
0 comments, last by Cydriic 10 years, 5 months ago

Hi Everyone,

I'm having this problem with using U, Vs on my Textures, using the SOIL Library.

If I pass a u or v superior to 1.0f, the texture will only show fully at u:0.0f and v:0,0f scaled down correctly, but all the other positions will be bugged out and stretched...

When using Glaux, I didn't have that problem, but ever since switching to SOIL, does that.

Here is my code for loading my textures:

void LoadTextures()

{

//LOAD TEXTURES
//GRASS TEXTURE TEXTURE 0
texture[0] = SOIL_load_OGL_texture("Data/Grass00.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
if(texture[0] == 0)
return false;
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
//STONEWALL TEXTURE 1
texture[1] = SOIL_load_OGL_texture("Data/StoneWall00.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
if(texture[1] == 0)
return false;
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
//STONEWALLDOOR TEXTURE 2
texture[2] = SOIL_load_OGL_texture("Data/WoodStoneDoor00.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
if(texture[2] == 0)
return false;
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
return true;
}
And Here is my code for Drawing an Object:
void CHouse::Draw(GLuint texture)
{
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x1,m_y1,m_z2);
glTexCoord2f(m_u2,m_v1); glVertex3f(m_x2,m_y1,m_z2);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x2,m_y2,m_z2);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x2,m_y2,m_z2);
glTexCoord2f(m_u1,m_v2); glVertex3f(m_x1,m_y2,m_z2);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x1,m_y1,m_z2);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x1,m_y1,m_z1);
glTexCoord2f(m_u2,m_v1); glVertex3f(m_x2,m_y1,m_z1);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x2,m_y2,m_z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x2,m_y2,m_z1);
glTexCoord2f(m_u1,m_v2); glVertex3f(m_x1,m_y2,m_z1);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x1,m_y1,m_z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x2,m_y1,m_z2);
glTexCoord2f(m_u2,m_v1); glVertex3f(m_x2,m_y1,m_z1);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x2,m_y2,m_z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x2,m_y2,m_z1);
glTexCoord2f(m_u1,m_v2); glVertex3f(m_x2,m_y2,m_z2);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x2,m_y1,m_z2);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x1,m_y1,m_z2);
glTexCoord2f(m_u2,m_v1); glVertex3f(m_x1,m_y1,m_z1);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x1,m_y2,m_z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(m_u2,m_v2); glVertex3f(m_x1,m_y2,m_z1);
glTexCoord2f(m_u1,m_v2); glVertex3f(m_x1,m_y2,m_z2);
glTexCoord2f(m_u1,m_v1); glVertex3f(m_x1,m_y1,m_z2);
glEnd();
if(xtrans <= -(m_x1-0.2) && xtrans >= -(m_x2+0.2) && ztrans <= -(m_z1-0.2) && ztrans >= -(m_z2+0.2))
{
if(MoveForward)
{
xpos += 2*(float)sin(heading*piover180) * 0.05f;
zpos += 2*(float)cos(heading*piover180) * 0.05f;
}
if(MoveBackward)
{
xpos -= 2*(float)sin(heading*piover180) * 0.05f;
zpos -= 2*(float)cos(heading*piover180) * 0.05f;
}
}
m_Door->Draw(texture);
}

Thanks

This topic is closed to new replies.

Advertisement