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

Normalized coordinates strange behaviour

Started by Infinity95 Jun 12, 2013 at 12:44 PM 3 replies 1k views
Original Post
Infinity95
Infinity95

Hi guys, im having some trouble with my rendering function. The following code produces the image i attachments. As you can see the Coordinates are really off for some reason i can't find out. If there's any more code you need, tell me. I'm gonna try and figure out things myself but please have a look and tell me if you spot anything cause i'm already sitting on this for a few hours and don't have a clue what's wrong.


void Graphics::RenderFrame(void) {

	VERTEX OurVertices[] =
	{
		{0.0f, 0.5f, 0.0f, D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)},
		{1.0f, -0.5f, 0.0f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)},
		{-1.0f, -0.5f, 0.0f, D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f)}
	};

	D3D11_BUFFER_DESC bd;
	SecureZeroMemory(&bd, sizeof(bd));

	bd.Usage = D3D11_USAGE_DYNAMIC;
	bd.ByteWidth = sizeof(VERTEX) * 3;
	bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;

	this->dev->CreateBuffer(&bd, NULL, &pVBuffer);

	D3D11_MAPPED_SUBRESOURCE ms;
	this->devcon->Map(this->pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
	memcpy(ms.pData, OurVertices, sizeof(OurVertices));
	this->devcon->Unmap(this->pVBuffer, NULL);


	this->devcon->ClearRenderTargetView(this->backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

	UINT stride = sizeof(VERTEX);
	UINT offset = 0;
	this->devcon->IASetVertexBuffers(0, 1, &this->pVBuffer, &stride, &offset);

	this->devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	this->devcon->Draw(3, 0);

	this->swapchain->Present(0, 0);

}
"Errare humanum est, sed in errare perseverare diabolicum."
Bacterius
Bacterius

I believe normalized coordinates have a z-depth of 0.5, not zero.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
FLeBlanc
FLeBlanc

It would be helpful if you indicated what you expected to happen.

Bacterius
Bacterius

It would be helpful if you indicated what you expected to happen.

He wants them to be drawn in the render target as if the vertex coordinates passed were in normalized device coordinates (-1 to +1). The SlimDX framework has a nice tutorial by the way:

http://slimdx.org/tutorials/SimpleTriangle.php

Should be readily convertible to C++ with raw DirectX.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Infinity95
Infinity95

Ok, sorry for not replying but i solved it on my own. The problem was, that i had an incorrect input element description.

This is how it should be:


D3D11_INPUT_ELEMENT_DESC ied[] = 
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};

I accidentially had DXGI_FORMATR32G32B32A32_FLOAT for POSITION which is nonsense, because a position only has 3 values. This messed up my coordinates. Now it works like its supposed to.

"Errare humanum est, sed in errare perseverare diabolicum."

Topic Locked

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

Sign in to reply to this topic.