Jump to content

  • Log In with Google      Sign In   
  • Create Account

How do I pass D3d11Device into a parameter correct?[SOLVE]!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Conny14156   Members   -  Reputation: 265

Like
0Likes
Like

Posted 25 December 2012 - 07:43 PM

Hi, This maybe is a stupid question but, I have a function like this Object::InitBuffer(ID3D11Device* D3d11Device) And I need to pass the D3d11Device, But when I do it like Object Test; Test.InitBuffer(D3d11Device); "nothing" happend, more like I see nothing >.<. I think it has something to do with that am just passing "value" and not the "whole" "object" so my program sets the setting onto another D3d11Device. But when I tried something like Test.InitBuffer(*D3d11Device); or Test.InitBuffer(&D3d11Device); I get errors :/ So my simple question is. Is the first passing parameter the correct way to do it? if not is there another way I should do it? if so what would that be? if the first parameter is correct than its something wrong with my function but I tried to do it "normal" (By having the function inside the same cpp file) than It worked as it suppose to be.



Sponsor:

#2 regonaros   Members   -  Reputation: 115

Like
1Likes
Like

Posted 25 December 2012 - 08:25 PM

You're supposed to add the pointer address of the Direct3D11 device.

 

So simply, first initialize your device, 

 


 

ID3D11Device* d3ddev = NULL;   // the pointer to the device class

 

 

in this case, in the parameter you write,

 


 

&d3ddev

 

 

hope this helps.


Edited by regonaros, 25 December 2012 - 08:34 PM.


#3 Conny14156   Members   -  Reputation: 265

Like
0Likes
Like

Posted 25 December 2012 - 08:51 PM

Seems like I miss phrased my question kinda bad >.<

 

I already have all my device and DeviceContext initialized, but When I try to pass the device with &, than I get a error like this

cannot convert parameter 1 from 'ID3D11Device **' to 'ID3D11Device *' 



#4 regonaros   Members   -  Reputation: 115

Like
0Likes
Like

Posted 25 December 2012 - 08:53 PM

post the code, otherwise can't help.



#5 Conny14156   Members   -  Reputation: 265

Like
0Likes
Like

Posted 25 December 2012 - 09:00 PM

Here the parts that gives me the error ;(
If you need any other piece of code just tell me :3




void DrawObject()
{
Test.InitBuffer(&D3d11Device);
Test.SetBuffer(&D3d11DevCon);
Test.DrawObject(&D3d11DevCon);
}

// ^ That code is in a seperate cpp file compared to the code below


bool Object::InitBuffer(ID3D11Device* D3d11Device)
{
	
	Vertex* Vertices;

	Vertices = new Vertex[Model.VertexCount];
	Vertex v[] =
	{
		Vertex( 0.0f, 0.5f, 0.5f ),
		Vertex( 0.5f, -0.5f, 0.5f ),
		Vertex(-0.5f, -0.5f, 0.5f ),
	};

	//Create the vertex buffer Describer and describ it
	D3D11_BUFFER_DESC vertexBufferDesc;
	ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );

	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof( Vertex ) * 3;
	//vertexBufferDesc.ByteWidth = sizeof( Vertex ) * Model.VertexCount;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA vertexBufferData; 

	ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
	vertexBufferData.pSysMem = v;
	D3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &Buffer.VertexBuffer);
	
	
	return true;
}
bool Object::SetBuffer(ID3D11DeviceContext* D3d11DevCon)
{
	//Set the vertex buffer
	UINT stride = sizeof( Vertex );
	UINT offset = 0;
	D3d11DevCon->IASetVertexBuffers( 0, 1, &Buffer.VertexBuffer, &stride, &offset );
	D3d11DevCon->IASetIndexBuffer(Buffer.IndexBuffer,DXGI_FORMAT_R32_UINT,0);
	return true;
}
bool Object::DrawObject(ID3D11DeviceContext* D3d11DevCon)
{
	D3d11DevCon->DrawIndexed(3,0,0);
	return true;
}


#6 regonaros   Members   -  Reputation: 115

Like
0Likes
Like

Posted 25 December 2012 - 09:17 PM

I need to see this code

 

//--------------------------------------------------------------------------------------
// Global Variables
//--------------------------------------------------------------------------------------
HINSTANCE               g_hInst = NULL;
HWND                    g_hWnd = NULL;
D3D_DRIVER_TYPE         g_driverType = D3D_DRIVER_TYPE_NULL;
D3D_FEATURE_LEVEL       g_featureLevel = D3D_FEATURE_LEVEL_11_0;
ID3D11Device*           g_pd3dDevice = NULL;
ID3D11DeviceContext*    g_pImmediateContext = NULL;
IDXGISwapChain*         g_pSwapChain = NULL;
ID3D11RenderTargetView* g_pRenderTargetView = NULL;


#7 Conny14156   Members   -  Reputation: 265

Like
0Likes
Like

Posted 25 December 2012 - 09:28 PM

Edit:
FUUU


#include <d3d11.h>
#include <D3DX11.h>
#include <D3DX10.h>
#include <DxErr.h>
#include <xnamath.h>

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "D3DX11.lib")
#pragma comment(lib, "D3DX10.lib")
#pragma comment(lib, "DXErr.lib")


#include "ObjectH.h"
#include "WindowsHandlerH.h"

IDXGISwapChain* SwapChain;
ID3D11Device* D3d11Device;
ID3D11DeviceContext* D3d11DevCon;
ID3D11RenderTargetView* RenderTargetView;
ID3D11DepthStencilView* DepthStencilView;
ID3D11Texture2D* DepthStencilBuffer;


D3DXCOLOR bgColour(0.0f,0.0f,0.0f,0.0f);

ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob* VSBuffer;
ID3D10Blob* PSBuffer;
ID3D11InputLayout* InputLayout;

D3D11_INPUT_ELEMENT_DESC Layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT LayoutElement = ARRAYSIZE(Layout );
Object Test;

This one?

Edited by Conny14156, 25 December 2012 - 09:30 PM.


#8 regonaros   Members   -  Reputation: 115

Like
0Likes
Like

Posted 25 December 2012 - 09:41 PM

I think the problem is you need to put the Draw Object function underneath the init buffer function. try that.



#9 Conny14156   Members   -  Reputation: 265

Like
0Likes
Like

Posted 25 December 2012 - 09:49 PM

I GOT IT TO WORK!

The problem was I used 

D3d11devCon->DrawIndexed INSTEAD of just simply ->Draw

 

I had forgot that I havent set up any Index buffer yet and only setted up a normal vertex buffer >.>. >.< 

so stupid of me.

and I would't realize this stupid misstake if u didnt tell me to rearrange the order of my object function, that was when I notice I had used DrawIndex instead of draw >.<

THANKS MAN! can finnaly keep moving on >.<






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS