currently I'm optimizing my render calls by drawing multiple textures with one shader. The background textures who all share the same position are no problem. But now I want to draw some Textures with different positions with one shader. I think it isn't possible, because the textures don't have the same geometry.
But maybe there is a possible way to do this? I never worked with the geometry shader for example. For example, draw a 512x512 texture to position (100, 50), draw a 256x256 texture to position (500, 300)... , like in this picture: shader

  • \$\begingroup\$ I'm surely misunderstanding something, but can't you just attach different textures to the same shader and draw geometry as usual. \$\endgroup\$ Aug 14, 2017 at 18:56
  • \$\begingroup\$ but the textures are then all drawn at the same position. but I wanted to draw them to different positions each. For example, draw a 512x512 texture to position (100, 50), draw a 256x256 texture to position (500, 300).... \$\endgroup\$
    – mrdlink
    Aug 14, 2017 at 19:00
  • \$\begingroup\$ You should edit your question to say that you specifically want all that on a single quad, I had to guess that. \$\endgroup\$ Aug 14, 2017 at 19:26
  • \$\begingroup\$ Then, just use separate texture coords for each texture, and in your fragment shader check if tex coords are in [0;1] range before applying it. \$\endgroup\$ Aug 14, 2017 at 19:27
  • \$\begingroup\$ This would usually be done by putting the three textures in an atlas, and making a vertex buffer that contains all three quads. Then the whole trio can be drawn in one call with minimal extra computation or overdraw. It sounds like you want something different, but you haven't told us enough about your situation for us to understand why. \$\endgroup\$
    – DMGregory
    Aug 15, 2017 at 11:36

1 Answer 1


You can use the geometry shader to generate new vertices, yes. You can also have multiple textures is the same shader program.

geometry shader:

#version 330 core

layout (points) in;
layout (triangle_strip, max_vertices = 3) out;

void main()
    // geometry shader has only one vertex input here
    vec4 pos = gl_in[0].gl_Position;

    gl_Position = vec4(pos.x+0.1, pos.yzw);
    gl_Position = vec4(pos.x, pos.y+0.1, pos.zw);
    gl_Position = vec4(pos.x+0.1, pos.y+0.1, pos.zw);

But this is a very general answer, and there are tons of ways to do a thing.

  • \$\begingroup\$ Well it seems LibGDX doesn't support geometry shaders. \$\endgroup\$
    – mrdlink
    Aug 15, 2017 at 10:32
  • \$\begingroup\$ Then I would recommend using an OpenGL API that does ;) I use glfw for my projects ( glfw ), but I'm sure FreeGlut is also a possibility. Otherwise creating extra vertices in the shader programs won't really be an option, and you will have to call the shader program multiple times from your application. \$\endgroup\$
    – alexpanter
    Aug 15, 2017 at 15:45
  • \$\begingroup\$ Ok, I managed to get the shader program compile with a geometry shader. But the screen is now blank when I draw something \$\endgroup\$
    – mrdlink
    Aug 15, 2017 at 16:25
  • \$\begingroup\$ This I cannot help you with, as it could be due to several reasons. Check that all in/out shader variables match, that uniforms are being properly activated from within the application, that textures are loaded, that coordinates are properly normalized before they enter the rasterization process, etc. \$\endgroup\$
    – alexpanter
    Aug 17, 2017 at 10:01

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