I am learning OpenGL and while working with textures I came across a problem. When I try to render a texture I simply see a black box instead of the texture image. My code is as follows:
my loadTexture function:
/* Function to load Textures */
void loadTextures(char* filename)
{
stbi_set_flip_vertically_on_load(1);
unsigned int logoTexture;
unsigned char* logo_buffer = NULL;
int width = 400, height = 400, BPP;
glGenTextures(1, &logoTexture);
glBindTexture(GL_TEXTURE_2D, logoTexture);
logo_buffer = stbi_load(filename, &width, &height, &BPP, 0);
if(logo_buffer == NULL)
{
cout<<"\nError"<<endl;
}
else
{
cout<<"\nSuccess"<<endl;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, logo_buffer);
stbi_image_free(logo_buffer);
}
The display function where I am drawing the texture:
glClearColor(255.0, 250.0, 250.0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
glTexCoord2f(250, 250);
glVertex3f(250.0, 250.0, 0.0);
glTexCoord2f(650, 250);
glVertex3f(650.0, 250.0, 0.0);
glTexCoord2f(650, 550);
glVertex3f(650.0, 550.0, 0.0);
glTexCoord2f(250, 550);
glVertex3f(250.0, 550.0, 0.0);
glEnd();
I see a black rectangle but no texture on it. Help will be highly appreciated.