Trying to LoadTextureFrom file into Quad

Recommended Posts

I've been going through the DirectX Tutorials and have made it to the Texture part, which is what I have been attempting to accomplish and am having some troubles.

My devices have been initialized and I have been able to draw both a colored triangle as well as a square. However, trying to follow the tutorial to get a texture ( a 256x256 PNG ) has thus far resulted in failure. I see the square, which is rendering as a darker blue than the background; however, no image is being loaded.

I am trying to load this into a 2d space, so I'm not needing the 3d environment as the tutorial uses, which may be causing some of my issues. Right now I'm just trying to create the texture, HRESULT is passing this stage, and then send that into the vertex buffer.

Here is what I have so far, maybe someone can point me in the right direction now:I call this function to finish setting up my Device after it has been created:

After this is done I now have a texture loaded and my quad set up. The coordinates for the position of the triangles are set at:Top Left: 0, 0, 0.5, 1, 1, 0, 0Top Right: 256, 0.5, 0, 1, 1, 0Bottom Left: 0, 256, 0.5, 1, 0, 1Bottom Right: 256, 256, 0.5, 1, 1, 1

Which should be setting up the appropriate X,Y,Z coordinates, an hr of 1 which is what the original tutorial set for the triangle, and then a tu and ty with respect to where they should be located in the window.

Share this post

Link to post

Share on other sites

Been playing with it all afternoon, and for the better part of last week, and still can't figure out what's wrong.

If anyone has any advice I'd greatly appreciate it, if what I've provided is not enough information then let me know what else you need to know, or if your willing to take a look at my source code I've zipped it up here:http://www.filefactory.com/file/b3fcc39/n/Direct3D_2.rar

void Direct3D::Render(){ //------------------- if ( NULL == d3d.d3d9Device) return; //------------------- d3d.d3d9Device->Clear( 0, // Number of Rectangles in Array - Set to 0 since Rects is NULL NULL, // Pointer to an Array of D3DRect to Clear - NULL indicates entire viewport D3DCLEAR_TARGET, // Surface to Clear D3DCOLOR_XRGB( 0, 0, 0 ), // Clear to this Color 1.0f, // Depth Buffer to Clear to 0 // Stencil Buffer to Clear to ); //------------------- if ( SUCCEEDED( d3d.d3d9Device->BeginScene() ) ) { //------------------- // Scene Rendering takes place Here //------------------- // Draw the triangles in the vertex buffer. This is broken into a few // steps. We are passing the vertices down a "stream", so first we need // to specify the source of that stream, which is our vertex buffer. Then // we need to let D3D know what vertex shader to use. Full, custom vertex // shaders are an advanced topic, but in most cases the vertex shader is // just the FVF, so that D3D knows what type of vertices we are dealing // with. Finally, we call DrawPrimitive() which does the actual rendering // of our geometry (in this case, just one triangle). //------------------- D3DCOLOR vertexColour = 0xFFFFFFFF; d3d.d3d9Sprite->Begin(D3DFILL_SOLID); d3d.d3d9Sprite->Draw( d3d.d3dTexture, NULL, new D3DXVECTOR3(128.0f, 128.0f, 0.5f), NULL, vertexColour ); d3d.d3d9Sprite->End();

Share this post

Link to post

Share on other sites

I figured it out finally. What I did instead of trying to draw the texture into the quad, I created a Sprite, initialized it, and then created a texture from file and called:

//------------------- D3DCOLOR vertexColour = 0xFFFFFFFF; //------------------- if ( NULL == d3d.d3d9Device) return; //------------------- d3d.d3d9Device->Clear( 0, // Number of Rectangles in Array - Set to 0 since Rects is NULL NULL, // Pointer to an Array of D3DRect to Clear - NULL indicates entire viewport D3DCLEAR_TARGET, // Surface to Clear D3DCOLOR_XRGB( 0, 0, 0 ), // Clear to this Color 1.0f, // Depth Buffer to Clear to 0 // Stencil Buffer to Clear to ); //------------------- if ( SUCCEEDED( d3d.hr = d3d.d3d9Device->BeginScene() ) ) { //------------------- // Scene Rendering takes place Here //------------------- // Draw the triangles in the vertex buffer. This is broken into a few // steps. We are passing the vertices down a "stream", so first we need // to specify the source of that stream, which is our vertex buffer. Then // we need to let D3D know what vertex shader to use. Full, custom vertex // shaders are an advanced topic, but in most cases the vertex shader is // just the FVF, so that D3D knows what type of vertices we are dealing // with. Finally, we call DrawPrimitive() which does the actual rendering // of our geometry (in this case, just one triangle). //-------------------