• Content count

  • Joined

  • Last visited

  1. Do you mean first writing everything to a char array (aka buffer) and then write that buffer to file? That could work, but then I have to calculate the index manually, which could be a risk if some type has a different bytesize on another problem (writing per variable and using sizeof, I think prevents this). In your example, shouldn't 3 be 4 (bytes for a float)? But perhaps there's a way to use a buffer while keeping this in mind (or don't manually calculate the index of each variable).
  2. Thanks. The VECTOR3 is my struct, so it's working for both an individual struct as a std::vector of them. Thanks
  3. What's with the downvote? Can someone enlighten me so I know how to do it right/ better.
  4. Thanks guys. I've been playing around using this input. Unfortunately writing the struct or array (std::vector) at once, doesn't work by trying to cast to (myType*), it does work when I cast it to (char*). See the code samples below, tested all 3 positive. Would I have any risks on this approach, depending on platform? (size of float etc.). I'll make sure the struct I use as a POD struct, which is the case in the example below. void ReadWriteStruct() { std::ofstream writeFile;"data.bin", std::ios::out, std::ios::binary); writeFile.write((char*)&srcVector, sizeof(VECTOR3)); writeFile.close(); MessageBox(NULL, L"Vector written to binary file - full struct!", L"Done", MB_OK); std::ifstream readFile;"data.bin", std::ios::in, std::ios::binary); VECTOR3 myReadVec3;*)&myReadVec3, sizeof(VECTOR3)); readFile.close(); char tempText[100]; sprintf_s(tempText, "Read: %f, %f, %f\n", myReadVec3.x, myReadVec3.y, myReadVec3.z); OutputDebugStringA(tempText); } void ReadWriteArray() { std::vector<VECTOR3> myVectors(2); myVectors[0].x = 0.2f; myVectors[0].y = 0.7f; myVectors[0].z = 0.95f; myVectors[1].x = 5.2f; myVectors[1].y = 4.7f; myVectors[1].z = 7.75f; std::ofstream writeFile;"data.bin", std::ios::out, std::ios::binary); writeFile.write((char*)&myVectors[0], myVectors.size() * sizeof(VECTOR3)); writeFile.close(); MessageBox(NULL, L"Vector written to binary file - full struct!", L"Done", MB_OK); std::ifstream readFile;"data.bin", std::ios::in, std::ios::binary); std::vector<VECTOR3> readVectors(2);*)&readVectors[0], sizeof(VECTOR3));*)&readVectors[1], sizeof(VECTOR3)); readFile.close(); char tempText[100]; sprintf_s(tempText, "Read 1: %f, %f, %f\n", readVectors[0].x, readVectors[0].y, readVectors[0].z); OutputDebugStringA(tempText); sprintf_s(tempText, "Read 2: %f, %f, %f\n", readVectors[1].x, readVectors[1].y, readVectors[1].z); OutputDebugStringA(tempText); }
  5. Hi all, For practice I'm trying to write 3D mesh data to a binary format. To eventually also be able to read meshes from binary files (provided by the asset pipeline). I understand how to write floats, vectors of floats, ints etc by using a write((char*)myVar, sizeof(type) to the file, for which I'm using std::ofstream. My goal is to write a 3D vector or other type (struct) to the file and be able to read it back the same way. From what I understand, I need to create function that returns a char array combining all members of the struct. So in short; how can I create this char array, in a "safe" way? So far I've come up with this approach: - calculate number of needed bytes/chars, i.e 12 bytes for a 3D vector with 3 floats - char result[12] - cast the 3 individual floats to char[4]'s and use strcpy to result for the 1st and strcat for the others Is this the way to go or would you suggest other approaches? question 2; How would I read/convert the char array back to the 3 floats when reading it from the binary file? Any input is appreciated.
  6. 3D Mesh data (format)

    My bad, appearantly I misread. Thanks all, enough thinking; time to experiment
  7. 3D Mesh data (format)

    @_Silence_ : assimp can import .max according to the documentation. I think I'll make a branch for the transform (offsets versus matrix), depending on animated or not. I also like the idea to "pre-transform" static mesh children, this can save quite some realtime matrix muls.
  8. 3D Mesh data (format)

    Thanks. I think I'm not far off that track. My tool will use assimp to load the DCC format, the only thing I'll do afterwards, is extract only the data I need to the format my engine will "eat". Any thoughts on storing the child transform data? (Matrix versus individual offsets)
  9. Hi all, As a part of my new framework/ 3D engine I've arrived at the point to go beyond nice cubes and spheres My plan is to create a tool that will convert DCC output (I.e 3ds max) to a straight forward format I can load up in my engine (binary). The format will basically consist of sets of: vertices (in one defined format), face indices, material ID's and a transform to parent. My question is about the transform. Would you store a position, rotation and scale? Or just a 4x4 matrix (I think assimp provides the latter). For the tool to convert (pipeline), I aim to use assimp. Besides the question on the transform, of course any feedback on the approach in general is appreciated.
  10. What should I do for my first game?

    I'd start with a game as simple as possible and make sure to completely finish it. So Yes, even simpler then a "small" rpg. Perhaps something like pacman, pong, asteroids etc. framework/ engine is up to you, Unity has a great community and the entry level is low.
  11. Thanks for the additional thoughts. Will also dig into file streams
  12. Hi all, I've just implemented a screenshot function for my engine, using dx11. This all works fine, also when the rendertarget has MSAA applied, then I use resolvesubresource into an additional rendertarget. Basically, without AA: - copy primary RT to RT with usage STAGING and CPU access (staging texture) - map the RT, copy the pixel data and unmap And with AA: - copy primary RT with AA to temporary 1 without AA (usage default, no CPU access) (resolve texture) - copy temporary RT without AA to new RT with usage STAGING and CPU access (staging texture) - map the RT, copy the pixel data and unmap So it all works fine, I applied a branch for MSAA enabled/ disabled. My question; according to the MSDN documentation, "Resolvesubresource", should only work when 'source' has >1 samples and 'dest' has 1 sample (in the desc). But somehow the process with the resolve texture, including using 'resolvesubresource', also works when I don't have MSAA enabled. So both source + dest has 1 sample. I would expect the D3D debugger/ logging to give an error or at least a warning. Below the code in which this applies (don't mind it not being optimized/ cleaned up yet, just for illustration) std::vector<char> DX11RenderTarget::GetRGBByteArray() const { CComPtr<ID3D11Device> myDev; CComPtr<ID3D11DeviceContext> myDevContext; mBuffer->GetDevice(&myDev); myDev->GetImmediateContext(&myDevContext); // resolve texture D3D11_TEXTURE2D_DESC tempRTDesc; tempRTDesc.Width = mWidth; tempRTDesc.Height = mHeight; tempRTDesc.MipLevels = 1; tempRTDesc.ArraySize = 1; tempRTDesc.Format = mDXGIFormat; tempRTDesc.BindFlags = 0; tempRTDesc.MiscFlags = 0; tempRTDesc.SampleDesc.Count = 1; tempRTDesc.SampleDesc.Quality = 0; tempRTDesc.Usage = D3D11_USAGE_DEFAULT; tempRTDesc.CPUAccessFlags = 0; CComPtr<ID3D11Texture2D> tempTex; CComPtr<ID3D11Texture2D> anotherTempTex; myDev->CreateTexture2D(&tempRTDesc, 0, &tempTex); // add check if(FAILED), logging myDevContext->ResolveSubresource(tempTex, 0, mBuffer, 0, GetDXGIFormat(mBufferFormat)); // format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ; not flexible now // staging texture tempRTDesc.Usage = D3D11_USAGE_STAGING; tempRTDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; myDev->CreateTexture2D(&tempRTDesc, 0, &anotherTempTex); // add check if(FAILED), logging myDevContext->CopyResource(anotherTempTex, tempTex); // map, copy pixels and unmap D3D11_MAPPED_SUBRESOURCE loadPixels; myDevContext->Map(anotherTempTex, 0, D3D11_MAP_READ, 0, &loadPixels); std::vector<char> image(mWidth*mHeight*3); char *texPtr = (char*)loadPixels.pData; int currPos = 0; for(size_t row=0;row<mHeight;++row) { texPtr = (char*)loadPixels.pData + loadPixels.RowPitch * row; for(size_t j=0;j<mWidth*4;j+=4) // RGBA, skip Alpha { image[currPos] = texPtr[j]; image[currPos+1] = texPtr[j+1]; image[currPos+2] = texPtr[j+2]; currPos += 3; } } myDevContext->Unmap(anotherTempTex, 0); return image; }
  13. Thanks all, this really helps. I'm going to look into better separation of read/write and read data and maybe using the change cwd solution.
  14. Hi, During the journey of creating my 2nd 3D engine, I'm basing quite some of the approaches on the Game Engine Architecture book (Jason Gregory). I've now arrived on the topic: IO. In short, the target platforms for me are PC, XBone and PS4. With this main assumption I thought of the following logics/ guidelines to follow: - I can assume file/folder structures will work on all 3 platforms, when I use '/' as a folder separator -- I will define 1 global with the base folder for the application, the rest will 'inherit' from there (which can be anything, independent of the 'mount' or drive) -- for now I'll create 1 subfolder with data/files that might need write access, so later on I only have to worry about 1 subfolder (settings, configs etc.). - file extensions can be longer than 3 characters (in Linux based FreeBSD on PS4) - all class members functions needing to load a file, shouldn't have to now about the file structure of the logical application, so they will all take a full filename string including path (combining root + subfolder + filename and separators is then the responsibility of the caller/ calling code) - some functions will need to be passed a folder, because contents in that folder need to be read OR I can simply define a small list of defined subfolders (under root/ base), because it won't be more then 5 to 10 folders in total (data/shaders, data/textures, data/objects, data/sound etc.) My questions: - what do you think about this approach? - regarding the last point, which of the 2 options would you apply? -- option 2 might work fine but feels a bit 'static', not very flexible (on the other hand, would you actually need flexibility here?) Any input is appreciated, as always.
  15. Thanks both. @Mussi: problem solved using the solution you proposed, thanks