Archived

This topic is now archived and is closed to further replies.

Beginner Question - Vertex Buffer/Texturing & Sprite problem

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

Hi all, I have a small problem here. Im starting to learn Direct3D and have set up the vertex buffer, loaded a texture from memory and displayed it to the screen, but when it gets displayed there is a black line on top of the bitmap im displaying. The line is across the top boundry of the bitmap, and its not an accidental coloring I did when drawing the picture so I has to have taken place when I loaded the texture. Heres the code I have: BYTE *Ptr; sVertex Verts[] = { { 200.0f, 200.0f, 0.0f, 0, 0.0f, 0.0f }, { 242.0f, 200.0f, 0.0f, 0, 1.0f, 0.0f }, { 200.0f, 270.0f, 0.0f, 0, 0.0f, 1.0f }, { 242.0f, 270.0f, 0.0f, 0, 1.0f, 1.0f } }; g_pDevice->CreateVertexBuffer( sizeof(sVertex)*4, 0, VertexFVF, D3DPOOL_DEFAULT, &g_pVB ); g_pVB->Lock( 0, 0, (BYTE**)&Ptr, 0 ); memcpy(Ptr, Verts, sizeof(Verts) ); g_pVB->Unlock(); D3DXCreateTextureFromFileEx( g_pDevice, "wonderboyframewithsword1.bmp", NULL, NULL, NULL, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, 0, D3DCOLOR_ARGB( 255, 255, 0, 255 ), NULL, NULL, &g_pTexture ); g_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); g_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); g_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); And in my Render() function I have this: g_pDevice->BeginScene(); g_pDevice->SetStreamSource( 0, g_pVB, sizeof( sVertex ) ); g_pDevice->SetVertexShader( VertexFVF ); g_pDevice->SetTexture( 0, g_pTexture); g_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ); g_pDevice->EndScene(); Also, the image is kind of blurry, would one of the SetRenderState's be the source of that problem? Thanks for any help [edited by - The Goon on October 20, 2002 12:47:05 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
geez your code sux you newb! Try some LOLios and ROFeL Puffs for breakfast! hahahahahaha

Share this post


Link to post
Share on other sites
Nevermind I figured it out.

---------------------------------------------
geez your code sux you newb! Try some LOLios and ROFeL Puffs for breakfast! hahahahahaha
---------------------------------------------

BTW, thanks for the constructive input masterball

Share this post


Link to post
Share on other sites
I''ve figured out a problem with textures in DX8, if you are using color keys, which it looks to me like you are.

Usually, textures will be "blurred" so that you don''t get a pixely effect when getting close to them. This is very desireable for the most part, but can cause some problems.

A bitmap looks like a square or rectangle to us, but in the comp, it is stored linearly. Meaning that the furthest pixel to the right on row 1 will be next to the furthest left pixel to the left in row 2, as far as I know.

Well, let''s say that you are going to draw a boomerang. The boomerang will be brown, and you set your color key to blue. If your boomerang is L shaped in the bitmap, meaning it touches the bottom and left borders of the bitmap, you will probably get a brown line running down the right side of the texture. This is because the program thinks that the furthest right pixel is next to the first pixel on the left of the next row, so it makes it partially brown so that you get a "nice transition" from the brown to the disappearing blue.

I''m not sure if this is the actual reason this occurs, but I''ve noticed that almost all of the time, if I create a bitmap where I don''t have a border of black (my transparent color) around it, I always get lines running along the border of the bitmap.

So the solution is simple. Take your bitmap, and just increase it''s width and height by 2 pixels, and make sure the newly added pixels are the color of your color key. This should eliminate any borders you get around your bitmap.

Please correct me if I''m wrong. This seems to be something that would be often discussed in the forums, but I''ve never seen it come up.

--Vic--

Share this post


Link to post
Share on other sites