Skip to main content
gamedev.net
🔒 Locked

textured quad

Started by BloodLust666 5 replies 600+ views
Original Post
BloodLust666
BloodLust666
I don't exactly know how to start it off so if someone could, give me a little code that takes a quad and texturizes it with a idirect3dtexture9 texture. or something
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
neneboricua19
neneboricua19
If you're just starting off, you should really start with the tutorials that come with the SDK. Tutorial 5 specifically sets up a textured quad and explains all the steps along the way.

The forum FAQ has links to a number of web sites with tutorials and sample code to help you learn different things.

neneboricua
DrunkenHyena
DrunkenHyena
http://www.drunkenhyena.com/cgi-bin/view_article.pl?chapter=2;article=30;lang=cpp

BTW, this is linked (indirectly) from the Forum FAQ. There are a lot of good resources listed there, it'd be worth checking out.
Stay Casual,KenDrunken Hyena</FON
Evil Steve
Evil Steve
Untested code, with minimal error checking:
// Assumes pDevice is a valid IDirect3DDevice9*// Assumes pTexture is a valid IDirect3DTexture9*// Vertex structure (post-transformed, in scrood coordinates)struct TLVertex{   TLVertex() {}   TLVertex(D3DXVECTOR3 _pos, DWORD _colour, float _u, float _v, float _rhw=1.0f)      : vPos(_pos), rhw(_rhw), dwColour(_colour), u1(_u), v1(_v) {}   D3DXVECTOR3 vPos;   float rhw;   DWORD dwColour;   float u1;   float v1;};#define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)// Create a vertex buffer with space for 4 quads. Specify D3DUSAGE_WRITEONLY!LPDIRECT3DVERTEXBUFFER9 pVB;HRESULT hResult = pDevice->CreateVertexBuffer(4*sizeof(TLVertex), D3DUSAGE_WRITEONLY, FVF_TLVERTEX, D3DPOOL_MANAGED, &pVB, NULL);if(FAILED(hResult))   return; // Error// Lock the vertex buffer, fill it, then unlock it:TLVertex* pVerts;hResult = pVB->Lock(0,0,(void**)&pVerts,0);if(FAILED(hResult))   return; // ErrorpVerts[0] = TLVertex(D3DXVECTOR3(0,0,0),0xffffffff,0,0);pVerts[1] = TLVertex(D3DXVECTOR3(0,100,0),0xffffffff,0,1);pVerts[2] = TLVertex(D3DXVECTOR3(100,0,0),0xffffffff,1,0);pVerts[3] = TLVertex(D3DXVECTOR3(100,100,0),0xffffffff,1,1);pVB->Unlock();// In your main rendering loop:// Only specify D3DCLEAR_ZBUFFER if you have a Z-Buffer attachedpDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0x00000000,1.0f,0);pDevice->BeginScene();// Tell D3D to render from the VB, and tell it what format it's to render in (Transformed verts)pDevice->SetFVF(FVF_TLVERTEX);pDevice->SetStreamSource(0,pVB,0,sizeof(TLVertex));// Set the texturepDevice->SetTexture(0,pTexture);// Draw the quad pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);// Show what's rendered on the screenpDevice->EndScene();pDevice->Present(NULL,NULL,NULL,NULL);

That's very rough, but it shows all the important steps. You might be better off trying to find a tutorial for this sort of thing though.
BloodLust666
BloodLust666
i got all the device setup and what not, i just need to know how to do the vertex and setting the texture and whatnot
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Evil Steve
Evil Steve
Quote:
Original post by EvilKnuckles666
i got all the device setup and what not, i just need to know how to do the vertex and setting the texture and whatnot
My example above shows how to create and fill a vertex buffer, and how to render from it, using a texture.
BloodLust666
BloodLust666
oh wow.. i didn't even see that scroll bar, sry haha
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML

Topic Locked

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

Sign in to reply to this topic.