Jump to content

  • Log In with Google      Sign In   
  • Create Account

bjornp

Member Since 10 Mar 2013
Offline Last Active Feb 15 2016 07:02 AM

Topics I've Started

Problems with MFStartup(MF_VERSION)

09 February 2016 - 03:19 AM

Hello, I'm trying to add audio to my game, and to load audio files I want to use the Media Foundation, however when i try to initialize it with this line:

 

MFStartup(MF_VERSION);

 

it crashes, before the program even loads with the following error:

 

"Unable to activate Windows Store App '031...'. The process started but failed with error 'The App didn't start'."

 

If I uncomment this line the game starts, but I need it to use audio, what am I doing wrong? :o

 

/Björn


Problems writing a BMP exporter

18 October 2015 - 12:19 PM

I am having some troubles when generating a .bmp file, from the code below i expected it to come out in shades of red, but as you'll see from the included picture it becomes both blue and green instead. Any ideas why this is happening?

struct Pixel
{
   unsigned char r; 
   unsigned char g;
   unsigned char b;
};

The main function generates the vector that holds all the pixel data, the color depends on the height of the image.

int main()
{
   std::vector<Pixel> ImageData;
   unsigned int Width = 640;
   unsigned int Height = 480;
 
   for (unsigned int i = 0; i < Height; i++)
   {
      for (unsigned int j = 0; j < Width; j++)
      {
         Pixel temp;
         temp.r = i % 255;
         temp.g = 0;
         temp.b = 0;
         ImageData.push_back(temp);
      }
   }
 
   WriteBitMap("raytracer.bmp", Width, Height, ImageData);
 
   return 0;
}
 
Writes the 2 headers needed for BMP files and then the image data.
bool WriteBitMap(std::string Filename, const unsigned int Width, const unsigned int Height, std::vector<Pixel> ImageData)
{
   //Create fileformat headers
 
   BitmapFileHeader fh;
   BitmapInfoHeader ih;
 
   fh.bmtype[0] = 'B';
   fh.bmtype[1] = 'M';
   fh.iFileSize = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + (Width*Height * 3);
   fh.iOffsetBits = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader);
 
   ih.iSizeHeader = 40;
   ih.iWidth = Width;
   ih.iHeight = Height;
   ih.iPlanes = 1;
   ih.iBitCount = 24;
   ih.Compression = 0;
 
   //Open file for writing
 
   std::ofstream file;
   file.open(Filename, std::ios::out);
 
   file.write(reinterpret_cast<char*>(&fh), sizeof(BitmapFileHeader));
   file.write(reinterpret_cast<char*>(&ih), sizeof(BitmapInfoHeader));
 
   for (auto it = ImageData.begin(); it != ImageData.end(); ++it)
   {
      char red = it->r;
      char green = 0;
      char blue = 0;
      file.write(&blue, sizeof(char));
      file.write(&green, sizeof(char));
      file.write(&red, sizeof(char));
   }
 
   file.close();
   return false;
}

 

Edit:

See solution further down smile.png

 

File needed to be opened in binary mode.


[Solved]Garbage data in Vertexbuffer

02 February 2015 - 01:07 AM

Hello, when loading data from my application into the Vertexbuffer, it seems that random data is loaded instead of my vertices. See picture:

 

Attached File  vb.jpg   181.92KB   4 downloads

 

However, my vertices are defiened as follows (there are 24 in total, model is a cube):

 

Attached File  vertices.jpg   133.98KB   5 downloads

 

 

I create my buffer like this:

D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(SimpleVertex2) * _vertexes.size();
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA InitialVertexData;
ZeroMemory(&InitialVertexData, sizeof(InitialVertexData));
InitialVertexData.pSysMem = &_vertexes;
InitialVertexData.SysMemPitch = 0;
InitialVertexData.SysMemSlicePitch = 0;
_gfx->GetDevice()->CreateBuffer(&vertexBufferDesc, &InitialVertexData, &_vertexbuffer);

I set my vertexbuffer before rendering:

unsigned int _stride = sizeof(SimpleVertex2);
unsigned int _offset = 0;
_gfx->GetContext()->IASetVertexBuffers(0, 1, &_vertexbuffer, &_stride, &_offset);

My vertexformat:

struct SimpleVertex2
{
XMFLOAT4 Pos;
XMFLOAT3 Normal;
};

I am having trouble locating the source of the error. Hoping you can help my once again with my problems smile.png.

 

 

 

Edit: The problem was on this line:

 

