Advertisement Jump to content
Sign in to follow this  
blueShadow

Mapping problem onto a 2D quad

This topic is 1753 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 !

I try to map a texture onto a quad but I get the strange mapping that there is here (I should have several characters and a sky): 

[attachment=20667:screenshot.png]

 

If I change the texture, I have the same type of error concerning the mapping... (colors are the ones which belong to the image which I try to map, but like you see mapping is uncorrect...)

I am sure that vertices positions are right. It seems that texture coordinates are right too...

 

Any idea of where the error could come from ? 

Here is a code snippet :

XMFLOAT2 texCoordinates[4] =  {XMFLOAT2(0.0f, 1.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT2(1.0f, 1.0f), XMFLOAT2(1.0f, 0.0f)/***/  };

XMFLOAT4 positions[] = {	 XMFLOAT4( -D3D11Rendering::width/2,  -D3D11Rendering::height/2,  0.0f, 1.0f), //bottom, left
								 XMFLOAT4( -D3D11Rendering::width/2,  D3D11Rendering::height/2,  0.0f, 1.0f), //up, left.
								 XMFLOAT4( D3D11Rendering::width/2,  -D3D11Rendering::height/2,  0.0f, 1.0f), //bottom, right
								 XMFLOAT4( D3D11Rendering::width/2,  D3D11Rendering::height/2,  0.0f, 1.0f)}; //up, right.

unsigned short int indexArray [] = {0, 2, 1, 2, 1, 3} ;

Share this post


Link to post
Share on other sites
Advertisement

It just looks like your texture co-ordinates are not being mapped correctly. I haven't had a good look at your code, but this is what I use to texture a full image to a quad. You do have to be very careful which texture coordinates you map to which point on your quad (and in the correct order).

    SimpleVertex vertices[] =
    {
        { XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f) },
        { XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) },
        { XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f) },
        { XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f) },
    };

Share this post


Link to post
Share on other sites

What does your input layout look like and how do you merge position and uv data into the vertex stream?

 

Also note that the winding order isn't consistent between the two triangles.

Share this post


Link to post
Share on other sites

I have found the error and strangely (for me), the rendering is correct when I changed DXGI_FORMAT_R16G16_FLOAT by DXGI_FORMAT_R32G32_FLOAT in the variable of type D3D11_INPUT_ELEMENT_DESC.

Do you know why ?

It was the only error.

Share this post


Link to post
Share on other sites

Because you are passing 32-bit floats, not 16-bit floats.

I’m not sure how deep an explanation on that can go…

 

 

L. Spiro

Share this post


Link to post
Share on other sites

If you specify a R16 format, the Input Assembler expects 16 bit floats. You'd have to do a manual float32-to-half16 conversion.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!