I have tried to draw a part of a picture, but instead repeating the part of the picture, it has stretched the picture and it looked ugly.
How can I repeat picture instead of streching it.
The relevant part of the code:
glEnable (GL_BLEND);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor3f(1.f, 1.f, 1.f);
glBindTexture(GL_TEXTURE_2D, texture[image]);
int repeat = (x2-x)/73;
glBegin(GL_QUADS); //create polygon
glTexCoord2f((part/3.f), 0.0f);glVertex2d(x, y);
glTexCoord2f(((part+1.f)/3.f)+repeat, 0.0f);glVertex2d(x2, y);
glTexCoord2f(((part+1.f)/3.f)+repeat, 1.0f);glVertex2d(x2, y2);
glTexCoord2f((part/3.f), 1.0f);glVertex2d(x, y2);
glEnd();
and the load of the texture:
texture[fNum] = SOIL_load_OGL_texture
(
fName.c_str(),
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
This is the fixed code after your help, but now there is another problem, I want to repeat only a specific part of the image. Thank a lot!
fixed: now I maked my own code to repeat that and it works:
float nx=x, nx2 = x+length;
float ny2 = y2+25.f;
if((x2-x)/length > 1)
{
while(nx2 < x2)
{
if(nx2+length < x2)
{
glBegin(GL_QUADS); //create polygon
glTexCoord2f((part/3.f), 0.0f);glVertex2d(nx, y);
glTexCoord2f(((part+1.f)/3.f), 0.0f);glVertex2d(nx2, y);
glTexCoord2f(((part+1.f)/3.f), 1.0f);glVertex2d(nx2, ny2);
glTexCoord2f((part/3.f), 1.0f);glVertex2d(nx, ny2);
glEnd();
nx = nx2;
nx2 += length;
}
else
{
glBegin(GL_QUADS); //create polygon
glTexCoord2f((part/3.f), 0.0f);glVertex2d(nx, y);
glTexCoord2f(((part+1.f)/3.f), 0.0f);glVertex2d(x2, y);
glTexCoord2f(((part+1.f)/3.f), 1.0f);glVertex2d(x2, ny2);
glTexCoord2f((part/3.f), 1.0f);glVertex2d(nx, ny2);
glEnd();
break;
}
}
}
else
{
glBegin(GL_QUADS); //create polygon
glTexCoord2f((part/3.f), 0.0f);glVertex2d(x, y);
glTexCoord2f(((part+1.f)/3.f), 0.0f);glVertex2d(x2, y);
glTexCoord2f(((part+1.f)/3.f), 1.0f);glVertex2d(x2, ny2);
glTexCoord2f((part/3.f), 1.0f);glVertex2d(x, ny2);
glEnd();
}