View Full Version : Transform feedback tutorial, not getting the desired output?

02-19-2018, 04:57 PM
Not sure if this is the problem, but I'll post my opengl version on linux anyways.

glxinfo | grep 'version'
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
Max core profile version: 3.3
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.0
OpenGL core profile version string: 3.3 (Core Profile) Mesa 17.2.4
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 17.2.4
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.2.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00

Anyways I'm following the tutorial on this page https://open.gl/feedback and my output is a string of zero's instead of the
normal square roots of 1 to 5. Here's the code; it compiles with these libs in codeblocks


Here's the code

// Link statically with GLEW

// Headers
#include <GL/glew.h>
#include <SFML/Window.hpp>

// Vertex shader
const GLchar* vertexShaderSrc = R"glsl( in float inValue; out float geoValue; void main() { geoValue = sqrt(inValue); } )glsl";

// Geometry shader
const GLchar* geoShaderSrc = R"glsl( layout(points) in; layout(triangle_strip, max_vertices = 3) out; in float[] geoValue; out float outValue; void main() { for (int i = 0; i < 3; i++) { outValue = geoValue[0] + i; EmitVertex(); } EndPrimitive(); } )glsl";

int main()
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;

sf::Window window(sf::VideoMode(800, 600, 32), "Transform Feedback", sf::Style::Titlebar | sf::Style::Close, settings);

// Initialize GLEW
glewExperimental = GL_TRUE;

// Compile shaders
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSrc, nullptr);

GLuint geoShader = glCreateShader(GL_GEOMETRY_SHADER);
glShaderSource(geoShader, 1, &geoShaderSrc, nullptr);

// Create program and specify transform feedback variables
GLuint program = glCreateProgram();
glAttachShader(program, vertexShader);
glAttachShader(program, geoShader);

const GLchar* feedbackVaryings[] = { "outValue" };
glTransformFeedbackVaryings(program, 1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);


// Create VAO
GLuint vao;
glGenVertexArrays(1, &vao);

// Create input VBO and vertex format
GLfloat data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };

GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);

GLint inputAttrib = glGetAttribLocation(program, "inValue");
glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

// Create transform feedback buffer
GLuint tbo;
glGenBuffers(1, &tbo);
glBindBuffer(GL_ARRAY_BUFFER, tbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data) * 3, nullptr, GL_STATIC_READ);

// Perform feedback transform


glDrawArrays(GL_POINTS, 0, 5);



// Fetch and print results
GLfloat feedback[15];
glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(feedback), feedback);

for (int i = 0; i < 15; i++)
printf("%f\n", feedback[i]);


glDeleteBuffers(1, &tbo);
glDeleteBuffers(1, &vbo);

glDeleteVertexArrays(1, &vao);


return 0;

I removed the version numbers from the shaders as neither 150 or 130 work. thanks ahead!

02-20-2018, 01:07 AM
Check shader compilation status with glGetShaderiv(GL_COMPILE_STATUS), linking status with glGetProgramiv(GL_LINK_STATUS), and general error status with glGetError().

Dark Photon
02-20-2018, 06:08 AM
The default GLSL version is 1.10. To compile your shaders, I think you'll find you'll need something greater like:

#version 150

02-21-2018, 03:43 PM
The default GLSL version is 1.10. To compile your shaders, I think you'll find you'll need something greater like:

#version 150

Mines at 130 so I would need a newer gpu, correct?

Dark Photon
02-21-2018, 04:45 PM
If your GPU doesn't support OpenGL 3.2 (GLSL 1.50), then yes as that version added Geometry Shader support via GLSL.