Hello Guest

I don't know how to test depth when assigning z indices to shader uniforms

  • 1 Replies
  • 51 Views
Hello! I'm trying to render textures at different z indices, by assigning values through my shaders. I've tested that I am able to successfully set my uniform values prior to running my shader program. Here is my attempt at setting the z-index in my vertex shader:

Code: [Select]
#version 140

in vec2 position;
in vec2 textureCoords;

out vec4 color;
out vec2 uvCoords;

uniform float zIndex;
uniform vec4 matColor;
uniform mat4 projection;
uniform vec4 offset;
uniform vec2 pixelScale;
uniform vec2 screenPosition;

void main()
{
    color = matColor;
    gl_Position = projection * vec4((position * pixelScale) + screenPosition, 0, 1);
    gl_Position.z = zIndex;
    uvCoords = (textureCoords * offset.zw) + offset.xy;
}

I am fairly certain that this is indeed setting the z-index properly, since if I set it to an out-of-bounds value (e.g. 1.01f), it causes textures rendered at that value to disappear. This, and some google searches, makes me think that I'm missing some way of enabling depth-testing... Here is the code I'm using to (try to) enable depth testing:

Code: [Select]
        glEnable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_ALPHA_TEST);
        glDepthFunc(GL_LESS);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I've tried disabling GL_BLEND, as some search results suggested, but this has not done the trick. What am I missing here?

Thanks!

I figured out the problem--I was disabling depth testing elsewhere in my code.  :-[