# Vertex Buffer + Vertices

This topic is 4653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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];

v[0].x = r.x;
v[0].y = r.y;

v[1].x = r.x + r.width;
v[1].y = r.y;

v[2].x = r.x + r.width;
v[2].y = r.y + r.height;

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 on other sites
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 on other sites
Quote:
 Original post by MasterWorksThere 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 on other sites
That's fine, are you using Direct3D8? 9?

##### Share on other sites
Quote:
 Original post by MasterWorksThat's fine, are you using Direct3D8? 9?

9.0c August 2005 update.

##### Share on other sites
Heres the Directly Mapping Texels to Pixels article.

I think this might be why your rectangle is being drawn one pixel short.

Hope this helps.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631740
• Total Posts
3001959
×