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

Started by
7 comments, last by Conny14156 11 years, 3 months ago

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.

Advertisement

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.

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 *'

post the code, otherwise can't help.


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;
}

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;
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?

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

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 >.<

This topic is closed to new replies.

Advertisement