Hi, I've been having some trouble using geometry shaders on drawables such as sf::Circles and sf::ConvexShapes. When attempting to draw the object with a loaded geometry shader, nothing is drawn whatsoever. I can only get the geometry shader to successfully execute on an array of sf::Vertex (sf::Vertex[]). I would have expected the geometry shader naturally to operate on each vertex of an sf::Drawable and at least display something, though I'm not well versed in what goes on under the hood of window.draw() so I'm probably missing something.
FWIW I'm on SFML-2.4.2 with MinGW 6.1.0. Here's my code:
//main.cpp
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window;
sf::VideoMode mode(800, 800);
window.create(mode, "test");
sf::Shader shader;
shader.loadFromFile("./test.vert", "./test.geom", "./test.frag");
sf::Vertex shape[] = {sf::Vertex({400.0f, 400.0f})};
sf::CircleShape shape2(5.0f);
shape2.setPosition(400, 100);
sf::Drawable* draw = &shape2;
while(window.isOpen())
{
sf::Event currEvent;
while(window.pollEvent(currEvent))
{
switch(currEvent.type)
{
case(sf::Event::Closed):
window.close();
break;
default:
break;
}
}
window.clear(sf::Color::Black);
window.draw(shape, 1, sf::Points, &shader);
window.draw(shape2, &shader);
window.display();
}
}
//test.vert
void main()
{
vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}
//test.geom
layout (points) in;
layout (triangle_strip, max_vertices = 3) out;
// Main entry point
void main()
{
vec4 offset = vec4(0.1, vec3(0.0));
vec4 offset2 = vec4(0.0, 0.1, 0.0, 0.0);
gl_Position = gl_in[0].gl_Position + offset;
EmitVertex();
gl_Position = gl_in[0].gl_Position - offset;
EmitVertex();
gl_Position = gl_in[0].gl_Position + offset2;
EmitVertex();
EndPrimitive();
}
//test.frag
void main()
{
gl_FragColor = vec4(1.0,0.0,1.0,1.0);
}
The window displays a pink triangle at the centre of the window but there is no circleshape or other geometry to be seen.