I am pretty new to using shaders, but I am attempting to use a shader from here:
http://www.geeks3d.com/20130705/shader-library-circle-disc-fake-sphere-in-glsl-opengl-glslhacker/4/It is a 'fake sphere' shader. I want it to make my planet look rather nice. Right now it rotates
I have declared them as so:
const char Vertex[] =
"#version 120\n"
"void main()"
"{"
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
"gl_TexCoord[0] = gl_MultiTexCoord0;"
"}";
const char Fragment[] =
"#version 120\n"
"uniform sampler2D tex0;"
"uniform vec4 bkg_color;"
"uniform float time;"
"void main(void)"
"{"
"vec2 p = -1.0 + 2.0 * gl_TexCoord[0].xy;"
"float r = sqrt(dot(p, p));"
"if (r < 1.0)"
"{"
"vec2 uv;"
"float f = (1.0 - sqrt(1.0 - r)) / (r);"
"uv.x = p.x*f + time;"
"uv.y = p.y*f + time;"
"gl_FragColor = texture2D(tex0, uv);"
"}"
"else"
"{"
"gl_FragColor = bkg_color;"
"}"
"}";
I loading it up like this:
sf::CircleShape planet;
sf::Texture texture;
sf::Shader m_planetShader;
m_planetShader.loadFromMemory(Vertex, Fragment);
texture.loadFromFile("assets/textures/environment/earthmap1k.jpg");
texture.setRepeated(true);
planet.setRadius(100);
planet.setOrigin(planet.getRadius(), planet.getRadius());
planet.setPosition(window.getSize().x / 2, window.getSize().y / 2);
planet.setTexture(&texture); //Is this still needed?
m_planetShader.setParameter("tex0", texture);
m_planetShader.setParameter("bkg_color", 1.0f, 0.0f, 0.0f, 1.0f); //Red as a test
m_planetShader.setParameter("time", 1.0f); //Should be able to update this later on to move the map.
and display is using
window.draw(planet, &m_planetShader);
Obviously with window.display() and other general uses. When it is loaded, It uses the bkg_color (red), but not the texture. Am I missing or declaring something wrong?
Thanks!