Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Problem in mapping Textures

  1. #1
    Newbie Newbie
    Join Date
    May 2014
    Posts
    2

    Problem in mapping Textures

    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:
    Attachment 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.

    Code :
       // 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);

  2. #2
    Newbie Newbie
    Join Date
    May 2014
    Posts
    2
    The problem was not in the code but with the image used: I with other images it worked correctly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •