Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vertex Buffer + Vertices

Started by MrDoomMaster Oct 20, 2005 at 11:08 PM 4 replies 1k views
Original Post
MrDoomMaster
MrDoomMaster
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...
MasterWorks
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...
MrDoomMaster
MrDoomMaster
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.
MasterWorks
MasterWorks
That's fine, are you using Direct3D8? 9?
MrDoomMaster
MrDoomMaster
Quote:
Original post by MasterWorks
That's fine, are you using Direct3D8? 9?


9.0c August 2005 update.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.