I am texture mapping a pyramid and the end result is a solid colored pyramid instead of the pixels from the picture i use:
[ATTACH=CONFIG]1753[/ATTACH]
My code (see any errors?):
float pyramid[] = {
0.0f, 1.0f, 0.0f, /* top */ 0.5f, 0.7f, // texmap
-1.0f, -1.0f, 1.0f, /* left front */ 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, /* right front */ 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, /* left back */ 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, /* right back */ 0.0f, 1.0f,
};
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)3);
glEnableVertexAttribArray(1);
glGenTextures(1, &texture);
//glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex_data);
//glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(tex_data);
//glUniform1i(usampler, 0);
//rendering:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); // necessary because before glutmain I disabled it
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDrawElements(GL_TRIANGLES, 18, GL_UNSIGNED_INT, 0);