• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tim Lawton

Why won't my grid appear

3 posts in this topic

Hey there,

recently tried to implement a 100x100 grid to my 3D Scene, although I believe I've done everything correctly the grid isn't appearing?

Land.h
[CODE]
//--------------------------------------------------\\
// Land.h \\
// Encapsulates the model data and rendering \\
// functionality to draw a 100x100 grid \\
//--------------------------------------------------\\
#ifndef _LAND_H
#define _LAND_H
#include <D3D11.h>
#include <D3DX10math.h>
#define LAND_WIDTH 100;
#define LAND_HEIGHT 100;
class Land
{
private:
struct VertexType //Struct to hold variables for the grid
{
D3DXVECTOR3 position;
D3DXVECTOR4 color;
};
public:
Land();
~Land();
bool Init(ID3D11Device*);
void Render(ID3D11DeviceContext*);
void Shutdown();
int GetIndexCount();
private:
bool InitBuffers(ID3D11Device*);
void RenderBuffers(ID3D11DeviceContext*);
void ShutdownBuffers();
int g_landWidth;
int g_landHeight;
int g_vertexCount;
int g_indexCount;
ID3D11Buffer *g_vertexBuffer, *g_indexBuffer;
};
#endif
[/CODE]

Land.cpp
[CODE]
//--------------------------------------------------\\
// Land.cpp \\
// Encapsulates the model data and rendering \\
// functionality to draw a 100x100 grid \\
//--------------------------------------------------\\
#include "Land.h"
/* Constructor & Deconstructor */
Land::Land()
{
g_vertexBuffer = 0;
g_indexBuffer = 0;
}
Land::~Land(){}
/* Initialize the land class, set the width and height of the land and initialize the buffers */
bool Land::Init(ID3D11Device* device)
{
bool r;
g_landWidth = LAND_WIDTH;
g_landHeight = LAND_HEIGHT;
r = InitBuffers(device);
if(!r)
{
return false;
}
return true;
}
/* Initialize the vertex and index buffers used to hold the grid data, forming 4 lines */
bool Land::InitBuffers(ID3D11Device* device)
{
VertexType* vertices;
unsigned long* indices;
int index, i, j;
float posX, posZ;
D3D11_BUFFER_DESC vertexBD, indexBD;
D3D11_SUBRESOURCE_DATA vertexData, indexData;
HRESULT r;
//Calculate vertices in grid
g_vertexCount = (g_landWidth - 1) * (g_landHeight - 1) * 8;
//Set index count
g_indexCount = g_vertexCount;
//Create vertex array
vertices = new VertexType[g_vertexCount];
if(!vertices)
{return false;}
//Create the index array
indices = new unsigned long[g_indexCount];
if(!indices)
{return false;}
//Load index into the vertex array
index = 0;
//Load the vertex and index arrays with the grid data
for(j = 0; j<(g_landHeight-1); j++)
{
for(i = 0; i < (g_landWidth-1); i++)
{
// LINE 1
// Upper left.
posX = (float)i;
posZ = (float)(j+1);
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// Upper right.
posX = (float)(i+1);
posZ = (float)(j+1);
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// LINE 2
// Upper right.
posX = (float)(i+1);
posZ = (float)(j+1);
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// Bottom right.
posX = (float)(i+1);
posZ = (float)j;
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// LINE 3
// Bottom right.
posX = (float)(i+1);
posZ = (float)j;
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// Bottom left.
posX = (float)i;
posZ = (float)j;
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// LINE 4
// Bottom left.
posX = (float)i;
posZ = (float)j;
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
// Upper left.
posX = (float)i;
posZ = (float)(j+1);
vertices[index].position = D3DXVECTOR3(posX, 0.0f, posZ);
vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
indices[index] = index;
index++;
}
}
//Setup the description of the vertex buffer
vertexBD.Usage = D3D11_USAGE_DEFAULT;
vertexBD.ByteWidth = sizeof(VertexType) * g_vertexCount;
vertexBD.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBD.CPUAccessFlags = 0;
vertexBD.MiscFlags = 0;
vertexBD.StructureByteStride = 0;
vertexData.pSysMem = vertices;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;
//Create the vertex buffer
r = device->CreateBuffer(&vertexBD, &vertexData, &g_vertexBuffer);
if(FAILED(r))
{return false;}
//Setup the descrption of the index buffer
indexBD.Usage = D3D11_USAGE_DEFAULT;
indexBD.ByteWidth = sizeof(unsigned long) * g_indexCount;
indexBD.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBD.CPUAccessFlags = 0;
indexBD.MiscFlags = 0;
indexBD.StructureByteStride = 0;
indexData.pSysMem = indices;
indexData.SysMemPitch = 0;
indexData.SysMemSlicePitch = 0;
//Create index buffer
r = device->CreateBuffer(&indexBD, &indexData, &g_indexBuffer);
if(FAILED(r))
{return false;}
//Release the arrays
delete [] vertices;
vertices = 0;
delete [] indices;
indices = 0;
return true;
}
/* Call the RenderBuffer function and put on the graphics pipeline */
void Land::Render(ID3D11DeviceContext* deviceContext)
{
RenderBuffers(deviceContext);
return;
}
/* Render Buffers lists the grid onto the graphics pipeline for rendering */
void Land::RenderBuffers(ID3D11DeviceContext* deviceContext)
{
unsigned int stride;
unsigned int offset;
stride = sizeof(VertexType);
offset = 0;
deviceContext->IASetVertexBuffers(0, 1, &g_vertexBuffer, &stride, &offset);
deviceContext->IASetIndexBuffer(g_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); //Make the grid a list of lines from each vertex
return;
}
/* Return the variables we are using */
int Land::GetIndexCount()
{return g_indexCount;}
/* Shutdown and release the objects we have used */
void Land::ShutdownBuffers()
{
if(g_indexBuffer)
{
g_indexBuffer->Release();
g_indexBuffer = 0;
}
if(g_vertexBuffer)
{
g_vertexBuffer->Release();
g_vertexBuffer = 0;
}
return;
}
void Land::Shutdown()
{
ShutdownBuffers();
return;
}
[/CODE]

