View Full Version : Newbie OpenGL Geometry shaders

02-19-2015, 10:21 PM

I am using opengl v2.0.1.8x.
I am trying to apply a geometry shader to the rendering procedure.
The problem is very unusual (I've put a "// ****** Bug here", before the problem codeline)

#version 120
#extension GL_ARB_geometry_shader4 : enable
in vec3 vertWorldPos[3];
in vec3 vertWorldNormal[3];
out vec3 worldNormal;
out vec3 worldPos;
uniform vec2 WIN_SCALE;
out vec3 dist;

void main(void) {
vec2 sz = WIN_SCALE;
vec2 tt = gl_PositionIn[0].xy;
vec2 t2 = vec2(gl_PositionIn[0].w, gl_PositionIn[0].w);
vec2 p0 = sz * tt / t2; // ****** Bug here

tt = gl_PositionIn[1].xy;
t2 = vec2(gl_PositionIn[1].w, gl_PositionIn[1].w);
vec2 p1 = (sz * tt) / t2; // ****** Bug here

tt = gl_PositionIn[2].xy;
t2 = vec2(gl_PositionIn[2].w, gl_PositionIn[2].w);
vec2 p2 = (sz * tt) / t2; // ****** Bug here

vec2 v0 = p2-p1;
vec2 v1 = p2-p0;
vec2 v2 = p1-p0;
float area = abs(v1.x*v2.y - v1.y * v2.x); // ****** Bug here

dist = vec3(area/length(v0),0,0); // ****** Bug here
worldPos = vertWorldPos[0];
worldNormal = vertWorldNormal[0];
gl_Position = gl_PositionIn[0];

dist = vec3(0,area/length(v1),0); // ****** Bug here
worldPos = vertWorldPos[1];
worldNormal = vertWorldNormal[1];
gl_Position = gl_PositionIn[1];

dist = vec3(0,0,area/length(v2)); // ****** Bug here
worldPos = vertWorldPos[2];
worldNormal = vertWorldNormal[2];
gl_Position = gl_PositionIn[2];


Thing is that it seems that the compilationcan not be applied on any code of line (in the geometry) where I am using the / or * operators...
Does anyone know what is wrong with that... and how to fix that?
I checked the version of the opengl I am using, but it seems that this code should work in the earlier versions as well (which I am using, I got quite old legacy "ATI Radeon x1650 GT" card).


Alfonse Reinheart
02-20-2015, 05:23 AM
#version 120
#extension GL_ARB_geometry_shader4 : enable
in vec3 vertWorldPos[3];

First, these three statements cannot go together. GLSL 1.20 does not use in/out on global variables, and ARB_geometry_shader4 does not make this syntax legal. ARB_geometry_shader4 and core geometry shader functionality (https://www.opengl.org/wiki/Geometry_Shader) are specified differently. I would tell you how ARB_geometry_shader4 actually works, but:

I got quite old legacy "ATI Radeon x1650 GT" card

That card does not support geometry shaders. Of any kind. So it would be useless to explain.