InitialVertexData.pSysMem = &_vertexes;

 

When using vectors to initialize VBs you need to use:

 

InitialVertexData.pSysMem = &_vertexes[0];

GET request contains addional non wanted data for XML document

12 September 2014 - 08:10 AM

I have a project where i download a XML file from a server using sockets, and doing a request with GET. This is the file:

 

http://api.yr.no/weatherapi/locationforecast/1.9/?lat=60.10;lon=9.58;msl=70

 

However when receiving the file it contains the string "008000" in some places of the file, which is not present when opened in my browser, and this string breaks the XML formating. Example:

<location altitude="70" latitude="6 
008000
0.1000" longitude="9.5800">

I used wireshark to see if this was also sent from the server, or if it was created on my side, but it seems the server sends this:

 

HM4LvS0.jpg

 

Any ideas on how to fix this?

 

My code

 
import java.io.DataInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.OutputStream;

import java.io.PrintWriter;

import java.net.*;
public class NetClient

{
    Socket clientSocket = new Socket();

    InetSocketAddress ip = new InetSocketAddress("api.yr.no", 80);

 

    public String GetData(float _latitude, float _longitude, int _msl)

    {

     try

     {

         byte[] data = new byte[65000];

         String translateddata = "";

      

         clientSocket.connect(ip);

         DataInputStream inData = new DataInputStream(clientSocket.getInputStream());

         OutputStream outData = clientSocket.getOutputStream();

        

         PrintWriter pw = new PrintWriter(outData, false);

         pw.print("GET " + "/weatherapi/locationforecast/1.9/?lat=" + _latitude + ";lon=" + _longitude + ";msl=" + _msl +  " HTTP/1.1\r\n");

         pw.print("Host: api.yr.no\r\n");

         pw.print("Accept: text/xml\r\n");

         pw.print("\r\n");

         pw.flush();

        

         Thread.sleep(1000);

        

         int bytesread = 0;

         int i = 0;

         while (bytesread != -1)

         {

          bytesread = inData.read(data);

          if (bytesread != -1)

          {          

           translateddata = translateddata + new String(data);  

           String temp = new String(data);

                 PrintWriter file;

           file = new PrintWriter("weather" + i++ + ".txt");

                 file.write(temp);

                 file.close();
          }

         }

         clientSocket.close();

         return translateddata;

     }

     catch (IOException e)

     {

      

     }

     catch (InterruptedException e)

     {

   e.printStackTrace();

  }

     finally

     {

      

     }
     return "Something went wrong when trying to download data from remote server!";

    }

   

}
 

[Solved] Depth not working

07 June 2014 - 11:44 AM

I have a problem where objects behind other objects are rendered.

 

I have set up my depth buffer as follows (code from msdn):

ID3D11Texture2D* pDepthStencil = NULL;
D3D11_TEXTURE2D_DESC descDepth;
descDepth.Width = 640;
descDepth.Height = 480;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
D3DDevice->CreateTexture2D(&descDepth, NULL, &pDepthStencil);
 
D3D11_DEPTH_STENCIL_DESC dsDesc;
 
// Depth test parameters
dsDesc.DepthEnable = true;
dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
dsDesc.DepthFunc = D3D11_COMPARISON_LESS;
 
// Stencil test parameters
dsDesc.StencilEnable = true;
dsDesc.StencilReadMask = 0xFF;
dsDesc.StencilWriteMask = 0xFF;
 
// Stencil operations if pixel is front-facing
dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
 
// Stencil operations if pixel is back-facing
dsDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
dsDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
dsDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
 
// Create depth stencil state
ID3D11DepthStencilState * pDSState;
D3DDevice->CreateDepthStencilState(&dsDesc, &pDSState);
 
// Bind depth stencil state
D3DDeviceContext->OMSetDepthStencilState(pDSState, 1);
 
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
descDSV.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
descDSV.Flags = 0;
 
// Create the depth stencil view
D3DDevice->CreateDepthStencilView(pDepthStencil, // Depth stencil texture
&descDSV, // Depth stencil desc
&pDSV);  // [out] Depth stencil view
 
// Bind the depth stencil view
D3DDeviceContext->OMSetRenderTargets(1,          // One rendertarget view
&RenderTargetView,      // Render target view, created earlier
pDSV);     // Depth stencil view for the render target
 
And I clear the buffer every frame:
 
D3DDeviceContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
 
I get no warnings in the output, have i forgotten something?

PARTNERS