Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Mar 2013
Offline Last Active May 19 2015 01:25 PM

Topics I've Started

[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   0 downloads


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


Attached File  vertices.jpg   133.98KB   0 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
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:




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 
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:




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)




         byte[] data = new byte[65000];

         String translateddata = "";



         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");






         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");





         return translateddata;


     catch (IOException e)




     catch (InterruptedException e)







     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);
// 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);
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?

Vector of derived types problem

01 May 2014 - 03:16 AM

Solved! The problem was  Effects.push_back(new Position3NormalColor()); should have been Effects.push_back(new EffectPosition3NormalColor());



Hi, I have a problem with the following code:

class EffectPosition3NormalColor : virtual public IEffect


vector<IEffect*> Effects;
Effects.push_back(new Position3NormalColor());
It gives me the following error:
1>error C2664: 'void std::vector<_Ty>::push_back(IEffect *&&)' : cannot convert parameter 1 from 'Position3NormalColor *' to 'IEffect *&&'
1>          with
1>          [
1>              _Ty=IEffect *
1>          ]
1>          Reason: cannot convert from 'Position3NormalColor *' to 'IEffect *'

Isnt this possible when Position3NormalColor inherits from IEffect?

[Solved] Need help with a warning when compiling Double to float, loss of data

27 April 2014 - 01:44 AM

Hello, I get a warning when comiling my project. The project works as intended but would be nice to resolve the warning.


It says:

warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data

for each of these lines

DirectX::XMMATRIX rotationMatrix = DirectX::XMMatrixRotationY(0.5f*DirectX::XM_PI);
Eye = DirectX::XMVectorSet( x, 3.0f, z, 0.0f );
At = DirectX::XMVectorSet( x + sin(CameraRotationHorizontal), 3.0f,z + cos(CameraRotationHorizontal), 0.0f );

they are declared as the following types

DirectX::XMVECTOR Eye;
DirectX::XMMATRIX rotationMatrix
How do I solve these? They're all predefined types from the DirectX API with their assosciated functions, not sure what i can do here.