Graphics.h
[CODE]
Land* land;
[/CODE]

Graphics::Init()
[CODE]
/* LAND */
land = new Land;
if(!land)
{return false;}
r = land->Init(d3d->GetDevice());
if(!r)
{MessageBox(hwnd, "Couldn't load Land Object!", "Error!", MB_OK);
return false;}
return true;
[/CODE]

Start of Graphics::Render()
[CODE]
/* BEGIN SCENE */
d3d->BeginScene(0.0f, 0.0f, 0.0f, 1.0f); //Clear buffer - RGBA
/* CAMERA */
camera->Render(); //Render Camera
d3d->GetWorldMatrix(worldMatrix); //...
camera->GetViewMatrix(viewMatrix); //Setup Camera & Matrixes
d3d->GetProjectionMatrix(projectionMatrix); //...
d3d->GetOrthoMatrix(orthoMatrix); //...
/* LAND */
land->Render(d3d->GetDeviceContext());
[/CODE]

I believe I've done everything right, there isn't any errors, so why is it not appearing?

Thanks
0

Share this post


Link to post
Share on other sites
It doesn't look like you're issuing a draw call in your RenderBuffers() method. You need to add:

[CODE]
deviceContext->DrawIndexed(indexbufferdesc.ByteWidth/sizeof(indexbuffersizetype),0,0);
[/CODE]

At the end of your RenderBuffers method (obviously you'll also need a reference to a descriptor for your index buffer that you can get from indexbuffer->GetDesc()).
0

Share this post


Link to post
Share on other sites
Thanks for the quick reply, but that wasn't it :( my other classes which render have very similar functions and they seem to work. I'm going to keep looking, probably something in the Syntax
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0