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

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

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • 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]
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • 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
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • 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 »
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • 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
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • 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