• Content count

  • Joined

  • Last visited

Community Reputation

115 Neutral

About liamf1986

  • Rank
  1. Ogg Vorbis decoder

    Hello,   I'm trying to implement a decoder for ogg vorbis audio files (.ogg). It all compiles and runs fine but the audio is mostly static. It plays a second or two of the correct audio occasionally but is mostly just static noise.   I was wondering if anyone could see any problems in the code, see below.   // Defined in .h file XAUDIO2_BUFFER m_xa; WAVEFORMATEX m_wf;     bool COgg::load(const char* szFile, bool loop) { if (szFile == NULL) return false; FILE* file = NULL; OggVorbis_File m_oggFile; errno_t error; error = fopen_s(&file, szFile, "rb"); if (error != 0) return false; // Get info from .ogg file. if (ov_open_callbacks(file, &m_oggFile, NULL, 0, OV_CALLBACKS_DEFAULT) != 0) { fclose(file); return false; } vorbis_info* vInfo = ov_info(&m_oggFile, -1); memset(&m_wf, 0, sizeof(m_wf)); m_wf.cbSize = sizeof(m_wf); m_wf.nChannels = vInfo->channels; m_wf.wBitsPerSample = 16; // Ogg vorbis is always 16 m_wf.nSamplesPerSec = vInfo->rate; m_wf.nAvgBytesPerSec = m_wf.nChannels * 2 * m_wf.nSamplesPerSec; m_wf.nBlockAlign = m_wf.nChannels * 2; m_wf.wFormatTag = WAVE_FORMAT_PCM; // Get size of file. fseek(file, 0, SEEK_END); // Jump to end of file. long fileSize = ftell(file); // Store current position in file (the end). fseek(file, 0, SEEK_SET); // Jump back to the begining. int bitstream = 0; DWORD pos = 0; int ret = 1; // Read the audio data from the opened .ogg file. char* m_data = new char[fileSize]; while (ret && pos<fileSize) { ret = ov_read(&m_oggFile, m_data+pos, fileSize-pos, 0, 2, 1, &bitstream); pos += ret; } m_xa.AudioBytes = fileSize; m_xa.pAudioData = reinterpret_cast<BYTE*>(m_data); m_xa.PlayBegin = 0; m_xa.PlayLength = 0; // Ignore the zero for now, it should be the length of the track. if (loop == true) { m_xa.LoopBegin = m_xa.PlayBegin; m_xa.LoopLength = m_xa.PlayLength; m_xa.LoopCount = -1; // -1 is an infinate loop. } // Kill the vorbis file. ov_clear(&m_oggFile); // close the file. fclose(file); return true; }    
  2. Odd ID3DXFont problem

    Looks like that was the problem, forgot to update that while I was doing everything else, Doh. Thanks for the reply. Liam F
  3. How to include in *fx. file?

    I've not read the book so can't be sure but my guess is that he wants you to pass the value returned from the GameTimer::GetTime() function into the .fx file as a variable. So something like this, .fx file [code] float gTime; // vertex shader stuff. Output VertexShader(Input in) { Output out; out = in.Position*gTime; return out; } [/code] So basically in the .fx file I've created a variable at the top called gTime. This value is then accessed somewhere inside the vertex shader ( in my basic example it is multiplied with the given position values). You would need to set this new variable in your C++ code before drawing anything with the effect applied, something like this, .cpp file [code] // Heres the important line!!! Effect.SetBool("gTime", GameTimer.GetTime()); Effect.Begin() // Draw something awesome. Like a duck! Effect.End() [/code] Unfortunatly I have no idea of the exact code to set variables in your example but your current code should be setting some variables for the effect file already. So if you can find that code and copy it for your new variable that should work out. Look in your draw code within your .cpp file and it should be setting a View or ViewProjection for the effect somewhere before drawing it. hope that all makes sense and that its what your actually looking for. Liam
  4. It's definitely highly advisable to read DirectX 9 books/tutorials from the start. Alot of functions have changed from 8 to 9 which could make starting out even more confusing for a new comer. As well as the introduction of the programmable graphics pipeline already mentioned, alot of DirectX 8 books refer to Direct Input and Direct Play which aren't really used anymore. If you don't want to invest in a new book just yet there is plenty of online tutorials to start of on, directXTutorials is fantastic although only the first few tutorials are free a premium membership is required for the later ones. The other 2 are quite old sites and not updated anymore I believe but the tutorials still stand up and work great. Good luck with it all, and have fun.
  5. Odd ID3DXFont problem

    Oh I forgot to mention, I just transfered this project from a Windows 7 laptop to a windows vista laptop which is when the issues arose. The text was always displaying fine on the other system. Both systems have The latest Direct X SDK (June 2010) and both running the Visual C++ 2010 express edition IDE. Thx again, Liam
  6. Hello all, I'm having an odd issue with ID3DXFont. I'll start by posting an image of the problem and maybe someone will recognize it straight away, [img][/img] That supposedly says Debug Mode.... This problem only occurs when the DrawText() function of any font object is only called once. If I draw another line later in the program both lines draw perfectly fine, as shown below, [img][/img] The problem is localized to each instance of ID3DXFont, meaning I can create 2 instances of ID3DXFont draw 2 lines with one instance and they will draw fine but if I only draw one line with the other instance that line will draw incorrectly. My Text drawing code is as follows; [code] device->ClearScreen(bgColor); device->BeginScene(); spriteInterface->Begin(D3DXSPRITE_ALPHABLEND); RECT fontPos; SetRect(&fontPos, xPos, yPos, 100, 100); debugText->DrawText(spriteInterface, "Debug Mode", -1, &fontPos, DT_LEFT | DT_NOCLIP, D3DCOLOR_XRGB(255, 255, 255)); spriteInterface->End(); device->EndScene(); device->Present(NULL, NULL, NULL, NULL); [/code] Greatly appreciate any help anyone can offer, cheers Liam F
  7. I'm thinking now that a boundingBox for the entire model may not be worth it. My plan was to use the overall bounding box as an initial check and then check with each individual bone if a collision was found, in order to save processing time. But the initial Bounding Box will be calculated while the model is in bind pose, then when animating the model arms and legs will be moving in and out of the box all the time, so to keep it acurate the overall box would need to be recalculated each frame therefore negating the benefit of less time spent performing collision checks... So I guess thats my problem solved.
  8. It seems there is some kind of scaling being applied to the model itself during loading, though i'm not sure where. My loading code is based on the examples over at ( if anyone is familiar with it. Anyway i've got my Hierachy of Bounding boxes working as you can see at the bottom of this post. This is working because the positioning of the AABoundingBoxes is calculated using the World Matrix of the bone it belongs to which is what makes me think the model is being down scaled somewhere in the loading process. Maybe if i take the world Matrix of just one bone into consideration during loading and scale the BoundingBox by that matrix that should hopefuly work. Just need to make sure its before I personally do any scaling/rotating/positioning myself.
  9. I've uploaded an image to show the problem better in case I didn't explain it too well. As you can see the box is about the right shape just far to large.
  10. Hey guys, I've been working on my animated model class and i'm having an issue with calculating the AxisAlignedBoundingBox for the entire frame Hierachy. I've got the bounding box being calculated upon loading the model, and it is working to an extent. The problem is the resulting box is too large for some reason. The box is working in that it is the right shape and is adjusting itself as the model moves or rotates but its about 3-4x the size it should be. The code calculating the Box is as follows, This first part is at the end of the load function shortly after the call to D3DXLoadMeshHierarchyFromX() Vector3 min = Vector3(0, 0, 0), max = Vector3(0, 0, 0); FrameCalculateBoundingBox(pFrameRoot, &min, &max); boundsBox.arrBoundsPoints[0] = Vector3(min.x, min.y, min.z); boundsBox.arrBoundsPoints[1] = Vector3(max.x, min.y, min.z); boundsBox.arrBoundsPoints[2] = Vector3(min.x, max.y, min.z); boundsBox.arrBoundsPoints[3] = Vector3(max.x, max.y, min.z); boundsBox.arrBoundsPoints[4] = Vector3(min.x, min.y, max.z); boundsBox.arrBoundsPoints[5] = Vector3(max.x, min.y, max.z); boundsBox.arrBoundsPoints[6] = Vector3(min.x, max.y, max.z); boundsBox.arrBoundsPoints[7] = Vector3(max.x, max.y, max.z); The following is the function that calls its self recursivly to loop through the hieracrhy and get the min and max vertex positions to use for the BoundingBox. void AnimatedMesh::FrameCalculateBoundingBox(LPD3DXFRAME frame, Vector3 *min, Vector3 *max) { LPD3DXMESHCONTAINER meshContainer = frame->pMeshContainer; // If this Frame contains a mesh... while (meshContainer) { BYTE* pData = NULL; meshContainer->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pData); // Compute the Min and Max values for this frames mesh Vector3 tempMin, tempMax; D3DXComputeBoundingBox((Vector3*)pData, meshContainer->MeshData.pMesh->GetNumVertices(), D3DXGetFVFVertexSize(meshContainer->MeshData.pMesh->GetFVF()), &tempMin, &tempMax); meshContainer->MeshData.pMesh->UnlockVertexBuffer(); // If the min/max values are lower/greater then the current stored values, update them. min->x = min(min->x, tempMin.x); min->y = min(min->y, tempMin.y); min->z = min(min->z, tempMin.z); max->x = max(max->x, tempMax.x); max->y = max(max->y, tempMax.y); max->z = max(max->z, tempMax.z); meshContainer = meshContainer->pNextMeshContainer; } // Recurse for sibblings if (frame->pFrameSibling != NULL) FrameCalculateBoundingBox(frame->pFrameSibling, min, max); // Recurse for children if (frame->pFrameFirstChild != NULL) FrameCalculateBoundingBox(frame->pFrameFirstChild, min, max); } (Just to note the above code isn't handling the axis alignment thats done every frame created from this initial box dependant on the rotation/scaling/positioning of the model in question.) The bounding Sphere was easy enough with a call to D3DXFrameCalculateBoundingSphere() However I'm fairly sure there is no such function implemented for Bounding Boxes (I could be wrong). Thanks in advance for any help. (edited post to place code in source brackets instead of code) [Edited by - liamf1986 on October 28, 2010 11:49:46 AM]
  11. Multi texture terrain

    Yup you were right that was it ^^ I was missing a couple of other things aswell. For example I was never calling CreateVertexDeclaration() I was simply declaring the VertexDeclaration as above and then attempting to use it .... thanks for all the help its working well enough now :) For anyone else having trouble with VertexDeclarations I remembered reading a nice tutorial that gives the basics of using them and managed to track it down. You can find it at:- Thanks again Demirug
  12. Multi texture terrain

    Oh I see. Got it rendering with the vertexDeclaration now and removed all the FVF stuff. This hasn't fixed the problem, in fact it's lost all texture now. But I'm sure thats just my lack of experience with the vertexDeclaration hopefully I'll find my mistake somewhere. Nice that I understand the FVF stuff alittle better now thanks for that :)
  13. Multi texture terrain

    Hey Demirug, thanks for the reply. I had a feeling i didn't quite understand how the D3DFVF_TEXx flags were working. I did experiment with my own vertexDeclaration this morning sometime, it looked something like this. const D3DVERTEXELEMENT9 declaration[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0}, {0, sizeof(float) * 3, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, {0, sizeof(float) * 6, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, {0, sizeof(float) * 8, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, D3DDECL_END() }; As its only the second time i've used this (the first being in my mesh class) i was confused how to call CreateVertexBuffer(). I tried the following Device->CreateVertexBuffer(iNumVertices*sizeof(MULTITEXLITVERTEX), 0, D3DXGetDeclVertexSize(declaration, 0), D3DPOOL_DEFAULT, &terrainVertexBuffer, NULL) The part I was unsure about being the 3 passed item where it requests the FVF. When that didn't seem to work I wussed out and when back to using FVF XD I'll have to look into it more
  14. Hellos, I'm working on a multi texture terrain in C++ with Direct x. I did in it XNA about a year ago following this tutorial and this is a port of the final result. I'm using 4 textures, a different texture should be shown dependant on the height of the vertex being processed. Its not working however the weighting for texture 3 and 4 seems to be getting incorrect information within the shader. I'm fairly certain the problem is with my vertex declaration leading to information being passed to the shader incorrectly. I just can't seem to isolate the error. I'm using the following Vertex declaration, #define FVF_MULTITEXLITVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2) typedef struct _MULTITEXLITVERTEX { Vector3 vecPosition; Vector3 vecNormal; Vector2 vecTexCoords; Vector4 vecTextureWeights; } MULTITEXLITVERTEX; and below is the vertex shader code, MTVertexToPixel MultiTexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0, float4 inTexWeights: TEXCOORD1) { // unimportant code hidden Output.TextureWeights = inTexWeights; return Output; } and finally my redering code, void Terrain::Render(Camera cam) { // Set terrains VertexBuffer to the Graphics card Engine_Settings.D3D_Device->SetStreamSource(0, terrainVertexBuffer, 0, sizeof(MULTITEXLITVERTEX)); Engine_Settings.D3D_Device->SetFVF(FVF_MULTITEXLITVERTEX); // Set the terrains IndexBuffer to the Graphics card Engine_Settings.D3D_Device->SetIndices(terrainIndexBuffer); terrainEffect.Begin(); for (unsigned short i = 0; i < terrainEffect.GetPasses(); i++) { terrainEffect.BeginPass(i); Engine_Settings.D3D_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, iNumVertices, 0, (map.GetWidth()-1)*(map.GetHeight()-1)*2); terrainEffect.EndPass(); } terrainEffect.End(); } Any help is greatly appreciated thanks in advance ^^
  15. Woo Hoo i cracked it. had to completelty rewrite my rendering to use Device->DrawIndexedPrimitive() instead of DrawSubset(). Here are all the changes i had to make to my mesh class to get tangent information included to send over to the shader. First off here is the Vertex shader input structure. struct VS_IN { float4 Position : POSITION; float2 TexCoord : TEXCOORD0; float3 Normal : NORMAL; float3 Tangent : TANGENT; }; i had to define the custom vertex to match the shader input in the mesh.h struct CUSTOMVERTEX { D3DXVECTOR3 position; D3DXVECTOR3 normal; float tu; float tv; D3DXVECTOR3 tangent; }; IDirect3DVertexDeclaration9* vertexDeclaration; then declared all its usage. i did it globaly in the .cpp but i will make it properly object oriented now that it works. D3DVERTEXELEMENT9 declaration [] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 }, D3DDECL_END() }; i use the following function to load the model. I'v only showed the initial loading and then calculating of normals and tangent info. You might then need to handle materials and textures. void Mesh::InitialiseFromX(std::string filename) { LPBuffer materialBuffer; if (FAILED(D3DXLoadMeshFromX(filename.c_str(), D3DXMESH_SYSTEMMEM, Engine_Settings.D3D_Device, &adjacencyBuffer, &materialBuffer, NULL, &numMaterials, &mesh))) { std::string msg = "Unable to load mesh " + filename + ".\n"; MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK); Engine_Settings.EngineContinue = false; return; } LPMesh tempMesh; if (FAILED(mesh->CloneMesh(mesh->GetOptions(), declaration, Engine_Settings.D3D_Device, &tempMesh))) { MessageBox(NULL, "FAILED", "DOOOOM!", MB_OK); } if (FAILED(D3DXComputeNormals(tempMesh, NULL))) { std::string msg = "D3DXComputeNormals() failed on " + filename + ".\n"; MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK); Engine_Settings.EngineContinue = false; return; } if (FAILED(D3DXComputeTangent(tempMesh, 0, 0, D3DX_DEFAULT, TRUE, NULL))) { std::string msg = "D3DXComputeTangent() failed on " + filename + ".\n"; MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK); Engine_Settings.EngineContinue = false; return; } if (mesh != NULL) { mesh->Release(); mesh = NULL; } mesh = tempMesh; } this was my original render function. Just a normal simple model rendering function. effect->Begin(); for(unsigned short i = 0; i < effect->GetPasses(); i++) { effect->BeginPass(i); mesh->DrawSubset(0); effect->EndPass(); } effect->End(); This is the new rendering function using the custom vertex declaration void Mesh::Render(Effect* effect) { Engine_Settings.D3D_Device->SetStreamSource(0, meshVertexBuffer, 0, D3DXGetDeclVertexSize(declaration, 0)); Engine_Settings.D3D_Device->SetIndices(indexBuffer); unsigned long attrSize = 0; mesh->GetAttributeTable(NULL, &attrSize); D3DXATTRIBUTERANGE *pAttr = new D3DXATTRIBUTERANGE[attrSize]; mesh->GetAttributeTable(pAttr, &attrSize); Engine_Settings.D3D_Device->SetVertexDeclaration(vertexDeclaration); effect->Begin(); for(unsigned short i = 0; i < effect->GetPasses(); i++) { effect->BeginPass(i); for (unsigned long ii = 0; ii < attrSize; ii++) { Engine_Settings.D3D_Device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, pAttr[ii].VertexStart, pAttr[ii].VertexCount, pAttr[ii].FaceStart *3, pAttr[ii].FaceCount); } effect->EndPass(); } effect->End(); attrSize = NULL; if (pAttr) { delete[] pAttr; pAttr = NULL; } } I hope this can be of some help to someone else with similar issues. And thanks again for your reply adt7.