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

Author Topic: Drawing on a rendertexture with moddern opengl fails...  (Read 1621 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Drawing on a rendertexture with moddern opengl fails...
« on: May 30, 2014, 04:31:08 pm »
I don't know if it's a bug of opengl or of SFML, but, when I draw with opengl on a renderwindow. (I mean by using the functions glVertexAttribPointer and the corresponding attribute location in the shaders) it works but when I want to draw it on a rendertexture, it doesn't draw anything!

Here it's a source code :
int main(void)
{
    odfaeg::RenderWindow window(sf::VideoMode(800, 600), "Test odfaeg");
    odfaeg::RenderTexture rTex;
    rTex.create(800, 600);
  odfaeg::Shader shader;
    const std::string vertexCode =  
    "attribute vec3 vertexPosition_modelspace;"
    "attribute vec4 vertex_color;"  
    "void main() {"
        "vec4 vertex = vec4(vertexPosition_modelspace.xyz, 1.0f);"
        "gl_Position = gl_ModelViewProjectionMatrix * vertex;"      
        "gl_FrontColor = vertex_color;"
    "}";
    const std::string fragmentCode =  
    "void main() {"      
        "gl_FragColor = gl_Color;"
    "}";
    shader.loadFromMemory(vertexCode, fragmentCode);
    shader.bindAttribute(0, "vertexPosition_modelspace");
    shader.bindAttribute(1, "vertex_color");
    odfaeg::Texture tex;
    tex.loadFromFile("tilesets/herbe.png");
    Tile tile(&tex, Vec2f(0, 0), Vec2f(120, 60), IntRect(0, 0, 100, 50));
     while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }
       odfaeg::RenderStates states;
        states.shader = &shader;
        window.clear();
        rTex.clear();
        rTex.draw(tile, states);
        rTex.display();
        odfaeg::Texture tex2 = rTex.getTexture();
        Tile tile2 (&tex2, Vec2f(0, 0), Vec2f(800, 600), IntRect(0, 0, 800, 600));
        window.draw(tile2);
        window.display();
    }
    return 0;
}
 
« Last Edit: May 30, 2014, 04:32:57 pm by Lolilolight »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing on a rendertexture with moddern opengl fails...
« Reply #1 on: May 30, 2014, 04:38:39 pm »
I don't know if it's a bug of opengl or of SFML
Did you consider the possibility that it's neither of them, and your code is wrong?

If you ask a question related to SFML and OpenGL, then please also use SFML and OpenGL in your code, not ODFAEG and OpenGL. We have no idea about your framework, and I don't think people feel like debugging it here.

Also, regard this advice when you ask for help. With more than a thousand posts, you should meanwhile know that...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Drawing on a rendertexture with moddern opengl fails...
« Reply #2 on: May 30, 2014, 04:57:31 pm »
Ok, I'll ask on an opengl forum, I'll have more chance of getting help I think.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Drawing on a rendertexture with moddern opengl fails...
« Reply #3 on: May 30, 2014, 05:49:09 pm »
Erf apparently we must use layout and not bindAttribute which doesn't work with FBO and I don't know how to do.

The problem is that layout is present in GLSL 330 only and my driver support only GLSL 130.

If someone have a solution, I'm ok.
Here is the link :
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/
« Last Edit: May 30, 2014, 05:51:49 pm by Lolilolight »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Drawing on a rendertexture with moddern opengl fails...
« Reply #4 on: May 30, 2014, 05:51:47 pm »
Please stick to English in the English forum and take French posts to the French forum.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Drawing on a rendertexture with moddern opengl fails...
« Reply #5 on: May 30, 2014, 05:52:18 pm »
Sorry wrong language. (I edited)