Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 2124 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, 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.

Share this post

Link to post
Share on other sites

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,






hope this helps.

Edited by regonaros

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites
Here the parts that gives me the error ;(
If you need any other piece of code just tell me :3

void DrawObject()

// ^ 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 );
	return true;
bool Object::DrawObject(ID3D11DeviceContext* D3d11DevCon)
	return true;

Share this post

Link to post
Share on other sites

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;

Share this post

Link to post
Share on other sites

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

UINT LayoutElement = ARRAYSIZE(Layout );
Object Test;

This one? Edited by Conny14156

Share this post

Link to post
Share on other sites


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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!