PDA

View Full Version : Problem in mapping Textures

Ediens
05-20-2014, 05:02 AM
Hello,

To apply an image as a texture to a rectangle formed by two triangles, I am following a tutorial in open.gl/textures
I am using freeglut for context creation and the only alterations I made to the original code were in respect to that.
I was expecting to obtain my whole image displayed on a rectangle, but instead I got this:
1305

I've checked the texture coordinates and I've come to the conclusion that other disposition would make more sense (commented in the code below) but the results are even worse.
I would appreciate some help in order to understand what I am doing wrong.

// Create a Vertex Buffer Object and copy the vertex data to it
GLuint vbo;
glGenBuffers(1, &vbo);

GLfloat vertices[] = {
// Position Color Texcoords
/*
-0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // Top-left
0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // Top-right
-0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, // Bottom-left
0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f // Bottom-righ
*/
-0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // Top-left
0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // Top-right
0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, // Bottom-right
-0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f // Bottom-left
};

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

// Create an element array
GLuint ebo;
glGenBuffers(1, &ebo);

GLuint elements[] = {
0, 1, 2,
2, 3, 0
};

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

Ediens
05-20-2014, 08:12 AM
The problem was not in the code but with the image used: I with other images it worked correctly.