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

Author Topic: Quads that are not rectangles  (Read 1437 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Quads that are not rectangles
« on: October 22, 2012, 11:18:38 pm »
Hi. ;D
Ok, so I have a quad, that is not a retangle nor square. It's a trapezoid.
Basically, the quad act as if it's a pair of triangles and texture becomes deformed the farer its' shape goes away from a square.
In case problem is on my end I attached the screens of what I see.
In case problem is not on my end, is this the desired and/or expected behaviour?
I didn't look very carefully through documentation but only thing I could notice is the warning about integer texture coords(but irrelevant here).
Here the code and image to reproduce the problem, press any key to increase the trapezoidness of the quad, press any mouse button to toggle texture smoothing(doesn't help):
#include <SFML/Graphics.hpp>
int main(int argc,char * argv[])
{
        sf::RenderWindow app(sf::VideoMode(600,600),"");
        sf::VertexArray arr(sf::Quads);
        sf::Vector2f pts[4];
        pts[0]=sf::Vector2f(0.f,0.f);
        pts[1]=sf::Vector2f(0.f,64.f);
        pts[2]=sf::Vector2f(64.f,64.f);
        pts[3]=sf::Vector2f(64.f,0.f);
        sf::Texture tex;
        tex.loadFromFile("laser.tga");
        tex.setSmooth(true);
        float test=0.f,max=512.f;
        arr.append(sf::Vertex(sf::Vector2f(0.f,0.f),pts[0]));
        arr.append(sf::Vertex(sf::Vector2f(0.f,max),pts[1]));
        arr.append(sf::Vertex(sf::Vector2f(max,max-test),pts[2]));
        arr.append(sf::Vertex(sf::Vector2f(max,test),pts[3]));
        while(1)
        {
                sf::Event eve;
                while(app.pollEvent(eve))
                {
                        if(eve.type==sf::Event::KeyPressed)
                        {
                                test+=1.f;
                                arr.clear();
                                arr.append(sf::Vertex(sf::Vector2f(0.f,0.f),pts[0]));
                                arr.append(sf::Vertex(sf::Vector2f(0.f,max),pts[1]));
                                arr.append(sf::Vertex(sf::Vector2f(max,max-test),pts[2]));
                                arr.append(sf::Vertex(sf::Vector2f(max,test),pts[3]));
                        }
                        if(eve.type==sf::Event::MouseButtonPressed)
                        {
                                tex.setSmooth(!tex.isSmooth());
                        }

                }
                app.clear(sf::Color::Green);
                app.draw(arr,&tex);
                app.display();
        }
}

[attachment deleted by admin]
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9720
    • View Profile
    • development blog
    • Email
Re: Quads that are not rectangles
« Reply #1 on: October 22, 2012, 11:40:47 pm »
A quad is nothing else than two triangles stitched together. If you now change the quad to not be a quad then the triangles will deform but not in the same way and that's causing different texture deforming. ;)
That's how 'graphics' work, every 3D model is split into hundreds up to billions of triangles. ;)

In the attachment I highlighted the two triangles.

[attachment deleted by admin]
« Last Edit: October 22, 2012, 11:45:17 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: Quads that are not rectangles
« Reply #2 on: October 22, 2012, 11:46:48 pm »
That's what I thought. ;D I assumed quads might be two triangles but then does it mean that one quad is as heavy to render as two triangles? Could you please run the code with that image and say if it happens to you too? I'd apperciate that since this laptop is quite interesting(Ahem ;)) piece of hardware and has intels graphics...
Quote
That's how 'graphics' work, every 3D model is split into hundreds up to billions of triangles. ;)
I know.
I also noticed there are two tirnagles forming out of that trapezoid quad but thanks for thought. :)
static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES,
GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS};
I see that quads are not hacked in by stiching two triangles by sfml so I'm asking if it's expected out of opengl. Preferably laurent or tank or someone else who is one of opengl pros in here. I found one post but there, the quad was drawn by opengl code so it's like invisible to me.
Well ok, gotta do it the triangles way. Awesome..
« Last Edit: October 22, 2012, 11:54:40 pm by FRex »
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9720
    • View Profile
    • development blog
    • Email
Re: Quads that are not rectangles
« Reply #3 on: October 22, 2012, 11:54:53 pm »
Yes it bends here too on my Radeon HD 6470M, just a bit different... ;)

I'm not sure, but I had in mind that some graphics card support quad rendering but I'm also not sure if SFML makes use of such features... :D

[attachment deleted by admin]
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32466
    • View Profile
    • SFML's website
    • Email
Re: Quads that are not rectangles
« Reply #4 on: October 23, 2012, 06:37:36 am »
It is the expected behaviour. The only way to fix this (i.e. get a fake 3D effect) would be to activate the perspective correction flag, and use the W coordinate of vertices.
Laurent Gomila - SFML developer

 

anything