GLSL – rewriting (geometry) shader from #330 to #130 version

| | August 10, 2015

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();
};

One Response to “GLSL – rewriting (geometry) shader from #330 to #130 version”

  1. Sean Middleditch on November 30, -0001 @ 12:00 AM

    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.

Leave a Reply