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

GhostfromTexas

Members
  • Content count

    22
  • Joined

  • Last visited

Community Reputation

107 Neutral

About GhostfromTexas

  • Rank
    Member
  1. [quote name='gekko' timestamp='1305488532' post='4811188'] The quick answer is use another tool, like Visual Leak Detector and it will give you the location of all your leaks in the output window when the program exists. [/quote] I looked into VLD but couldn't get it to give me anymore information than I already knew... But however I did figure out a way to make CRT work better for me thanks from some help from someone.. global header. either a forced header in visual studio or one that's included everywhere in the project by some sort of method. In Visual Studio it's under Project Settings -> c++ -> Advanced -> Forced Include File (just list the file there without quotes. This assumes you own file, not a standard library include) //--- CRT debug header (must be last) #if defined(DEBUG) | defined(_DEBUG) #include <crtdbg.h> #define new new( _NORMAL_BLOCK, __FILE__, __LINE__) #pragma warning(disable : 4345) //this warning is when using empty () when allocating a new object. Only happens when allocating memory with this debug option, so disabling it #endif first line in main: #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)|_CRTDBG_LEAK_CHECK_DF); //_CrtSetBreakAlloc(100); //break on a specific memory allocation #endif This allowed visual studio to output file and line number for the leaked allocation. The output looks something like this now: c:\users\user\desktop\project-folder\files\file.cpp(392) : {487594} normal block at 0x087F1500, 456 bytes long. Data: < fff?o : > CD CD CD CD 66 66 66 3F 6F 12 03 3A CD CD CD CD {487590} normal block at 0x087F14B8, 8 bytes long. Data: < > 1C 13 7F 08 00 00 00 00 c:\users\user\desktop\project-folder\files\file.cpp(275) : {487585} normal block at 0x087F12E0, 100 bytes long. Data: < { > 20 14 7B 08 00 00 00 00 00 00 00 00 00 00 00 00 c:\users\user\desktop\project-folder\files\file.cpp(133) : {487578} normal block at 0x087E5038, 96 bytes long. Data: < ;& > B8 3B 26 02 01 00 00 00 00 00 00 00 02 00 00 00 So even though i was getting random leaks, this method allow me to figured out how to track them down much easier. Hopefully this helps some others in the future on how to fix it. Thanks to Ghaleon from #gamedev on the #efnet IRC for this. He's the one that came up with the code
  2. I am having a hard time tracking down some memory leaks in my program.. I am using the CRT visual c++ debugger, which is great for finding memory leaks that have consistant allocation numbers. But these memory leaks have different allocation numbers each time the program is run, so it's quite difficult to find what allocation is causing the leak. Is there a way to log all memory allocations so I can go back later and figure out which one specifically happened for the particular time I ran the program? Or some better method of solving the memory leak issue? Thanks in advance...
  3. I ended up making this for my project since I know I have a lot of colors that are randomly defined by name, so I figured I'd spend a few hours and make a really large compilation of a lot of colors that could be used throughout my project. The header has #defines and const variables to use. Just block comment out the section you don't want. http://www.cameronferguson.net/UTILSColors.h feel free to do with this what you want.. I don't care for credit or anything, just a list I thought I'd share. The colors came from wikipedia's list of colors. So they are named accordingly there with sample colors of what it looks like. The link is in the header comment of the file. Enjoy! GhostfromTexas
  4. I've done a lot of digging through the University of Google but haven't found anything so far. I am managing a fairly large project at the moment and our compile times do get quite large. Right now depending on the way I want to compile, I have go to in and change several options under my debug configuration to swap between doing incremental builds and multi-processor builds. By doing a multi-processor build (/MP), then incremental build option (/Gm) must be turned off. Which is fine, but I am looking for a way to easily swap between different build options under the SAME configuration. I don't want a new configuration.. i want this to all work under debug mode. Preferably, I'd like to be able to create a toolbar button or keyboard shortcut that will build the project differently depending on which button I hit. Does anyone know of the ability to do this or an addin that will help? I am using Visual Studio 2010 Ultimate Edition Thanks for your time!
  5. Quote:Original post by Corefanatic 3D Math Primer for Graphics and Game Development by Fletcher Dunn and Ian Parberry has a good chapter on Quaternions. Yeah you are the 2nd person that's recommended that book... problem is that I have to order it... was hoping for something I could run out and grab today.. but it's looking like I might have to order it.
  6. Hey guys. I am starting to look using quaternion to help with some rotation algorithms... Specifically I am wanting to take an object pointing in 1 direction, and rotate it to point another direction. Are there any good popular books that have great examples and tutorials on using quaternions in DirectX? I am trying to find one I can go readily grab at a local book store in the DFW area... Thanks! GFT!
  7. Quote:Original post by Adam_42 It's possible you're running out of video memory. Perfhud can tell you for sure. As a simple test you could try using D3DXCreateTextureFromFileEx() to load your textures and pass D3DFMT_DXT5 as the format of your textures. That will cut their size in video ram down significantly at the cost of extra load time. Ideally you'd want to use D3DFMT_DXT1 for textures with no alpha channel, and also convert them offline with the texture tool that comes with the SDK into .dds files. Even if you aren't running out of memory, the smaller textures will be quicker to upload to video ram which could help. Ok i converted over to use this function and low and behold, the lag problem is gone! I do notice, however, it does take longer to load up initially (about an extra 5-6 seconds) but it's worth the improvement that I am seeing in game... could you possibly explain to me exactly what the format does, and what are the other similar formats like D3DFMT_DXT3, D3DFMT_DXT4, etc?
  8. Quote:Original post by mhagain Are you using Windows Vista or 7 (with a WDDM driver) and does this happen when you run it in the debugger? This problem is happening across the board on several systems.. ranging from Windows XP 32bit to Windows 7 64bit.. and pretty much everything in between. So it's not just Windows Vista or Windows 7 Related @ ET3D: I decided to take what you said a step further, and I simply commented out the call where I set the texture to a my shader handle when I updated the models. Obviously now my models are black and not textured, but the problem is now gone when I do that. Is 1mb too large for a texture? Could it be something in my shader? Is there like an allocated amount of video memory that I might be filling up when I do this?
  9. Thanks for your response. I have to admit when I first read your possibility for the solution I got kind of excited because that made 100% total sense for what I was doing... My models have around 1mb textures each for them and the models have quite the UV layout on them for these textures. I did call PreLoad() on all the textures for the models after I loaded them, but alas the problem didn't correct itself. best guess I've had so far.. so again thanks for the response. Got any other ideas?
  10. *Update* I went through using the DirectX Control panel to debug possible errors and warnings that were popping up. I had some issues that I cleared up with it, however when it comes to the lag spike issue itself, there are no warnings or errors that are popping up when it happens.
  11. Ok let me try to explain this odd problem as much and as simply as possible, because it does not seem to be a simple problem. The project I am working on is a basic DX9 game for school. It's our Junior level applied development project. We are doing nothing insanely fancy or out of the ordinary so keep that in mind as I explain the issue. The summary of the problem is that when I draw models for the first time during the run-time of the game.. there is a small lag issue. After a particular model has been drawn the first time, drawing it again there is 0 lag. Let me explain the basic setup. I am not loading the .X files when I spawn them in the game. They are loaded at the beginning and stored in memory. Whenever I spawn an entity in the game, it's just accepting a pointer to already loaded model data and simply just draws what's in memory. I made a basic profiler using the difference of the GetTickCount() method before and after certain areas to try and find the actual spike. I found the spike directly around the calls: gd3dDevice->EndScene(); gd3dDevice->Present(0, 0, 0, 0); The spike does not come from anywhere that handles setting up drawing the objects to the back buffer.. it's only when I go to present that buffer that the issue pops up. I am using D3DPOOL_MANAGED for my loading on the areas where that's set. Also, this problem happens on multiple computers of all different types of video cards, processors, driver versions etc. It's not just my computer or my drivers or my gfx card. This problem also just spawned recently. But I have 0 idea what might have been changed to cause this, I have gone back to older versions I have saved, and the problem doesn't exists, but where it counts that I can find, I don't see anything in the core drawing that would have caused it. I will post any code that is requested. I have 0 idea where to even consider looking so I have no idea what I would need to post for you guys to look at. I just know these key things. The problem lies when presenting the back buffer The problem does not happen when drawing to the shader The problem only happens when a model is drawn for the first time during runtime The problem is gone for that particular model once it has been drawn once I have also tried to draw the mesh data's subset during the load time for each of those models that cause the issue to see if drawing it once would eliminate the issue like that, and it does not. If you got any questions.. want to see any part of my code.. or have an idea you want me to try let me know! Thanks, GFT *Update* I went through using the DirectX Control panel to debug possible errors and warnings that were popping up. I had some issues that I cleared up with it, however when it comes to the lag spike issue itself, there are no warnings or errors that are popping up when it happens. [Edited by - GhostfromTexas on August 16, 2010 11:51:30 PM]
  12. I appreciate the responses guys! I did find out one thing that makes my FPS increase significantly. I got rid of the multiple BeginPass and EndPass calls for each tile. I found out while doing some model imports from my book that there is a handy little method in an ID3DXEffect called "CommitChanges" that allows me to have a single BeginPass and EndPass for all of my tiles. However, I am still calling gd3dDevice->DrawIndexedPrimitive(...) for each tile and I know this should be able to optimized as well, but at least I've got another method of ID3DXEffect under my belt! So my new drawing method for my tile class now looks like this: void Tile::drawGrid() { /******************** ** START TILE DRAW ** ********************/ gd3dDevice->SetStreamSource(0, Tile::m_VertexBuffer, 0, sizeof(VertexPNT)); gd3dDevice->SetIndices(Tile::m_IndexBuffer); gd3dDevice->SetVertexDeclaration(VertexPNT::Decl); //gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); gd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); HR(m_sFX->SetTechnique(m_hTech)); Tile::m_sFX->SetValue(m_hLightVecW, &m_xv3LightVecW, sizeof(D3DXVECTOR3)); Tile::m_sFX->SetValue(m_hDiffuseMtrl, &m_xcDiffuseMtrl, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hDiffuseLight, &m_xcDiffuseLight, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hAmbientMtrl, &m_xcAmbientMtrl, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hAmbientLight, &m_xcAmbientLight, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hSpecularLight, &m_xcSpecularLight, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hSpecularMtrl, &m_xcSpecularMtrl, sizeof(D3DXCOLOR)); Tile::m_sFX->SetFloat(m_hSpecularPower, m_fSpecularPower); UINT numPasses = 0; Tile::m_sFX->Begin(&numPasses, 0); for(UINT i = 0; i < numPasses; ++i) { Tile::m_sFX->BeginPass(i); for(int j = 0; j < Tile::m_vTileList.size(); j++) { D3DXMATRIX wvp = (*Tile::m_vTileList[j]->getWorld()) * DXCI->getView() * DXPI->getProj(); Tile::m_sFX->SetMatrix(Tile::m_hWVP, &wvp); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, Tile::m_vTileList[j]->getWorld()); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); Tile::m_sFX->SetMatrix(m_hWorldInvTrans, &worldInvTrans); Tile::m_sFX->SetTexture(m_hTex, Tile::m_vTileList[j]->getCurrentTexture()); Tile::m_sFX->SetMatrix(m_hWorld, Tile::m_vTileList[j]->getWorld()); gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12); Tile::m_sFX->CommitChanges(); } Tile::m_sFX->EndPass(); } Tile::m_sFX->End(); }
  13. Quote:Original post by GregMichael What are the rotations for each tile...are they arbitary or in 90 degree steps ? 90 degree steps
  14. Quote:Original post by Dom_152 Sounds like what you are after is instancing. The idea is that you would have a vertex and an index buffer with all of your tile vertices and indices in it and assign it to one input stream. You then create a buffer that holds the transformations for each individual tile and assign that to a second input stream. By setting the instance data (The transformations) to only be changed every 4 vertices you can use your vertex shader to access the same instance data for all 4 vertices for each tile. This effectively allows you to draw all of your tiles in a single call whilst allowing each discrete tile mesh to access unique instance data. I believe D3D11 has specific creation flags for input data to allow you to distinguish between vertex and instance data. But you're using Direct3D 9 so I don't think that will be available to you so you'd have to set it up manually. I think I understand what you are talking about, I've also had another person explain something similar, but I am still confused on the approach to do it. I don't get how I take the individual tiles and actually go through the process of putting them all in a single vertex and index buffer, while still allowing me to dynamically say which tile has which rotation and which tile has which texture...
  15. I am learning how to use Vertex and Index buffers with shaders. I am still very new the concept and I am working on a big project course atm. Basically I have a bunch of tile grid that is 20x15 in size. The tiles depending on what level we load is going to support 1 of 3 different textures. The project is a basic tower defense demonstration. So the tile will either have a Path Straight piece, a Path corner piece, or a plain grass/ground piece. The corner and straight piece will need to be rotated depending obviously which way the level is designed. Here is the thing. I have all of this working and displaying the way I want it. (minus the rotation at the moment but I know how I am going to do that). Each tile has their own world matrix to handle the position and rotation of the tile. Right now I am drawing each of the 300 tiles one by one and because of this my FPS has dropped significantly. I know this is not the way I need to do it, but I am completely lost how I should approach revising this the easiest way. I've heard that I can do everything from combining objects together right before drawing, to building the vertex buffers and index buffers together... I am looking for something that's going to be much more efficient than my approach, but at the same time is simple enough for me to understand, realize again that I am very new to this concept and still learning DirectX. Here is my Tile class (which is also my grid class) This tile class has a bunch of static methods to work 20x15 grid aspect, as well as it also being used to create Tile objects to hold each tile's properties (world matrix, pointer to texture, etc..) Here is my header file: //Tile.h - Used for holding information about each tile. #ifndef TILE_H #define TILE_H #include <d3dx9.h> #include "Vertex.h" #include "DXCamera.h" #include "DXProjection.h" enum TextureType { //towers TT_TileGrass, TT_TilePathStraight, TT_TilePathCorner, }; class Tile { public: //Constructors Tile(int id); ~Tile(); bool occupied; D3DXVECTOR3* getPos(); D3DXMATRIX* getWorld(); IDirect3DTexture9* getCurrentTexture(); int getTextureType(); int getRotationType(); void setTexture(int textureType); private: void generateWorldMatrix(); D3DXVECTOR3 m_xv3Pos; D3DXMATRIX m_m4x4World; IDirect3DTexture9* mp_tCurrentTexture; //pointer to the current texture of that tile int m_iTextureType; int m_iRotationType; int m_iTileID; //static methods and variables public: static void initialize(); static void generateGrid(); static void release(); static void onLostDevice(); static void onResetDevice(); static void drawGrid(); static bool SETUP_VARIABLE; static bool SETUP_FUNCTION(); private: static vector<Tile*> m_vTileList; //static method calls static void buildIndexBuffer(); static void buildVertexBuffer(); static void buildFX(); static void buildTileBuffers(); //Buffer Member Variables static IDirect3DIndexBuffer9* m_IndexBuffer; static IDirect3DVertexBuffer9* m_VertexBuffer; //FX static ID3DXEffect* m_sFX; //Handles static D3DXHANDLE m_hTech; static D3DXHANDLE m_hWVP; static D3DXHANDLE m_hWorldInvTrans; static D3DXHANDLE m_hLightVecW; static D3DXHANDLE m_hDiffuseMtrl; static D3DXHANDLE m_hDiffuseLight; static D3DXHANDLE m_hAmbientMtrl; static D3DXHANDLE m_hAmbientLight; static D3DXHANDLE m_hSpecularMtrl; static D3DXHANDLE m_hSpecularLight; static D3DXHANDLE m_hSpecularPower; static D3DXHANDLE m_hEyePos; static D3DXHANDLE m_hWorld; static D3DXHANDLE m_hTex; //Lighting static D3DXVECTOR3 m_xv3LightVecW; static D3DXCOLOR m_xcAmbientMtrl; static D3DXCOLOR m_xcAmbientLight; static D3DXCOLOR m_xcDiffuseMtrl; static D3DXCOLOR m_xcDiffuseLight; static D3DXCOLOR m_xcSpecularMtrl; static D3DXCOLOR m_xcSpecularLight; static float m_fSpecularPower; //Textures static IDirect3DTexture9* m_tGrassTile; static IDirect3DTexture9* m_tPathCornerTile; static IDirect3DTexture9* m_tPathStraightTile; }; #endif Here is my CPP file #include "Tile.h" #include "d3dUtil.h" IDirect3DIndexBuffer9* Tile::m_IndexBuffer = NULL; IDirect3DVertexBuffer9* Tile::m_VertexBuffer = NULL; ID3DXEffect* Tile::m_sFX = NULL; D3DXHANDLE Tile::m_hTech = NULL; D3DXHANDLE Tile::m_hWVP = NULL; D3DXHANDLE Tile::m_hWorldInvTrans = NULL; D3DXHANDLE Tile::m_hLightVecW = NULL; D3DXHANDLE Tile::m_hDiffuseMtrl = NULL; D3DXHANDLE Tile::m_hDiffuseLight = NULL; D3DXHANDLE Tile::m_hAmbientMtrl = NULL; D3DXHANDLE Tile::m_hAmbientLight = NULL; D3DXHANDLE Tile::m_hSpecularMtrl = NULL; D3DXHANDLE Tile::m_hSpecularLight = NULL; D3DXHANDLE Tile::m_hSpecularPower = NULL; D3DXHANDLE Tile::m_hEyePos = NULL; D3DXHANDLE Tile::m_hWorld = NULL; D3DXHANDLE Tile::m_hTex = NULL; //Lighting D3DXVECTOR3 Tile::m_xv3LightVecW = D3DXVECTOR3(0, 0, 0); D3DXCOLOR Tile::m_xcAmbientMtrl = D3DXCOLOR(); D3DXCOLOR Tile::m_xcAmbientLight = D3DXCOLOR(); D3DXCOLOR Tile::m_xcDiffuseMtrl = D3DXCOLOR(); D3DXCOLOR Tile::m_xcDiffuseLight = D3DXCOLOR(); D3DXCOLOR Tile::m_xcSpecularMtrl = D3DXCOLOR(); D3DXCOLOR Tile::m_xcSpecularLight = D3DXCOLOR(); float Tile::m_fSpecularPower = D3DXCOLOR(); //Textures IDirect3DTexture9* Tile::m_tGrassTile = NULL; IDirect3DTexture9* Tile::m_tPathCornerTile = NULL; IDirect3DTexture9* Tile::m_tPathStraightTile = NULL; vector<Tile*> Tile::m_vTileList; bool Tile::SETUP_VARIABLE = Tile::SETUP_FUNCTION(); bool Tile::SETUP_FUNCTION() { Tile::m_vTileList.push_back(NULL); Tile::m_vTileList.pop_back(); return true; } /***************** ** Constructors ** *****************/ Tile::Tile(int id) { m_xv3Pos.x = 0; m_xv3Pos.y = 0; m_xv3Pos.z = 0; m_iTileID = id; Tile::m_vTileList.push_back(this); int a = rand() % 3; setTexture(a); } Tile::~Tile() { } void Tile::setTexture(int textureType) { //set the current texture pointer for a tile object to one of the 3 defined textures switch(textureType) { case TT_TileGrass: mp_tCurrentTexture = Tile::m_tGrassTile; break; case TT_TilePathStraight: mp_tCurrentTexture = Tile::m_tPathStraightTile; break; case TT_TilePathCorner: mp_tCurrentTexture = Tile::m_tPathCornerTile; break; } } D3DXVECTOR3* Tile::getPos() { return &m_xv3Pos; } D3DXMATRIX* Tile::getWorld() { return &m_m4x4World; } IDirect3DTexture9* Tile::getCurrentTexture() { return mp_tCurrentTexture; } int Tile::getTextureType() { return m_iTextureType; } int Tile::getRotationType() { return m_iRotationType; } void Tile::generateWorldMatrix() { D3DXMATRIX trans; D3DXMatrixTranslation(&trans, m_xv3Pos.x, m_xv3Pos.y, m_xv3Pos.z); m_m4x4World = trans; int a = 0; } /******************* ** Static Methods ** *******************/ void Tile::initialize() { D3DXCreateTextureFromFile(gd3dDevice, "..//Textures//Tile_Grass.dds", &Tile::m_tGrassTile); D3DXCreateTextureFromFile(gd3dDevice, "..//Textures//Tile_PathCorner.dds", &Tile::m_tPathCornerTile); D3DXCreateTextureFromFile(gd3dDevice, "..//Textures//Tile_PathStraight.dds", &Tile::m_tPathStraightTile); Tile::m_xv3LightVecW = D3DXVECTOR3(0.0, 0.0f, -1.0f); Tile::m_xcDiffuseMtrl = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); Tile::m_xcDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); Tile::m_xcAmbientMtrl = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); Tile::m_xcAmbientLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); Tile::m_xcSpecularMtrl = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); Tile::m_xcSpecularLight = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f); Tile::m_fSpecularPower = 8.0f; Tile::buildTileBuffers(); Tile::buildFX(); } void Tile::generateGrid() { float x = -2432.0f; float z = 1792.0f; int count = 0; for(int i = 0; i < 15; i++) { for(int j = 0; j < 20; j++) { Tile* temp = new Tile(count); temp->m_xv3Pos.x = x; temp->m_xv3Pos.z = z; x += 256.0f; temp->generateWorldMatrix(); count++; } z -= 256.0f; //decriment Z x = -2432.0f; //reset X } GS::wout << "Size: " << Tile::m_vTileList.size() << endl; } void Tile::release() { ReleaseCOM(Tile::m_IndexBuffer); ReleaseCOM(Tile::m_VertexBuffer); ReleaseCOM(Tile::m_sFX); ReleaseCOM(Tile::m_tGrassTile); ReleaseCOM(Tile::m_tPathCornerTile); ReleaseCOM(Tile::m_tPathStraightTile); for(int i = 0; i < Tile::m_vTileList.size(); i++) { delete Tile::m_vTileList[i]; } } void Tile::onLostDevice() { Tile::m_sFX->OnLostDevice(); } void Tile::onResetDevice() { Tile::m_sFX->OnResetDevice(); } void Tile::drawGrid() { /******************** ** START TILE DRAW ** ********************/ gd3dDevice->SetStreamSource(0, Tile::m_VertexBuffer, 0, sizeof(VertexPNT)); gd3dDevice->SetIndices(Tile::m_IndexBuffer); gd3dDevice->SetVertexDeclaration(VertexPNT::Decl); //gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); gd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); HR(m_sFX->SetTechnique(m_hTech)); Tile::m_sFX->SetValue(m_hLightVecW, &m_xv3LightVecW, sizeof(D3DXVECTOR3)); Tile::m_sFX->SetValue(m_hDiffuseMtrl, &m_xcDiffuseMtrl, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hDiffuseLight, &m_xcDiffuseLight, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hAmbientMtrl, &m_xcAmbientMtrl, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hAmbientLight, &m_xcAmbientLight, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hSpecularLight, &m_xcSpecularLight, sizeof(D3DXCOLOR)); Tile::m_sFX->SetValue(m_hSpecularMtrl, &m_xcSpecularMtrl, sizeof(D3DXCOLOR)); Tile::m_sFX->SetFloat(m_hSpecularPower, m_fSpecularPower); for(int j = 0; j < Tile::m_vTileList.size(); j++) { D3DXMATRIX wvp = (*Tile::m_vTileList[j]->getWorld()) * DXCI->getView() * DXPI->getProj(); Tile::m_sFX->SetMatrix(Tile::m_hWVP, &wvp); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, Tile::m_vTileList[j]->getWorld()); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); Tile::m_sFX->SetMatrix(m_hWorldInvTrans, &worldInvTrans); Tile::m_sFX->SetTexture(m_hTex, Tile::m_vTileList[j]->getCurrentTexture()); Tile::m_sFX->SetMatrix(m_hWorld, Tile::m_vTileList[j]->getWorld()); UINT numPasses = 0; Tile::m_sFX->Begin(&numPasses, 0); for(UINT i = 0; i < numPasses; ++i) { Tile::m_sFX->BeginPass(i); gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12); Tile::m_sFX->EndPass(); } Tile::m_sFX->End(); } } void Tile::buildFX() { ID3DXBuffer* errors = 0; D3DXCreateEffectFromFile(gd3dDevice, "..//FX//Tile.fx", 0, 0, D3DXSHADER_DEBUG, 0, &m_sFX, &errors); if(errors) { MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0); } //m_hTech = m_sFX->GetTechniqueByName("TileTech"); Tile::m_hTech = Tile::m_sFX->GetTechniqueByName("DirLightTexTech"); Tile::m_hWVP = Tile::m_sFX->GetParameterByName(0, "gWVP"); Tile::m_hWorldInvTrans = Tile::m_sFX->GetParameterByName(0, "gWorldInvTrans"); Tile::m_hLightVecW = Tile::m_sFX->GetParameterByName(0, "gLightVecW"); Tile::m_hDiffuseMtrl = Tile::m_sFX->GetParameterByName(0, "gDiffuseMtrl"); Tile::m_hDiffuseLight = Tile::m_sFX->GetParameterByName(0, "gDiffuseLight"); Tile::m_hAmbientMtrl = Tile::m_sFX->GetParameterByName(0, "gAmbientMtrl"); Tile::m_hAmbientLight = Tile::m_sFX->GetParameterByName(0, "gAmbientLight"); Tile::m_hSpecularMtrl = Tile::m_sFX->GetParameterByName(0, "gSpecularMtrl"); Tile::m_hSpecularLight = Tile::m_sFX->GetParameterByName(0, "gSpecularLight"); Tile::m_hSpecularPower = Tile::m_sFX->GetParameterByName(0, "gSpecularPower"); Tile::m_hEyePos = Tile::m_sFX->GetParameterByName(0, "gEyePosW"); Tile::m_hWorld = Tile::m_sFX->GetParameterByName(0, "gWorld"); Tile::m_hTex = Tile::m_sFX->GetParameterByName(0, "gTex"); } void Tile::buildTileBuffers() { // Create the vertex buffer. gd3dDevice->CreateVertexBuffer(24 * sizeof(VertexPNT), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &Tile::m_VertexBuffer, 0); // Write box vertices to the vertex buffer. VertexPNT* v = 0; Tile::m_VertexBuffer->Lock(0, 0, (void**)&v, 0); float halfSize = 256.0f / 2.0f; v[0] = VertexPNT(-halfSize, halfSize, -halfSize, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f); v[1] = VertexPNT(-halfSize, halfSize, halfSize, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); v[2] = VertexPNT(halfSize, halfSize, halfSize, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f); v[3] = VertexPNT(halfSize, halfSize, -halfSize, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f); Tile::m_VertexBuffer->Unlock(); // Create the vertex buffer. gd3dDevice->CreateIndexBuffer(36 * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &Tile::m_IndexBuffer, 0); // Write box indices to the index buffer. WORD* i = 0; Tile::m_IndexBuffer->Lock(0, 0, (void**)&i, 0); i[0] = 0; i[1] = 1; i[2] = 2; i[3] = 0; i[4] = 2; i[5] = 3; Tile::m_IndexBuffer->Unlock(); } Tile::Initialize() is called at the beginning to setup the buffers and load textures and whatnot. Tile::generateGrid(); is then call immediately after the initialize to create the grid. then each frame I call Tile::drawGrid(). Everything else happens internally. I am planning on talking to my teacher about it tomorrow to see his suggestions on how to make this more efficient, but I figured while I had 24 hours to see if someone had an easy way of explaining it. If you need anymore information then please let me know! Thanks GFT