Jump to content
  • Advertisement
Sign in to follow this  
GroZZleR

Texture Coordinates *sigh*

This topic is 4862 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

Hey all, I'm chipping away on a custom GUI and I've hit a snag with texture coordinates. This problem pertains specifically to progress bars, but will also be an issue with other GUI elements I'm planning on implementing. I'm trying to take an image such as these: And map them to controls. The top represents a full progress bar and the bottom an empty one. I map my texture coordinates like so (Top, Left, Bottom, Right)
Full:    0, 0, 0.5, 1.0
Empty: 0.5, 0, 1.0, 1.0
Here's the result: As you can see, I'm losing the bottom pixel somewhere. Anyone have any ideas? I'm not sure what code to provide because I'm not sure what the problem could be.

Share this post


Link to post
Share on other sites
Advertisement
I made a sample using your texture and it worked fine. Here's my code:

#include <windows.h>
#include <fstream>
#include <mmsystem.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "CTimer.h"
#include "CDirectInput.h"
#include "CDirect3D.h"

HWND g_hWnd = 0;
dfgames::CDirect3D g_D3D;
dfgames::CDirectInput g_DInput;

class Vertex
{
public:
float x, y, z, w;
float u, v;
};

IDirect3DTexture9* pTexture = 0;

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
WNDCLASS WndClass;
ZeroMemory(&WndClass, sizeof(WNDCLASS));
WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndClass.hCursor = LoadCursor(0, IDC_ARROW);
WndClass.hIcon = LoadIcon(0, IDI_APPLICATION);
WndClass.hInstance = GetModuleHandle(0);
WndClass.lpfnWndProc = DefWindowProc;
WndClass.lpszClassName = "D3D9 3D Programming";
RegisterClass(&WndClass);

g_hWnd = CreateWindowEx(0, "D3D9 3D Programming", "D3D9 3D Programming", WS_POPUP | WS_VISIBLE, 0, 0, 800, 600, 0, 0, GetModuleHandle(0), 0);

if(!g_D3D.Create(g_hWnd)) return false;
if(!g_DInput.Create(g_hWnd)) return false;
if(!g_DInput.AttachKeyboard(false, true)) return false;
if(!g_DInput.AttachMouse(true, true)) return false;

D3DXCreateTextureFromFile(g_D3D.GetDevice(), "grass.bmp", &pTexture);
g_D3D.GetDevice()->SetTexture(0, pTexture);
g_D3D.GetDevice()->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);

MSG Msg;
ZeroMemory(&Msg, sizeof(MSG));
while(1)
{
if(PeekMessage(&Msg, 0, 0, 0, PM_REMOVE))
{
if(Msg.message == WM_QUIT)
break;
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
if(!g_DInput.Update())
continue;

if(g_DInput.GetKeyboard()->KeyIsDown(DIK_ESCAPE))
PostQuitMessage(0);

g_D3D.Begin(dfgames::CLR_GREEN);

Vertex V[] =
{
{0.0f, 16.0f, 0.0f, 1.0f, 0, 0.5f},
{0.0f, 0.0f, 0.0f, 1.0f, 0, 0},
{64.0f, 16.0f, 0.0f, 1.0f, 1.0f, 0.5f},
{64.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0},
};
g_D3D.GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, V, sizeof(Vertex));
g_D3D.End();
}
}
pTexture->Release();
g_DInput.Release();
g_D3D.Release();
return 0;
}





Edit: Are you using windowed-mode with a title-bar?

Share this post


Link to post
Share on other sites
hmmm... when I set the progress bar to 100%, it renders just fine too. It seems to be when I size it, that the problem occurs. Here's a picture with the value at 100% (full) and using the full texture.



The first image I have the control set to 64x16, the second 64x32, the third 64x64. It appears that decreasing the size of the control below the default image size causes the issue with the bottom pixel disappearing. From the previous pictures, decreasing the width also seems to remove the pixel on the far right (the missing blue bar on the right).

I am using a window with a title bar. I'm also using an orthographic projection with regular vertices, where as you seem to be using transformed. What are you thinking?

Share this post


Link to post
Share on other sites
I wondered if maybe the DirectX was "resizing it" because of inaccuracies (800x600 window but a smaller client.) But, if it's rendering fine part of the time I have no idea.

Share this post


Link to post
Share on other sites
Try changing texture coordinates like this:
u1 -= 0.5f / width;
v1 -= 0.5f / height;
u2 -= 0.5f / width;
v2 -= 0.5f / height;

My progress bar works fine:


!EDIT! Oh, you're resizing it. I do not resize anything unless it repeats in that direction (like progress bar which can well be 1 pixel in width, resized to fit the whole bar).

[Edited by - ReaVeR-Andrey on July 22, 2005 2:03:07 AM]

Share this post


Link to post
Share on other sites
Can't you layer the frame separate from the bar? Draw the bar using which ever color you want, then place the box with an ALPHA center overtop. The box would be fixed to 0,0…1,1, but the bar would be what ever you want.

This technique will let you get fancier, creating non standard shapes and still able to render your bars by doing so in layers with alpha

For example, in this picture, the bar wrapping around the center HUD is an alpha texture with an alpha HUD blended together:


Share this post


Link to post
Share on other sites
Programmer16, thanks for catching that. I guess it didn't like the single quotes I had. I used your working post to debug mine.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!