Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:04:03+00:00 2026-05-14T09:04:03+00:00

having troubles with the following line HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB)); it appears the CreateBuffer method

  • 0

having troubles with the following line

HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));

it appears the CreateBuffer method is having troubles reading &mVB. mVB is defined in box.h and looks like this

ID3D10Buffer* mVB;

Below is the code it its entirety. this is all files that mVB is in.

//Box.cpp
#include "Box.h"
#include "Vertex.h"
#include <vector>

Box::Box()
: mNumVertices(0), mNumFaces(0), md3dDevice(0), mVB(0), mIB(0)
{   
}

Box::~Box()
{
    ReleaseCOM(mVB);
    ReleaseCOM(mIB);
}

float Box::getHeight(float x, float z)const
{
    return 0.3f*(z*sinf(0.1f*x) + x*cosf(0.1f*z));
}

void Box::init(ID3D10Device* device, float m, float n, float dx)
{
    md3dDevice = device;
    mNumVertices = m*n;
    mNumFaces = 12;

    float halfWidth = (n-1)*dx*0.5f;
    float halfDepth = (m-1)*dx*0.5f;
    std::vector<Vertex> vertices(mNumVertices);

    for(DWORD i = 0; i < m; ++i)
    {
        float z = halfDepth - (i * dx);
        for(DWORD j = 0; j < n; ++j)
        {
            float x = -halfWidth + (j* dx);

            float y = getHeight(x,z);

            vertices[i*n+j].pos = D3DXVECTOR3(x, y, z);

            if(y < -10.0f)
                vertices[i*n+j].color = BEACH_SAND;
            else if( y < 5.0f)
                vertices[i*n+j].color = LIGHT_YELLOW_GREEN;
            else if (y < 12.0f)
                vertices[i*n+j].color = DARK_YELLOW_GREEN;
            else if (y < 20.0f)
                vertices[i*n+j].color = DARKBROWN;
            else
                vertices[i*n+j].color = WHITE;
        }
    }

    D3D10_BUFFER_DESC vbd;
    vbd.Usage = D3D10_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex) * mNumVertices;
    vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices;
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));

    //create the index buffer 

    std::vector<DWORD> indices(mNumFaces*3); // 3 indices per face

    int k = 0;

    for(DWORD i = 0; i < m-1; ++i)
    {
        for(DWORD j = 0; j < n-1; ++j)
        {
            indices[k]      = i*n+j;
            indices[k+1]    = i*n+j+1;
            indices[k+2]    = (i*1)*n+j;

            indices[k+3]    = (i*1)*n+j;
            indices[k+4]    = i*n+j+1;
            indices[k+5]    = (i*1)*n+j+1;

            k+= 6;
        }
    }

    D3D10_BUFFER_DESC ibd;
    ibd.Usage = D3D10_USAGE_IMMUTABLE;
    ibd.ByteWidth = sizeof(DWORD) * mNumFaces*3;
    ibd.BindFlags = D3D10_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA iinitData;
    iinitData.pSysMem = &indices;
    HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mIB));
}

void Box::Draw()
{
    UINT stride = sizeof(Vertex);
    UINT offset = 0;
    md3dDevice->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
    md3dDevice->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);
    md3dDevice->DrawIndexed(mNumFaces*3, 0 , 0);

}


//Box.h

#ifndef _BOX_H
#define _BOX_H
#include "d3dUtil.h"

Box.h

class Box {
public:

    Box();
    ~Box();

    void  init(ID3D10Device* device, float m, float n, float dx);
    void  Draw();
    float getHeight(float x, float z)const;

private:
    DWORD mNumVertices;
    DWORD mNumFaces;

    ID3D10Device* md3dDevice;
    ID3D10Buffer* mVB;
    ID3D10Buffer* mIB;
};

#endif

[EDIT]
Arguements being passed for m and n dx is

m = 129, n = 129, dx = 1.0f (they are all floats)

m and n stand for rows and columns perspectively. dx is the width and height.

Thanks again for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:04:03+00:00Added an answer on May 14, 2026 at 9:04 am

    If you want a pointer to the data array of a vector, you should use &vec[0]. If you use &vec it will give you a pointer to the vector object, which might contain all kinds management structures/… that have nothing to do with the data you inserted into the vector.

    The data itself is stored at continuous memory starting at &vec[0], so use that when you initialize your D3D structures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sorry, it should have been completely obvious from the beginning… May 14, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer List<Class3> all = c.SelectMany(c2 => c2).ToList(); May 14, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer Make sure that: You have specified the encoding type enctype="multipart/form-data"… May 14, 2026 at 7:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.