Original Post
Hello im writting a small opengl engine and am having lots of problems with texturing. Up close the texture looks kinda distorted and with random colors. I tried everything and nothing worked. Oh yeah I draw a cube and the texture got the same color as the cube but i don't want that.
Gl enable
This is how I load my texture I use freeimage for this
And finally the render function
Now this displays the texture like this:

The actual texture is:
Gl enable
glClearColor (0.0,0.0,0.0,1.0);
//set default viewport
glViewport(0, 0, (int)w, (int)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (float)640/(float)480, 1, 1000);//set default values for projection
//Default smooth shading
glShadeModel(GL_SMOOTH);
//Enable Z buffering
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
This is how I load my texture I use freeimage for this
FREE_IMAGE_FORMAT format = FreeImage_GetFileType(path,0);
FIBITMAP* image = FreeImage_Load(format, path, 0);
if (!image) return false;
FIBITMAP* temp = image;
image = FreeImage_ConvertTo32Bits(temp);
FreeImage_Unload(temp);
int w = FreeImage_GetWidth(image);
int h = FreeImage_GetHeight(image);
BYTE *bits = (BYTE*)malloc( w * h * 3 );
BYTE *pixels = (BYTE*)FreeImage_GetBits(image);
//Free image stores data in BGR format so swap pixels
for(int pix=0; pix < w * h; pix++){
bits[pix*3+2]=pixels[pix*3+0];
bits[pix*3+1]=pixels[pix*3+1];
bits[pix*3+0]=pixels[pix*3+2];
}
GLuint textureID[1];
glGenTextures(1, &textureID[0]);
glBindTexture(GL_TEXTURE_2D, textureID[0]);
// Tried GL_MODULATE and GL_REPLACE none worked like i wanted them to
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
//Generate the texture with mipmaps
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)bits );
free(bits);
free(pixels);
GLenum error = glGetError();
if(error)
return (double)error;
else
return (double)textureID[0];
And finally the render function
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(xf, yf, zf, xt, yt, zt, xu, yu, zu);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (GLuint)textid);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0f);glVertex3f(_x1, _z1, _y1);
glTexCoord2f(0.0f,1.0f * vrepeat);glVertex3f(_x1, _z2, _y2);
glTexCoord2f(1.0f * hrepeat,1.0f * vrepeat);glVertex3f(_x2, _z2, _y2);
glTexCoord2f(1.0f * hrepeat,0.0f);glVertex3f(_x2, _z1, _y1);
glEnd();
glDisable(GL_TEXTURE_2D);
SwapBuffers( ehDC );
Now this displays the texture like this:

The actual texture is: