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

Simple texture mapping

Started by ll0377 Jul 13, 2004 at 3:45 PM 2 replies 850+ views
Original Post
ll0377
ll0377
Could someone please help me, I can't figure out what I'm doing wrong. I'm new to DirectX and I've been trying to texture map a simple 256 x 256 image: http://www.mycgiserver.com/~ll0377/stuff/reddot.bmp to a single triangle. I end up with this: http://www.mycgiserver.com/~ll0377/stuff/scene.JPG It seems like the texture is being sampled at the same coordinate repeated across the horizontal, and is being repeated in the vertical. The following is the portion of my code concerning texture mapping. // This is done in the constructor of the object D3DXCreateTextureFromFile(g_pdevice, "res/tex/reddot.bmp", &ptex); g_pdevice->CreateVertexBuffer(sizeof(d3d::STex1Vertex) * 3, 0, d3d::STex1Vertex::FVF, D3DPOOL_DEFAULT, &vb, 0); d3d::STex1Vertex *pverts; vb->Lock(0, 0, (void**)&pverts, 0); pverts[0] = d3d::STex1Vertex(-10.0f, -10.0f, 10.0f, 0.0f, 1.0f); pverts[1] = d3d::STex1Vertex(-10.0f, 10.0f, 10.0f, 0.0f, 0.0f); pverts[2] = d3d::STex1Vertex(10.0f, 10.0f, 10.0f, 1.0f, 0.0f); vb->Unlock(); // This is done some time before rendering g_pdevice->SetRenderState(D3DRS_LIGHTING, FALSE); g_pdevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); g_pdevice->SetRenderState(D3DRS_ZENABLE, TRUE); g_pdevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // This is done in the render() of the object g_pdevice->SetTexture(0, ptex); g_pdevice->SetFVF(d3d::STex1Vertex::FVF); g_pdevice->SetStreamSource(0, vb, 0, sizeof(d3d::STex1Vertex)); g_pdevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); // This is the FVF I defined struct STex1Vertex { STex1Vertex(float x, float y, float z, float u, float v) { this->x = x; this->y = y; this->z = z; this->u = y; this->v = v; } float x, y, z; float u, v; static const DWORD FVF = D3DFVF_XYZ | D3DFVF_TEX1; }; I've tried different images, different texture stage states and different sampler states, all leads back to the same problem. I'd appreciate any suggestions.
........................Leo LeeSoftware Engineerhttp://www.leolees.com
DrunkenHyena
DrunkenHyena
STex1Vertex(float x, float y, float z, float u, float v)
{
this->x = x; this->y = y; this->z = z;
this->u = y; this->v = v;
}


I think you meant:
this->u = u; this->v = v;
Stay Casual,KenDrunken Hyena</FON
ll0377
ll0377
Another dumb moment. I spent the whole day over a typo, but can't say it was the first time. I wonder if veteran programmers ever stop making dumb mistakes like I do. Thank you much for finding it for me!
........................Leo LeeSoftware Engineerhttp://www.leolees.com
Sharky
Sharky
Quote:
Original post by ll0377
Another dumb moment. I spent the whole day over a typo, but can't say it was the first time. I wonder if veteran programmers ever stop making dumb mistakes like I do. Thank you much for finding it for me!


:) I wouldn't worry about it... it happens to us all! Even after 7-8 years as a professional game programmer I still make those same silly mistakes. We are human and prone to errors now and again... ;) My most common typo tends to be when I use '&' instead of '&&' (or vice versa). Oops.

Regards,
Sharky

Topic Locked

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

Sign in to reply to this topic.