Heightmap tutorials?
Any hood ones out there? Sorry for asking but I looked for them with google but I only found really crappy ones. I only need to know how to set up the index buffer for a 256*256 vertex buffer.
Have a look on my here: http://www.uniqsoft.co.uk/directx/
I hope this will help. (tutorials 3)
[edited by - robert_s on June 18, 2003 2:50:15 PM]
I hope this will help. (tutorials 3)
[edited by - robert_s on June 18, 2003 2:50:15 PM]
Have a look on my here: http://www.uniqsoft.co.uk/directx/
(tutorials 3)
I am trying to run through this tutorial but it keeps getting erros 31 C:\Documents and Settings\jeremy_king\Desktop\test2\main.cpp
`m_iNumOfVerticesZ'' undeclared (first use this function)
has any one elsa done these or can any one help
(tutorials 3)
I am trying to run through this tutorial but it keeps getting erros 31 C:\Documents and Settings\jeremy_king\Desktop\test2\main.cpp
`m_iNumOfVerticesZ'' undeclared (first use this function)
has any one elsa done these or can any one help
__int32 is used to declare integer variables. Just makes sure they're always 32 bits. you can replace it with int if you want.
Kingpinzs:
you should declare in you header file the following :
__int32 m_iNumOfVerticesX; // Number of vertices in the grid along x-axis
__int32 m_iNumOfVerticesZ; // Number of vertices in the grid along y-axis
__int32 m_iTotalNumOfVertices; // Total number of vertices 32*32
__int32 m_iTotalNumOfPrimitives;// Total number of primitives to draw
Just define how many vertices you want to have in your grid on X & Z. eg. 32 by 32 grid.
[edited by - robert_s on June 19, 2003 5:36:32 AM]
Kingpinzs:
you should declare in you header file the following :
__int32 m_iNumOfVerticesX; // Number of vertices in the grid along x-axis
__int32 m_iNumOfVerticesZ; // Number of vertices in the grid along y-axis
__int32 m_iTotalNumOfVertices; // Total number of vertices 32*32
__int32 m_iTotalNumOfPrimitives;// Total number of primitives to draw
Just define how many vertices you want to have in your grid on X & Z. eg. 32 by 32 grid.
[edited by - robert_s on June 19, 2003 5:36:32 AM]
Ok I change the variables to int but it wont display anything on the screen but a window
So what am I doing wrong if any one could help me I would be very happy. Please and thank you
#include <d3d8.h>#include <d3dx8.h>#include <stdio.h>#include <mmsystem.h>#include <stdlib.h>////////////////////////////////////////////////////////////////////////////////LPDIRECT3D8 gpD3D = NULL;LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;LPDIRECT3DVERTEXBUFFER8 m_pTerrVertexBuffer; // Terrain vertex buffer to hold vertices XYZ used to render triangles LPDIRECT3DINDEXBUFFER8 m_pTerrIndexBuffer; int m_iTotalNumOfVertices;int m_iTotalNumOfPrimitives;int m_iNumOfVerticesZ = 32 ; int m_iNumOfVerticesX = 32 ; //////////////////////////////////////////////////////////////////////////////// // Denfines my own custom D3D vertex format used by the vertex buffer struct TERRAINVERTEX { float posX, posY, posZ; // Vertex XYZ position }; #define D3DFVF_TERRAINVERTEX (D3DFVF_XYZ) //////////////////////////////////////////////////////////////////////////////////Initialisetion of d3d/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////HRESULT InitialiseD3D(HWND hWnd){if( NULL == ( gpD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) ){return E_FAIL;}D3DDISPLAYMODE d3ddm;if(FAILED(gpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))){return E_FAIL;}D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));d3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;d3dpp.BackBufferFormat = d3ddm.Format;d3dpp.EnableAutoDepthStencil = TRUE ; d3dpp.AutoDepthStencilFormat = D3DFMT_D16;if(FAILED(gpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice))){return E_FAIL;}//g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);//g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);g_pD3DDevice->SetRenderState(D3DRS_AMBIENT, 255);return S_OK;}////////////////////////////////////////////////////////////////////////////////HRESULT FeedVertexBuffer(){ TERRAINVERTEX* m_pVertices; if( SUCCEEDED( m_pTerrVertexBuffer->Lock( 0, 0, (BYTE**)&m_pVertices, 0 ) ) ) { MessageBox(NULL, " FeedVertex" , "error",MB_OK|MB_ICONEXCLAMATION); return S_OK;} D3DXVECTOR3 NormalVector; TERRAINVERTEX* pVertex; int iVertexBuffOffset = 0; int terrScale = 8; // loop as many times as there are vertices along x & Z axes calculating the coordinates for each terrain vertex (X,Y,Z) and store // in VB in a linear fashion. NOTE: the 2D regular grid (X,Y) is being transformed into 3D (X,Y,Z) terrain grid with height equal to 0. for (int z = 0; z < m_iNumOfVerticesZ; z++) //vertical rows { for (int x = 0; x < m_iNumOfVerticesX; x++) //horizontal rows { iVertexBuffOffset = x +( z * m_iNumOfVerticesX); pVertex = &( m_pVertices[ iVertexBuffOffset ] ); // 1. Calculate each terrain vertex coordinates pVertex->posX = (float)x * terrScale; pVertex->posY = 0.0; //constant terrain height pVertex->posZ = (float)z * terrScale; } } m_pTerrVertexBuffer->Unlock(); return S_OK;}////////////////////////////////////////////////////////////////////////////////HRESULT CreateTerrainIndexBuffer(){ int iTotalNumOfIndices; WORD *pIndices; UINT Index; // Calculate the number of indices iTotalNumOfIndices = ((m_iNumOfVerticesX * 2) + 2) * (m_iNumOfVerticesZ - 1); // Create the Index Buffer if( FAILED( g_pD3DDevice->CreateIndexBuffer( iTotalNumOfIndices *sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pTerrIndexBuffer ) ) ) return E_FAIL; if( FAILED( m_pTerrIndexBuffer->Lock( 0, // Fill from start of the buffer. 0, // Size of the data to load. (BYTE**)&pIndices, // Returned index data. 0 ) ) ) // Send default flags to the lock. return E_FAIL; int IndexOffset = 0; // Use the following equation to get the number of primitives to draw m_iTotalNumOfPrimitives = ( (m_iNumOfVerticesX + 1) * (m_iNumOfVerticesZ - 1) * 2 ) - 2; // Fill in the index buffer with vertex ID linking the vertex buffer for( int z = 0; z < m_iNumOfVerticesZ-1; z++ ) { for( int x = 0; x < m_iNumOfVerticesX; x++ ) { Index = x + ( z * m_iNumOfVerticesX ); pIndices[IndexOffset] = (WORD)Index; IndexOffset++; Index = x +( (z+1) * m_iNumOfVerticesX ); pIndices[IndexOffset] =(WORD)Index; IndexOffset++; } //Place in copy of previous one pIndices[IndexOffset] =(WORD)Index; IndexOffset++; //Place in first one for next row Index = 0 + ( (z+1) * m_iNumOfVerticesX ); pIndices[IndexOffset] = (WORD)Index; IndexOffset++; } m_pTerrIndexBuffer->Unlock(); return S_OK;} //////////////////////////////////////////////////////////////////////////////////the Render////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void Render(){D3DXMATRIX matView; D3DXMATRIX TranslationMatrix; g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); // What ever this does it is important if(SUCCEEDED(g_pD3DDevice->BeginScene())){ g_pD3DDevice->SetStreamSource( 0, m_pTerrVertexBuffer, sizeof(TERRAINVERTEX) ); g_pD3DDevice->SetVertexShader( D3DFVF_TERRAINVERTEX ); g_pD3DDevice->SetIndices( m_pTerrIndexBuffer, 0 ); //Renders the specified geometric primitive, based on indexing into an array of vertices. g_pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP , 0, m_iTotalNumOfVertices, 0, m_iTotalNumOfPrimitives);g_pD3DDevice->EndScene();}g_pD3DDevice->Present(NULL, NULL, NULL, NULL);}//////////////////////////////////////////////////////////////////////////////////shuts down d3d////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void CleanUp(){if (g_pD3DDevice !=NULL){g_pD3DDevice->Release();g_pD3DDevice = NULL;}if(gpD3D != NULL){gpD3D->Release();gpD3D = NULL;}}////////////////////////////////////////////////////////////////////////////////LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){ switch( msg ) { case WM_DESTROY: PostQuitMessage( 0 ); return 0;break; case WM_KEYUP: switch (wParam) { case VK_ESCAPE: DestroyWindow(hWnd); return 0; break; } } return DefWindowProc( hWnd, msg, wParam, lParam );}//////////////////////////////////////////////////////////////////////////////////Win Main//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ){ // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "D3D Tutorial", NULL }; RegisterClassEx( &wc ); // Create the application''s window HWND hWnd = CreateWindow( "D3D Tutorial", "My window", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL,(HINSTANCE)wc.hInstance, NULL );//////////////////////////////////////////////////////////////////////////////// //The Game Loop///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if( SUCCEEDED( InitialiseD3D( hWnd ) ) ) { MessageBox(NULL, "Initd3d worked" , "error",MB_OK|MB_ICONEXCLAMATION); // Create the scene geometry ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); MSG msg; ZeroMemory(&msg, sizeof(msg)); while(1) { if (PeekMessage( &msg, NULL, 0, 0,PM_REMOVE ) ) { if(msg.message == WM_QUIT) break; TranslateMessage( &msg ); DispatchMessage( &msg ); } else Render(); } } CleanUp(); UnregisterClass( "D3D Tutorial", (HINSTANCE) wc.hInstance ); return 0;}
So what am I doing wrong if any one could help me I would be very happy. Please and thank you
In your init() you should make the m_iTotalNumOfVertices equal to:
m_iTotalNumOfVertices = m_iNumOfVerticesZ * m_iNumOfVerticesZ;
because your render needs it here:
g_pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP , 0, -->>m_iTotalNumOfVertices<<--, 0, m_iTotalNumOfPrimitives);g_pD3DDevice->EndScene();
I hope this is it!
m_iTotalNumOfVertices = m_iNumOfVerticesZ * m_iNumOfVerticesZ;
because your render needs it here:
g_pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP , 0, -->>m_iTotalNumOfVertices<<--, 0, m_iTotalNumOfPrimitives);g_pD3DDevice->EndScene();
I hope this is it!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement