0
\$\begingroup\$

I'm porting my Direct3D-based engine to OpenGL and I'm using geometry shaders for rendering text characters (basically, textured billboards).

D3D version works fine, but in OpenGL mode it gives only a flickering point right in the center of the screen.

It seems that somehow the geometry shader stage is not enabled (in AMD GPUPerfStudio the box, representing GS stage, is grayed-out).

I tripple-checked the OpenGL back-end and the shader code but couldn't find any mistakes. Maybe, I'm missing something.

Below is the source code of the relevant shaders:

Vertex shader:

in vec4 in_xy_wh;
in vec4 in_tl_br;   // UVs for top left and bottom right corners
out vec4 v_xy_wh;
out vec4 v_tl_br;
void main()
{
    v_xy_wh = in_xy_wh;
    v_tl_br = in_tl_br;
}

Geometry shader:

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

in vec4 v_xy_wh[];
in vec4 v_tl_br[];  // UVs for top left and bottom right corners

out vec2 v_uv;

void main()
{
    vec2    pos = v_xy_wh[0].xy;
    float   width = v_xy_wh[0].z;
    float   height = v_xy_wh[0].w;

    vec2    tl = v_tl_br[0].xy;
    vec2    br = v_tl_br[0].zw;

    gl_Position = vec4( pos.x, pos.y, 0.0f, 1.0f );
    v_uv = vec2( tl.x, tl.y );
    EmitVertex();

    gl_Position = vec4( pos.x + width, pos.y, 0.0f, 1.0f );
    v_uv = vec2( br.x, tl.y );
    EmitVertex();

    gl_Position = vec4( pos.x, pos.y - height, 0.0f, 1.0f );
    v_uv = vec2( tl.x, br.y );
    EmitVertex();

    gl_Position = vec4( pos.x + width, pos.y - height, 0.0f, 1.0f );
    v_uv = vec2( br.x, br.y );
    EmitVertex();

    EndPrimitive();
}

Fragment shader:

in vec2 v_uv;
out vec4 v_color;

uniform sampler2D   s_font;

void main()
{
    vec4 color = texture( s_font, v_uv ).rgba;
    if( color.w < 1.0/255.0 ) {
        discard;
    }
    v_color = color;
}

I've added the "#version 420 core" preamble to each shader. I know I shouldn't use the glProgramParameteriEXT function to define GL_GEOMETRY_INPUT_TYPE_EXT, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_GEOMETRY_VERTICES_OUT_EXT, because these parameters are specified in the geometry shader (which is core in OpenGL 4.2).

EDIT: My mistake was incorrect usage of glVertexAttribPointer (wrong value of the the last parameter). Thanks for all the answers and sorry for your wasted time!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ A probable cause of this is using the old GL_ARB_shader_objects extension for your VS and FS. This extension was never taken up into core OpenGL (GL2+ shaders use a different API) so GL2+ features shouldn't be expected to work with it (some might but it's not guaranteed). \$\endgroup\$ Dec 29, 2013 at 13:17

1 Answer 1

2
\$\begingroup\$

Geometry shader is only available in GLSL version 1.5 and later, and you need to specify that explicitly in the geometry shader source. I guess it's #version 400 in your case. Here is the list of GLSL verseions.

\$\endgroup\$
2
  • \$\begingroup\$ I've added #version 400 at the beginning of all shaders and now it shows only a black screen. (Fixed-function states are not to blame, because fullscreen quad with font texture is shown just fine.) Wow, the support on this forum is lightning fast! \$\endgroup\$ Dec 29, 2013 at 13:26
  • \$\begingroup\$ try #version 420 \$\endgroup\$
    – concept3d
    Dec 29, 2013 at 13:42

You must log in to answer this question.

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