Jump to content
  • Advertisement
Sign in to follow this  
wicked357

DirectX vertex size problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Below is my code for creating a quad in DirectX, I noticed that in order to have a 32x32 quad I have to make the width 33 and the height 34. Can someone explain that to me, doesn't seem to make sense?


CUSTOMVERTEX vertices[] =
{
{ 100.0f, 100.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(127, 0, 0), },
{ 133.0f, 100.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(0, 127, 0), },
{ 100.0f, 134.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 127), },
{ 133.0f, 134.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(127, 0, 0), },
};


Also a side question I noticed when you determine the window width and height, say 800x600 that is the actual viewing portion but the border as well. That has me baffled and not sure if most people even noticed that, is there a way to counter that without adding the offset of x and y for the border?

Share this post


Link to post
Share on other sites
Advertisement
I read and followed it, but I have the same problem. Here is my code, it didn't fix my actual size of the quad to be 32x32 instead it is 31x30... I would still have to add an offset of +1 to r and +2 to b.


struct CUSTOMVERTEX
{
float X, Y, Z, RHW, tu, tv;
};

float t = 0.0f;
float l = 0.0f;
float b = 32.0f;
float r = 32.0f;

CUSTOMVERTEX vertices[] =
{
{ l, t, 0.0f, 1.0f, 0.0f, 0.0f, },
{ r, t, 0.0f, 1.0f, 1.0f, 0.0f, },
{ l, b, 0.0f, 1.0f, 0.0f, 1.0f, },
{ r, b, 0.0f, 1.0f, 1.0f, 1.0f, },
};

Share this post


Link to post
Share on other sites
I haven't set up the viewport or projection yet, I take it that is probably the problem.I guess I don't see why that would be the issue, but this is all new to me.

Share this post


Link to post
Share on other sites
On an alternate note, would it be possible to create a viewport + project using LPD3DXSPRITE to render textures or would that way just be a pain? Reason being say I create a tilemap 512x512 of 32x32 square textures. I could only display so many at a time and just move the viewport based on the certain center point.

Share this post


Link to post
Share on other sites
Here is the weird thing I just found out by messing around with window size. I set width = 800 height = 600.

When I create the window I add + 14 to width and + 36 to height because at just 800x600 I actually get a viewing area of 785x564 because the border is counting as size. This actually fixes my problem with the quad rendering at 31x30 pixels instead of the 32x32 pixels. Is it me or is something wrong with that whole system of creating a window?

Share this post


Link to post
Share on other sites
Nothing's wrong with it, but you're missing a step. I forget the exact fuction name but Windows can tell you how big the window needs to be to make the client area a specific size. Try googling for "AdjustWindowRect" but that might be slightly wrong. Sorry if so.

Chad Vernon's tutorials contain code that does this.

The aspect ratio difference could account for your incorrect projected rectangle size too.

Share this post


Link to post
Share on other sites
Thanks I found Chad Vernon's use of it and it works perfectly, for anyone who wanted to know the window sizing issue.

Goes after CreateWindowEx(.....)

RECT rect = {0, 0, width, height};
AdjustWindowRect(&rect, GetWindowLong(hWnd, GWL_STYLE), FALSE);
SetWindowPos(hWnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!