Sign in to follow this  
MrDoomMaster

Vertex Buffer + Vertices

Recommended Posts

MrDoomMaster    103
I have a question about vertex coordinates concerning 2D textured quads. As you all know, textured quads are measured in screen units (pixels), so having said this I can proceed with my question: Currently, I use the following structure to define a rectangle on the screen:
struct Rect
{
    int x;
    int y;
    int width;
    int height;
}
When setting up the 4 vertices that compose of the quad, I was wondering if the bottom and right edges are measured like Win32 RECT's are measured in GDI, that is, the right and bottom edges are -1 pixel short. I'm having a hard time explaining this, so allow me to show some examples: Assume that I want to create a textured quad that starts at 0,0 (top left of the screen) and is 7 pixels wide and 7 pixels high. So, I would create a Rect object as follows:
Rect r;
r.x = 0;
r.y = 0;
r.width = 7;
r.height = 7;
Now, when I create my quad, I create my vertex array as follows:
Vertex v[4];

// Top Left of Quad
v[0].x = r.x;
v[0].y = r.y;

// Top Right of Quad
v[1].x = r.x + r.width;
v[1].y = r.y;

// Bottom Right of Quad
v[2].x = r.x + r.width;
v[2].y = r.y + r.height;

// Bottom Right of Quad
v[3].x = r.x;
v[3].y = r.y + r.height;



As you can see, the top left is at pixel 0, and the top right pixel is at pixel 7. This means the quad is actually 8 pixels wide, since pixel 7 is actually the 8th pixel (starting from 0). To make things even more unusual, this method is actually correct and creates a quad that is 7 pixels wide. The math isn't making sense for some reason. Can someone explain this a bit for me? Thanks...

Share this post


Link to post
Share on other sites
MasterWorks    496
There is a famous texel-to-pixel mapping article that I'm sure somebody can you give you the URL for.

Just as a side note, with Direct3D I think you're better off keeping float values for position, etc. And of course your 'quad' can be rotated or whatever (if you want) so maybe you could just store the 4 corner points? It depends what you're trying to do and what version you're using...

Share this post


Link to post
Share on other sites
MrDoomMaster    103
Quote:
Original post by MasterWorks
There is a famous texel-to-pixel mapping article that I'm sure somebody can you give you the URL for.

Just as a side note, with Direct3D I think you're better off keeping float values for position, etc. And of course your 'quad' can be rotated or whatever (if you want) so maybe you could just store the 4 corner points? It depends what you're trying to do and what version you're using...


I have my Rect object as it is now so I can easily change the position of the rectangle without having to change the width/height information, and likewise with the size of the rectangle.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this