0
votes

I have to do the following: "Split a texture into parts. You have one texture, and you should pass the texture coordinates az uniform parameters."

Specifically, I have 15 cubes, and I want to apply one texture to cover the upper side of them (to make one big picture)

The thing is, that I don't know what a uniform parameter is, and how can I use it to solve the problem. Has it maybe something to do with one of these methods? http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml

Here are the relevant parts of my code:

struct Vertex
{
    glm::vec3 p;
    glm::vec3 c;
    glm::vec2 t; // texture coordinates
};

-

    Vertex vert[] =
    { 

//          x,  y, z             R, G, B
        {glm::vec3(0, 0, 0), glm::vec3(1, 1, 1)}, //0
        {glm::vec3(1, 0, 0), glm::vec3(1, 1, 1)}, //1
        {glm::vec3(0, 1, 0), glm::vec3(1, 1, 1)}, //2

        {glm::vec3(1, 1, 0), glm::vec3(1, 1, 1)}, //3
        {glm::vec3(0, 0, 1), glm::vec3(1, 1, 1)}, //4

        {glm::vec3(1, 0, 1), glm::vec3(1, 1, 1)}, //5

        {glm::vec3(0, 1, 1), glm::vec3(1, 1, 1)}, //6

        {glm::vec3(1, 1, 1), glm::vec3(1, 1, 1)}, //7


    };

    GLushort indices[]=
    {       

        6,7,2,
        7,3,2,

        0,1,4,
        1,5,4,

        6,2,4,
        2,0,4,

        7,6,5,
        6,4,5,

        3,7,1,
        7,5,1,

        2,3,0,
        3,1,0,

    };

-

for(int i=0; i<15; i++)
{
    m_matWorld[i] = glm::translate<float>( (float)(i%4), (float)(i/4), 0.0f);
}

-

for(int i=0; i<15; i++)
        {
glUniformMatrix4fv( m_loc_world, 1, GL_FALSE, &(m_matWorld[i][0][0]) ); //az elso i azt jelenti, h hanyadik kockarol van szo a 15-bol
            glDrawElements( GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);

        }
1
A single (OpenGL) texture that contains several smaller texture that are used on multiple objects is called a texture atlas. You can search on that term to find lots of examples. - Ben Jackson
It seems like a solution, but it doesn't seem to be exactly what they want me to do :/ - Tyler Durden
"You have one texture, and you should pass the texture coordinates az uniform parameters." ... what? You should re-verify with your teacher that the texture coordinates are supposed to be a uniform and not an "attribute" or something else. Did he mean texture coordinate, or texture sampler? - Nicol Bolas

1 Answers

-1
votes

A uniform is a shader variable that is constant for all vertices/fragments. A better explanation can be found at http://www.opengl.org/wiki/Uniform_(GLSL) and the page you've linked above has all the ways you can set it