Jump to content
  • Advertisement

Nahrix

Member
  • Content Count

    100
  • Joined

  • Last visited

Everything posted by Nahrix

  1. Thank you for the information, Hodgman.  Since this exercise is just a learning experience for me, and not intended to be productive, I've decided to investigate the optimized approach.   I have one other question about having a single vertex buffer.  If I were to add a model to the vertex buffer after having already initialized it with vertex data earlier on, the method that I see typically presented is: Create a new vertex array, with a mirror of the data already on the GPU, except sized larger to store the additional model vertex data Map the vertex buffer resource Copy the new vertex array over to the mapped resource My question is, is there a way to append the model's data to the end of the vertex buffer on the GPU, rather than copying over an entire block of redundant data, with the new model at the end?
  2. I've been using the tutorial site http://www.rastertek.com/ to learn DirectX 11 in C++.  I'm a little ways past a tutorial about rendering models to the screen.  The strategy in the tutorial is to create a class for the model, which includes an initialize function which creates a vertex buffer for the model.  I've since expanded and generalized the class to load any number of models, to be rendered to the screen later.   After doing some browsing on other sites related to DirectX, I found what seems to be a consensus opinion that everything should be put into a single vertex buffer, which is different than what I'm doing:  I'm creating a vertex buffer for every model, and in another function in my application, iterating through all the model objects, and calling their Render() function, which in turn call IASetVertexBuffers, IASetIndexBuffer, and IASetPrimitiveTopology, and then runs the shaders on each in turn.  This draws multiple models properly, but I don't want to continue doing it this way if it's wrong.   I have a few questions. Is it best practice to fit everything into a single vertex buffer? If so, how do I efficiently add / remove models to/from the vertex buffer in-between frames? Are there any tutorials out there that illustrate this method for DirectX 11 in C++? Because I'm so new to this, I might even be asking the wrong questions, so please correct any assumptions I might have accidentally made if that's the case.   Thanks!
  3. I'm using this tutorial as a baseline for parsing obj files: http://www.rastertek.com/dx11tut08.html   This works fine if the obj file only contains faces with 3 vertices, but I'm trying to figure out how to make it work for obj files with faces that index 4 or more vertices.   My original thought was that, for faces with more than 3 vertices, (I'll simplify their description as f1, f2, f3, f4...) the first polygon would be built from f1, f2, f3, and the next from f2, f3, f4, etc.  When I parse and render that, however, there are lots of missing polygons in the mesh, so there's something I'm doing wrong.   My next thought was to read in f1, f2, f3 normally (backwards as f3, f2, f1, to convert the right-hand coordinate system to left-hand), and then read f2, f3, f4 in reverse (so in forwards order, f2, f3, f4, to convert coordinate systems again), and alternate that back and forth, since maybe the vertices were supposed to be read in like a stripe in Maya.  That didn't work either.   Anyways, I'm completely new to this, but I gave it my best shot before coming here for help.  Hopefully someone knows exactly how to handle this.
  4. It could also be that you have to perform: UV.y = 1.0f - UV.y;.     L. Spiro   It's all good;  I just made a typo where I was assigning the same value over and over.  Everything works after modifying my code for triangle fans.  Thanks for all the help; you're the best!
  5. It works! .. sort of.   All the polygons show up now, but both the texture and normals are all out of whack.  It must be due to a combination of the right-hand to left-hand coordinate conversion, and the triangle-fan conversion I've done for the indices.   Edit:  Actually nevermind, it was just a simple typo in my code.  Everything works perfectly now!
  6. Thanks!  I'll go try to implement that right now :)
  7. I have a thread that writes to a struct, and it needs access to that struct all the time.  I don't want to use a mutex to allow other threads to access this struct, because I don't want the first thread to ever have to wait for access to the data in the struct.   My solution is to write a copy of the struct every time it modifies the data, so other threads can access the copy of the (now potentially outdated, but that doesn't matter) struct data, without interrupting the primary thread.  If the primary thread needs to read the data, it references its own copy.  If it needs to write the data, it writes to its own struct, and only writes a copy if that copy isn't being read from (otherwise it skips that step).  I'd like to make this as efficient as possible, so I was wondering if there a way to write to 2 identical structs that's more efficient than simply writing, for example:   struct1.data1 = newdata; struct2.data1 = newdata;   assuming that you know the data is identical, and both are being written at the exact same time.
  8.   This analogy is close enough that the solution actually fits really well!  I can just have 2 structs that the primary thread alternates between writing, and then it can stick to just one of the structs while the other thread is busy reading from another one.  I only have to write a single time per loop, too!  Thanks!
  9. Define 'large'? Hundreds of times a second isn't very fast - we are potentially talking 10 milliseconds between copies, which is quite a lot of CPU time...       About 10 megabytes.
  10.   Sorry, I didn't mean it that way.  Let me clarify with an example stripped to the bones:   Let's say you have 2 ints: int1 and int2, and 2 threads: thread1 and thread2.  int1 and int2 are set to 0 by default.  At some point, thread1 takes int1, adds 1 to it, and saves the value to int1 and int2.  int2 will be accessed by thread2 as well at some point, so the write to int2 is done with a mutex.  Later, thread1 reads from int1 (1), adds 1 to it (2), and saves it back to int1.  Thread1 notices that int2 is being read from, so code is added to ignore the attempt to write to it (doesn't wait on the mutex, just skips to whatever else thread1 wants to do next).  What I'm saying is that, specific to the code I'm writing, it logically doesn't matter to me that thread2 is now reading 1 from int2, when the most current version of int1 reads 2.  I'm not talking about race conditions or anything, just that the logic in my code doesn't care that the two threads are dealing with 2 different values at this point in time.   The copy will be happening on large blocks of data hundreds of times per second, so this is an area I'd be willing to find an efficient solution to, even if it's something very complex.
  11. I need help devising a counting algorithm using the following rules: I have a string where each character comes lexicographically after the last, ie if the first letter is 'a', then the next letter MUST be between 'b' and 'z'. So some valid words would be: abc abd bcd bdz wxy And invalid words would be: aaa aab zab zy ca Then I want to find its integer value, where it counts up. ie: a = 1 b = 2 ... z = 26 ab = 27 ac = 28 ad = 29 ... az = 51 bc = 52 bd = 53 be = 54 Note that ab = 27 (there is no aa = 27, because aa would be an invalid word, and so bc = 52 after az, because there is no ba, or bb) I'm looking for an algorithm that can determine the numeric value of a valid word based on that counting algorithm.
  12. Nahrix

    Counting algorithm

    I've been working on this for a long time. I haven't learned combinatorial mathematics yet, so I have tried to solve this using recursion. This is what I have so far. It doesn't work at all, but will show how I am thinking about the problem: (Java) public static int mapCodeword(String word) { String alphabet = "abcdefghijklmnopqrstuvwxyz"; int total = 0, alphabetLocation = alphabet.indexOf(word.charAt(0)); alphabet = alphabet.substring(alphabetLocation); if (word.length() == 1) return alphabetLocation + 1; for (int i = 0; i < word.length() + alphabetLocation - 1; ++i) total += (alphabet.length() * (word.length() - 1)) + mapCodeword(word.substring(1)); return total; }
  13. Nahrix

    Counting algorithm

    Yeah sorry, I meant implementation. Does it have a name?
  14. Trying a piece of code from the book, "Ultimate Game Programming With DirectX" Language: C++ Compiler: MinGW IDE: Eclipse Problem: I'm getting the error, "undefined reference to `Direct3DCreate9@4'" on the line that uses Direct3DCreate9(D3D_SDK_VERSION), and I'm getting two warnings, "ignoring #pragma comment", for the two pragma lines up front. #include <d3d9.h> #pragma comment(lib, "d3d9.lib") #pragma comment(lib, "d3dx9.lib") #define WINDOW_CLASS "UGPDX" #define WINDOW_NAME "Blank D3D Window" // Function prototypes bool InitializeD3D(HWND hWnd, bool fullscreen); void RenderScene(); void Shutdown(); // Direct3D object and device LPDIRECT3D9 g_D3D = NULL; LPDIRECT3DDEVICE9 g_D3DDevice = NULL; LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); return 0; break; case WM_KEYUP: if (wParam == VK_ESCAPE) { PostQuitMessage(0); break; } } return DefWindowProc(hWnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdLine, int show) { // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0, 0, hInst, NULL, NULL, NULL, NULL, WINDOW_CLASS, NULL }; RegisterClassEx(&wc); // Create the application's window HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, GetDesktopWindow(), NULL, wc.hInstance, NULL); // Initialize Direct3D if (InitializeD3D(hWnd, false)) { // Show the window ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { RenderScene(); } } } // Release any and all resources Shutdown(); // Unregister the class UnregisterClass(WINDOW_CLASS, wc.hInstance); return 0; } bool InitializeD3D(HWND hWnd, bool fullscreen) { D3DDISPLAYMODE displayMode; // Create the D3D object g_D3D = Direct3DCreate9(D3D_SDK_VERSION); if (g_D3D == NULL) { return false; } // Get the desktop display mode if (FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode))) { return false; } // Set up the structure used to create the D3DDevice D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); if (fullscreen) { d3dpp.Windowed = FALSE; d3dpp.BackBufferWidth = 640; d3dpp.BackBufferHeight = 480; } else { d3dpp.Windowed = TRUE; } d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = displayMode.Format; // Create the D3DDevice if (FAILED( g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_D3DDevice))) { return false; } return true; } void RenderScene() { // Clear the backbuffer g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // Begin the scene. Start rendering g_D3DDevice->BeginScene(); // End the scene. Stop rendering g_D3DDevice->EndScene(); // Display the scene. g_D3DDevice->Present(NULL, NULL, NULL, NULL); } void Shutdown() { if (g_D3DDevice != NULL) { g_D3DDevice->Release(); } if (g_D3D != NULL) { g_D3D->Release(); } g_D3DDevice = NULL; g_D3D = NULL; } [Edited by - Nahrix on April 23, 2009 5:50:59 PM]
  15. Nahrix

    Problem with basic DirectX app

    I have resolved the issue by using Visual Studio instead of Eclipse.
  16. Nahrix

    Problem with basic DirectX app

    Damn; I fixed that, but the problem still exists (same error / two warnings)
  17. Nahrix

    Sick

    I've been dead with a flu/fever recently, and have been spending countless hours asleep in various rooms of my house. My head is spinning and pounding, and it's been impossible to get any work done. I have, however, purchased a book on AI, and am attempting to read it between migraines. Hopefully I'll finish it soon. I just want to get back to programming again.
  18. I'm not sure how to create an array of enumerations. I've tried using a vector of enumerations instead, but the push_back function doesn't seem to work with them.
  19. I'm working on my first project to aid me in development of programming skills. It's going to be a 2D simulation. What I need to know is how do implement very basic AI algorithms, such as movement, eating, hunting, etc, in such a manner that 'upgrading' the AI to advanced heuristics, genetic algorithms, neural networks, etc, will be seamless. As of now, I'm not even sure how to implement any form of pathfinding, such as using nodes, and as such, I need to start of small. The important thing, though, is keeping the doors open for adding functionality without large code rewrites. Thank you very much in advance for any input provided.
  20. Nahrix

    Done and done. Well, sort of done.

    CivEdit has transcended to complete, while basic, functionality. This landmark is halled with the sigil 'beta' instead of alpha, and has been been moved to version 0.3. Whereas previous screenshots were carefully captured to display maximum potential and minimum bugs, I now present you a screenshot of the editor that acts exactly the way it looks like it acts. Visually, little difference can be discerned from earlier builds. However, major additions have been coded to the structure of the objects, and what information those objects hold. As well, the manner in which tiles are 'painted' on by the user to create landscapes has been drastically altered for maximum intuitiveness. I will now officially begin work on the AI, while simultaneously updating code to the editor. For example, I still plan on implementing a minimap to both CivEdit and CivSim. Everything is going according to the plans which I never drew. Excellent.
  21. Nahrix

    Done and done. Well, sort of done.

    No, I cannot load multiple maps in the editor.
  22. Nahrix

    In more then one place at once...

    Your game has definition. That definition is: kickin rad. I salute you.
  23. Nahrix

    Hola!

    I have come to say that Raptor is an amazing game of which I have loved since I was a tiny little nerd.
  24. Nahrix

    Array of enumerations

    Thanks guys, but I've found the solution myself. Sorry I haven't responded; I went to bed, and had to work today.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!