0
\$\begingroup\$

How to make textures fill all area as it is specified? I'm getting small gaps if the texture is smaller than area example: gl_quads setup like these:

-1f, 1f, 0, 
-0.98f, 1f, 0, 
-0.98f, -1f, 0, 
-1f, -1f, 0 

I get this: https://i.stack.imgur.com/kWJnh.png

Red one's a texture, black is background, ignore it. Texture is imported by slick loader.

Texture itself: https://i.stack.imgur.com/8x7ZH.png (in case someone will think it has gaps)

Do I need to use a glTexParameter somehow on it? Added a rendering code down below:

//VertexArray initialization, vertexSize is 3, amountOfVertices is 8
private void initVertexArrays() {
    borderVertex = BufferUtils.createFloatBuffer(vertexSize
            * amountOfVertices);
    borderVertex.put(new float[] { -1f, 1f, 0, -0.98f, 1f, 0, -0.98f, -1f,
            0, -1f, -1f, 0 });
    borderVertex.flip();

    borderTextureVertex = BufferUtils.createFloatBuffer(vertexSize
            * amountOfVertices);
    borderTextureVertex.put(new float[] { -1f, 1f, 0, -0.98f, 1f, 0,
            -0.98f, -1f, 0, -1f, -1f, 0 });
    borderTextureVertex.flip();

    amountOfArrays = 2;
}
//VertexBufferObject initialization
private void initVBO() {
    borderVertexHandle = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, borderVertexHandle);
    glBufferData(GL_ARRAY_BUFFER, borderVertex, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    borderTextureHandle = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, borderTextureHandle);
    glBufferData(GL_ARRAY_BUFFER, borderTextureVertex, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
//Texture loading with slick
private void setupTextures(){
    borderTexture = TextureDecoder.getTextureAt(borderTextureLocation,
            "PNG");
}
//Rendering part
public void draw() {
    borderTexture.bind();
    glBindBuffer(GL_ARRAY_BUFFER, borderVertexHandle);
    glVertexPointer(vertexSize, GL_FLOAT, 0, 0L);

    glBindBuffer(GL_ARRAY_BUFFER, borderTextureHandle);
    glTexCoordPointer(vertexSize, GL_FLOAT, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glDrawArrays(GL_QUADS, 0, amountOfVertices * amountOfArrays);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
}
\$\endgroup\$
3
  • \$\begingroup\$ How do you render your background? A somewhat full example may help to explain your problem. \$\endgroup\$
    – rioki
    Apr 2, 2014 at 13:26
  • \$\begingroup\$ I'm not rendering it just for now, it's a simple display window. \$\endgroup\$
    – Vanguard
    Apr 2, 2014 at 13:26
  • \$\begingroup\$ Added rendering code for this part, just in case \$\endgroup\$
    – Vanguard
    Apr 2, 2014 at 13:32

1 Answer 1

0
\$\begingroup\$

Firs things first, The texture coordinates are probably not that what you want. You probably want 0, 0, 0, 1, 1, 0, 1, 1 with a size of 2.

Further you are using glVertexPointer and glTexCoordPointer with the value vertexSize, it is unclear what that is. It is probably 3 or the code would not render. Ensure that this is the number of values per vertex.

The remainder of the code looks sort of ok.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .