Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML2 and Vertex Shader problem  (Read 1528 times)

0 Members and 1 Guest are viewing this topic.

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
SFML2 and Vertex Shader problem
« on: March 06, 2012, 09:36:00 am »
Hi, I am real beginner in GLSL. I have this GLSL vertex shader and it doesnt work as I want. According to me it should change the position of the rectangle by * 0.5, because SFML draw it like GL_QUAD with vertexes, but rect disapears. Can somebody help me please?
I also tried change last line to, but it doesnt work :( .
Code: [Select]
  gl_Position = gl_ModelViewProjectionMatrix * a;
Shader code
Code: [Select]
void main(void)
{
   vec4 a = gl_Vertex;
   a.x = a.x * 0.5;
   a.y = a.y * 0.5;

   gl_Position = a;
}

Here is my code
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,600,32),"SFML");
    App.SetFramerateLimit(30);

    sf::Shader vertShader;

    if(!vertShader.LoadFromFile("scaleshader.vert",sf::Shader::Vertex))
        App.Close();

    while(App.IsOpen())
    {
        App.Clear();
        sf::Event event;
        while(App.PollEvent(event))
        {
            if((event.Type == sf::Event::Closed) || (event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
                App.Close();
        }

        sf::RenderStates shader(&vertShader);
        sf::RectangleShape rect(sf::Vector2f(200,100));
        rect.SetPosition(300,250);
        rect.SetFillColor(sf::Color(255,0,0,255));

        App.Draw(rect,shader);

        App.Display();
    }

    return 0;
}

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
SFML2 and Vertex Shader problem
« Reply #1 on: March 08, 2012, 09:42:02 pm »
I solved my problem. I had to add this line code at the end of the shader.   :D
Code: [Select]
gl_FrontColor = gl_Color;
I am sorry for my mistake and the surplus topic. :oops:

 

anything