JJJohan

Members
  • Content count

    11
  • Joined

  • Last visited

Community Reputation

138 Neutral

About JJJohan

  • Rank
    Member
  1. Ah, you're right. I overlooked my projection matrix!   I am beginning to recall reversing my projection matrix for the depth buffer accuracy for distant objects. It seems then that a clear value of 0 and reversing the depth functions is indeed correct behaviour.   I do feel silly now!
  2. I can't for the life of me figure out why my depth buffer is playing up, and it seems like a simple oversight somewhere.   Basically, I'm drawing a series of objects in my scene and can navigate around. What happens is the objects are drawing as if they are behind each-other, with the farthest away objects being drawn through closer ones.   I can "solve" this by setting the depth buffer D3D12_CLEAR_VALUE to 0.0 and performing a D3D12_COMPARISON_FUNC_GREATER_EQUAL instead of D3D12_COMPARISON_FUNC_LESS_EQUAL Everything then renders correctly. However rather than being happy with that, I want to know what's causing this - as it's unusual and does not reflect the behaviour of the DirectX Samples.   My psuedo render loop: Set gbuffer as active render targets. Clear gbuffer render textures. Clear depth buffer. Draw objects. Set backbuffer as active render target. Draw gbuffer result. In terms of actual code, I suppose the three useful bits here are my depth buffer creation, depth buffer clearing and PSO setup.   Creating the depth buffer: // Create a resource description for the depth texture. D3D12_RESOURCE_DESC depthDesc = {}; depthDesc.MipLevels = 1; depthDesc.Format = DXGI_FORMAT_R32_TYPELESS; depthDesc.Alignment = 0; depthDesc.Width = _screenWidth; depthDesc.Height = _screenHeight; depthDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; depthDesc.DepthOrArraySize = 1; depthDesc.SampleDesc.Count = 1; depthDesc.SampleDesc.Quality = 0; depthDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; depthDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; D3D12_CLEAR_VALUE* clearVal = new D3D12_CLEAR_VALUE(); clearVal->Format = DXGI_FORMAT_D32_FLOAT; clearVal->DepthStencil.Depth = 1.0f; clearVal->DepthStencil.Stencil = 0; // Create a depth stencil view description. D3D12_DEPTH_STENCIL_VIEW_DESC stencilDesc = {}; stencilDesc.Format = DXGI_FORMAT_D32_FLOAT; stencilDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; stencilDesc.Texture2D.MipSlice = 0; // Create a shader resource view description. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srvDesc.Format = DXGI_FORMAT_R32_FLOAT; srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = 1; LOGFAILEDCOM(_device->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &depthDesc, D3D12_RESOURCE_STATE_DEPTH_READ, clearVal, IID_PPV_ARGS(&_pDepthBuffer))); _device->CreateDepthStencilView(_pDepthBuffer, &stencilDesc, _dsvHeap->GetCPUDescriptorHandleForHeapStart()); DepthBufferIndex = ResourceFactory::GetTextureSlot(); CD3DX12_CPU_DESCRIPTOR_HANDLE srvHandle(_cbvSrvHeap->GetCPUDescriptorHandleForHeapStart(), DepthBufferIndex, D3DUtils::GetSRVDescriptorSize()); _device->CreateShaderResourceView(_pDepthBuffer, &srvDesc, srvHandle); Clearing the depth buffer (how difficult can it be?): _commandList->ClearDepthStencilView(_dsvHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); PSO (relevant bits): D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = {&inputLayout[0], UINT(inputLayout.size())}; psoDesc.pRootSignature = _pRootSignature; psoDesc.VS = {reinterpret_cast<UINT8*>(_pVertexShader->GetBufferPointer()), _pVertexShader->GetBufferSize()}; psoDesc.PS = {reinterpret_cast<UINT8*>(_pPixelShader->GetBufferPointer()), _pPixelShader->GetBufferSize()}; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT; psoDesc.BlendState = blendState; psoDesc.SampleMask = UINT_MAX; psoDesc.SampleDesc.Count = 1; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthFunc = _depthCheck; psoDesc.DepthStencilState.DepthEnable = TRUE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.DepthStencilState.DepthWriteMask = _depthWrite; psoDesc.NumRenderTargets = GBuffer::GBUFFER_NUM_TEXTURES; for (size_t i = 0; i < GBuffer::GBUFFER_NUM_TEXTURES; ++i) { psoDesc.RTVFormats[i] = DXGI_FORMAT_R8G8B8A8_UNORM; }
  3. I've created a client-server scenario, first using broadcast and then moving on to multicasting as an improvement. I began noticing problems in how the networking handled based on whether the client or server opened up first. For example, if I start the server and THEN the client, the client won't be able to read anything from the server, but the other way around worked fine. Turns out that binding both the server and the client on the same port isn't a good idea and doesn't work. However, my next problem isn't as simple as far as I can tell. In addition to sending a 'disconnect' packet if the client or server closes down, they also send heartbeats in the case that the disconnect packet does not arrive, e.g. the program crashes for any reason. Now here's the problem scenario: The server and client are both running. The server sends a 'ping' every second and the client receives it. If the client has not received a ping for 10 seconds, the server is removed from the server list. However, if I close the server, rather than the client ceasing to receive pings, it seems to continue receiving them every single second. I know it's simply a stack of messages in the buffer because even if I run the server for only around 2 seconds, it will continue to receive pings endlessly, and it's only sending them once a second as verified with some logging. The server and client use a similar yet basic setup: -Initiate winsock -Create a socket -Bind to port 12345 and 12346 for client and server respectively on INADDR_ANY. -Send to a multicast address -select() to determine if there are messages and receive them Here's a somewhat stripped-down version of the client's receiving code: [code] fd_set checksockets; checksockets.fd_count = 1; checksockets.fd_array[0]=m_socket; struct timeval t; t.tv_sec=0; t.tv_usec=0; int waiting = select(NULL, &checksockets, NULL, NULL, &t); // If there is at least one packet receive it. if (waiting>0) { sockaddr senderAddr; int senderAddrSize = sizeof (senderAddr); recvfrom(m_socket,buf,10000,0,&senderAddr,&senderAddrSize); switch(((Packet*)buf)->m_type) { case PT_SERVERPACKET: { for (auto it = m_serverList.begin();it != m_serverList.end();++it) { if (((sockaddr_in*)&(*it).m_address)->sin_addr.s_addr == ((sockaddr_in*)&senderAddr)->sin_addr.s_addr) { OutputDebugString("Server ping.\n"); // Server ping! } } } break; } }[/code]
  4. I'm working on a simple little game that requires me to constantly create objects, and I figured the best way would be to use arrays as they are individually managed. Here's the object class, simplified so I can actually see if it works at its base. class Block { private: SDL_Rect box; public: SDL_Rect* blockclip; Block( int x, int y, int w, int h, int randomnumber ); void show(); }; Block::Block( int x, int y, int w, int h, int randomnumber ) { box.x = x; box.y = y; box.w = w; box.h = h; blockclip = &clip[ randomnumber ]; lastblockheight = lastblockheight + box.h; lastclip = randomnumber; } void Block::show() { apply_surface( box.x, box.y + newblockheight, blocks, screen, blockclip ); } And I'm trying to create them as so: Block Blocks[4]; for(int i =0;i<4;i++) { Blocks[i] = Block( 164 - (clip[randomnumber].w), lastblockheight, clip[randomnumber].w, clip[randomnumber].h, randomnumber ); } Then show them again later like this in the rendering loop: for(int i =0;i<4;i++) { Blocks[i].show(); } Now I can't figure out how I can actually perform this. As I'm getting a range of error messages. error: no matching function for call to `Block::Block() I tried using this method instead: Block* Blocks[4]; for(int i =0;i<4;i++) { Blocks[i] = new Block( 164 - (clip[randomnumber].w), lastblockheight, clip[randomnumber].w, clip[randomnumber].h, randomnumber ); } But then I get this error message: error: request for member `show' in `Blocks[i]', which is of non-class type `Block*
  5. Using physFS with SDL

    A few weeks ago I had asked how to use zlib to load files for SDL, and after little discussion I've been directed towards physFS. I've managed to install it, it works perfectly fine (I'm still shocked I got it working) but now here's the part of integrating it into SDL. How would I go about using zip file resources in my application? I'm currently focusing on the template file that is created when making a new SDL project in CodeBlocks, but I've had no luck so far. I've looked for tutorials, but all I found was ones which were using other libraries which are only going to make it harder for me. Here's a very rough test version of what I'm trying to do: #ifdef __cplusplus #include &lt;cstdlib&gt; #else #include &lt;stdlib.h&gt; #endif #ifdef __APPLE__ #include &lt;SDL/SDL.h&gt; #else #include &lt;SDL.h&gt; #endif #include "physfs.h" #include &lt;iostream&gt; int main ( int argc, char** argv ) { /* This is the RWops structure we'll be using */ SDL_RWops *rw; SDL_Surface *one; SDL_Rect rect; PHYSFS_init(NULL); PHYSFS_addToSearchPath("myzip.zip", 1); PHYSFS_file* cb = PHYSFS_openRead("cb.bmp"); PHYSFS_sint64 file_size = PHYSFS_fileLength(cb); //on a platform where char = 1 byte char *myBuf; myBuf = new char[PHYSFS_fileLength(cb)]; int length_read = PHYSFS_read (cb, myBuf, 1, PHYSFS_fileLength(cb)); // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) &lt; 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE|SDL_DOUBLEBUF); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } rw = SDL_RWFromMem(myBuf, file_size); one = SDL_LoadBMP_RW(rw, 0); // program main loop bool done = false; while (!done) { // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) done = true; break; } } // end switch } // end of message processing // DRAWING STARTS HERE // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen-&gt;format, 0, 0, 0)); rect.x = rect.y = 20; rect.w = one -&gt; w; rect.y = one -&gt; h; SDL_BlitSurface(one, NULL, screen, &rect); // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(screen); } // end main loop PHYSFS_close(cb); PHYSFS_deinit(); // all is well ;) printf("Exited cleanly\n"); return 0; } Now I obviously can't directly load the pointer file and use it as an image in SDL, but that's why I'm posting this :). [Edited by - JJJohan on April 25, 2009 1:15:50 AM]
  6. Thanks, I feel stupid for having missed that, I take back about the lack of documentation. I was rather stressed and had spend the entire previous day finding a suitable solution so I wasn't particularly relaxed in the morning.
  7. Now I'm just getting the following message when compiling the original physfs.c(whoops with the first time) 1>Linking... 1> Creating library C:\Users\JJJohan\Documents\Visual Studio 2008\Projects\physfs\Debug\physfs.lib and object C:\Users\JJJohan\Documents\Visual Studio 2008\Projects\physfs\Debug\physfs.exp 1>LINK : fatal error LNK1561: entry point must be defined But other than that, even if I do manage to compile it, what am I supposed to do with it? There's very few details on usage anywhere.
  8. I can't seem to find any way to compile physfs, seeing as it doesn't come with any sort of installation instructions :(. I just get spammed with 3 errors which I can't seem to figure out when I try to compile physfs.c 1>------ Build started: Project: physfs, Configuration: Debug Win32 ------ 1>Compiling... 1>physfc.cpp 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(177) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(327) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(157) : see declaration of 'strncpy' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(560) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(566) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(567) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(79) : see declaration of 'strcat' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(626) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(650) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(79) : see declaration of 'strcat' 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(672) : error C2440: '=' : cannot convert from 'const char *' to 'char *' 1> Conversion loses qualifiers 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(675) : error C2440: '=' : cannot convert from 'const char *' to 'char *' 1> Conversion loses qualifiers 1>c:\users\jjjohan\documents\visual studio 2008\projects\physfs\physfs\physfc.cpp(1444) : error C2440: '=' : cannot convert from 'void *' to 'char *' 1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast 1>Build log was saved at "file://c:\Users\JJJohan\Documents\Visual Studio 2008\Projects\physfs\physfs\Debug\BuildLog.htm" 1>physfs - 3 error(s), 7 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  9. I've spend quite a few hours looking for a bunch of zlib resources since I have no idea what to actually use.. Anyway, I downloaded zlib along with zlibtool.zip elsewhere, which basically lets me do this to compress and uncompress files: #include "zlibengn.h" #pragma comment(lib,"zdll.lib") ZlibEngine z; int main(int argc, char* argv[]) { z.compress( "zlib.h","zlib.h__"); z.decompress( "zlib.h__", "test.h"); return 0; } Now the question is, how would I go at compressing multiple files into one file, then obviously decompressing them all again in their original place? I tried using a folder which doesn't seem to work, and I don't arrays are working either. If I can't use zlibtools, then please be so kind to redirect me to what I need to use. I'd really like to use this method to store a hefty number of game resources into a single compress folder, then if needed uncompress them while the game loads etc. (or just load them while compressed if that's possible)