2
\$\begingroup\$

I'm having trouble running example from: https://raw.github.com/progschj/OpenGL-Examples/master/07geometry_shader_blending.cpp My graphics card supports only #130 shaders version so I have to rewrite shaders.

I figured out how to fix vertex and fragment shaders. I removed:

layout(location = 0)

from

layout(location = 0) in vec4 vposition;

and added this into my source code:

glBindAttribLocation(shader_program, 0, "vposition");

However I have no idea how to rewrite geometry shader...

#version 130
uniform mat4 View;
uniform mat4 Projection;
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
out vec2 txcoord;
void main() {
   vec4 pos = View*gl_PositionIn[0].gl_Position;
   txcoord = vec2(-1,-1);
   gl_Position = Projection*(pos+vec4(txcoord,0,0));
   EmitVertex();
   txcoord = vec2( 1,-1);
   gl_Position = Projection*(pos+vec4(txcoord,0,0));
   EmitVertex();
   txcoord = vec2(-1, 1);
   gl_Position = Projection*(pos+vec4(txcoord,0,0));
   EmitVertex();
   txcoord = vec2( 1, 1);
   gl_Position = Projection*(pos+vec4(txcoord,0,0));
   EmitVertex();
}

The main problem is how to get rid of location here:

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

Can someone help me?

EDIT: @melak47 - I edited shader, now I'm not getting any error, but window is black.

#version 130
#extension GL_EXT_geometry_shader4 : enable
precision mediump float;
uniform mat4 View;
uniform mat4 Projection;
out vec2 txcoord;
void main() {
    vec4 pos = View*gl_PositionIn[0];
    txcoord = vec2(-1,-1);
    gl_Position = Projection*(pos+vec4(txcoord,0,0));
    EmitVertex();
    txcoord = vec2( 1,-1);
    gl_Position = Projection*(pos+vec4(txcoord,0,0));
    EmitVertex();
    txcoord = vec2(-1, 1);
    gl_Position = Projection*(pos+vec4(txcoord,0,0));
    EmitVertex();
    txcoord = vec2( 1, 1);
    gl_Position = Projection*(pos+vec4(txcoord,0,0));
    EmitVertex();
};
\$\endgroup\$
1
  • \$\begingroup\$ try simply removing those two lines, adding #extension GL_EXT_geometry_shader4 : enable, and replacing gl_PositionIn[0].gl_Position with gl_PositionIn[0]. Maybe you will also have to add gl_FrontColor = gl_FrontColorIn[0]; \$\endgroup\$
    – user13213
    Jul 28, 2012 at 20:13

1 Answer 1

6
\$\begingroup\$

Your graphics card most likely does not support geometry shaders, which require GLSL 1.50 or higher. Geometry shaders were added in OpenGL 3.2, which is the version that supports GLSL 1.50. GLSL 1.30 is part of OpenGL 3.0 which did not support geometry shaders.

I assume you are using a pre-Sandy-Bridge Intel GPU or are on Linux. Intel's drivers are complete crap before the Sandy Bridge and they don't update their older drivers at all. Linux's standard GPU drivers do not yet support geometry shaders, so you'd need to install the proprietary NVIDIA/AMD drivers if you want geometry shaders.

Update: the Asker's problem was out of date drivers. Especially with OpenGL, always keep Windows drivers up to date. OpenGL support tends to lag heavily, and also tends to be buggy. I've shipped more than a few OpenGL games that had support nightmares on Windows thanks to the drivers. If you're only targetting Windows, consider D3D. If you're multi platform, consider supporting both D3D and OpenGL if you have the time/money/manpower.

\$\endgroup\$
6
  • \$\begingroup\$ You are right. My Radeon HD4570 doesn't support GLSL 1.40/1.50. \$\endgroup\$
    – Ziem
    Jul 28, 2012 at 21:50
  • 2
    \$\begingroup\$ ... It should. If you're on Wibdows, upgrade your drivers. \$\endgroup\$ Jul 28, 2012 at 22:26
  • \$\begingroup\$ @Ziem: My Radeon HD3300, an integrated motherboard GPU, supports GL 3.3 just fine. Even on Linux. \$\endgroup\$ Jul 28, 2012 at 22:34
  • 1
    \$\begingroup\$ The proprietary Linux drivers support everything the Windows drivers do, with a few corner case exceptions. The FOSS drivers are only at GL 3.0, and then only if you compile in some patented features that are disabled by default. OSX might also be an issue - it supports GL 3.2, but only if you use Core Profile / forward compatibility when crating the GL context. If you don't, you might be limited to older versions of GL (not sure which off the top of my head). \$\endgroup\$ Jul 29, 2012 at 0:24
  • 2
    \$\begingroup\$ I thought that I had the newest drivers, but I was wrong... I installed AMD Catalyst and updated drivers and voila - everything is working. According to OpenGL Extensions Viewer, my graphics card supports 3.3 and #330 GLSL. Thanks you all for help! \$\endgroup\$
    – Ziem
    Jul 29, 2012 at 9:38

You must log in to answer this question.

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