SFML community forums

Help => Window => Topic started by: FRex on February 10, 2018, 03:48:12 am

Title: GL - 3rd coord being large causes primitives to not be displayed
Post by: FRex on February 10, 2018, 03:48:12 am
I'm not sure what's going on. I thought z will be ignored due to sf::View setting ortho projection but it's not - if it's uploaded (hold Q) and large (hold E) then there will be nothing displayed.

I don't want to upload just 2 GL_FLOATs since I'm making a buffer of 3D vertices and then want to draw them 3 times from 3 sides with 3 different ortho projections (that I'll set myself in the GL_PROJECTION matrix but I want to get the common xy case 100% working and understood first).

#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
    sf::RenderWindow app(sf::VideoMode(800u, 600u), "gl");
    app.setFramerateLimit(60u);

    {
        //get ortho sf::View applied
        sf::Vertex v;
        app.draw(&v, 1, sf::Points);
    }

    float trig[9] = {
        0.f, 0.f, 0.f,
        100.f, 100.f, 0.f,
        100.f, 0.f, 0.f,
    };

    while(app.isOpen())
    {
        sf::Event eve;
        while(app.pollEvent(eve))
        {
            if(eve.type == sf::Event::Closed)
                app.close();
        }//while app poll event eve

        app.clear();
        trig[2] = trig[2 + 3] = trig[2 + 6] = sf::Keyboard::isKeyPressed(sf::Keyboard::E) * 100.f;

        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
        glVertexPointer(2 + sf::Keyboard::isKeyPressed(sf::Keyboard::Q), GL_FLOAT, sizeof(sf::Vector3f), trig);
        glDrawArrays(GL_TRIANGLES, 0, 3);

        app.display();
    }
}
 
Title: Re: GL - 3rd coord being large causes primitives to not be displayed
Post by: fallahn on February 10, 2018, 11:07:52 am
Orthographic projections are still 3D, they just don't provide any perspective calculation. If your camera position (ie your view matrix) is set to the default 0 on the Z axis, then any geometry with a positive Z value will end up behind the camera - which is why you can't see it. Try setting the Z positions to negative values which will move them away from the camera - although, again, you won't be able to see them if they go beyond the far clip plane and I don't know what the default value is for that is in SFML.
Title: Re: GL - 3rd coord being large causes primitives to not be displayed
Post by: FRex on February 10, 2018, 11:49:28 am
Yes. With my own ortho from glm::ortho with far near and far clip planes it seems to be okay for all three views (I multiply in a permutation matrix into the GL_PROJECTION one to make other axis take the Z place before ortho projection applies). Are there any downsides to +/- billion for these two or my multiplication with a permutation matrix?