<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C++ Graphikprogramm mit chat Kreuzen]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich versuche mein Graphikprogramm mit einem Chat clientprogramm zu kreuzen , habe aber keine ahnung wie das geht. Ich hoffe mir kann jemand helfen</p>
<p>Code des Graphikprogramms:</p>
<pre><code>#pragma comment (lib, &quot;wsock32.lib&quot;)

#include &quot;Client.h&quot;
#include &quot;stdio.h&quot;
#include &lt;conio.h&gt;

#include &lt;iostream&gt;
#include &lt;winsock.h&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;

#include &quot;resource.h&quot; 
#include &lt;windows.h&gt;
#include &lt;math.h&gt;
#include &lt;d3d9.h&gt;
#include &lt;d3dx9.h&gt; // DirectX Extensions Utility library

#define DIRECTINPUT_VERSION 0x0800
#include &lt;dinput.h&gt; // DirectX/Direct Input

#define PI 3.141592654f

typedef struct
{

   float x, y, z;
} point_t;

typedef struct
{
	float neigen;
   float Rotation;   
   point_t Location; 
} camera_t;

LPDIRECT3D9          g_pDirect3D = NULL;
LPDIRECT3DDEVICE9    g_pDirect3D_Device = NULL;
LPDIRECTINPUT8       g_pDI = NULL; // The DirectInput object
LPDIRECTINPUTDEVICE8 g_pKeyboard = NULL; // The keyboard device 
BYTE                 dx_keyboard_state[256]; // DirectInput keyboard state buffer 
camera_t             g_Camera;

LRESULT WINAPI WndProc(HWND hwnd,  UINT msg, WPARAM wParam, LPARAM lParam);
void CalcMatrices(void);
void RenderFrame(void);

HRESULT CreateKeyboardDirectInputDevice(HWND hWnd);
void HandleKeys(void);
HRESULT ReadImmediateData(HWND hWnd);
VOID FreeDirectInput(void);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
{
   MSG msg;
   WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC, WndProc, 0, 0, hInstance, 
                    NULL, NULL, NULL, NULL, &quot;DX9_TUTORIAL3_CLASS&quot;, NULL};
   RegisterClassEx(&amp;wc);
   HWND hMainWnd = CreateWindow(&quot;DX9_TUTORIAL3_CLASS&quot;, &quot;DirectX 9 Tutorial 3 - Simple 3D Room&quot;, WS_OVERLAPPEDWINDOW,
                                0, 0, 1024, 768, NULL, NULL, hInstance, NULL);

   g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);
   D3DPRESENT_PARAMETERS PresentParams;
   memset(&amp;PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));
   PresentParams.Windowed = TRUE;
   PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
   PresentParams.EnableAutoDepthStencil = TRUE; // turn on z-buffering
   PresentParams.AutoDepthStencilFormat = D3DFMT_D16;

   g_pDirect3D-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &amp;PresentParams, &amp;g_pDirect3D_Device);
      D3DXMATRIXA16 ProjectionMatrix;
   D3DXMatrixPerspectiveFovLH(&amp;ProjectionMatrix, PI/4, 1.0f, 1.0f, 5000.0f);
   g_pDirect3D_Device-&gt;SetTransform(D3DTS_PROJECTION, &amp;ProjectionMatrix);
    D3DXMATRIXA16 WorldTransformMatrix;
   D3DXMatrixIdentity(&amp;WorldTransformMatrix);
   g_pDirect3D_Device-&gt;SetTransform(D3DTS_WORLD, &amp;WorldTransformMatrix);
     g_pDirect3D_Device-&gt;SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);    g_pDirect3D_Device-&gt;SetRenderState(D3DRS_LIGHTING, FALSE);
   ShowWindow(hMainWnd, nShow);
   UpdateWindow(hMainWnd);
   while(PeekMessage(&amp;msg, NULL, 0, 0, TRUE))
   {
      DispatchMessage(&amp;msg);
      ReadImmediateData(hMainWnd); // get keyboard state
      HandleKeys();
      RenderFrame();
      InvalidateRect(hMainWnd, NULL, FALSE);
   }
   g_pDirect3D_Device-&gt;Release();
   g_pDirect3D-&gt;Release();
   FreeDirectInput();

   return(0);
}
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   HRESULT hr = S_OK;

   switch(msg)
   {
      case WM_CREATE:
         hr = CreateKeyboardDirectInputDevice(hwnd);

         if(FAILED(hr))
         {
            ::MessageBox(hwnd, &quot;Could not create DirectInput device for keyboard.&quot;, &quot;Error&quot;, MB_OK);
            PostQuitMessage(0);
            break;
         }
         g_Camera.Location.x = -64;
         g_Camera.Location.y = 40;
         g_Camera.Location.z = -550;
         g_Camera.Rotation = PI/2.0f;

         return(0);
      case WM_DESTROY:
         PostQuitMessage(0);
         return(0);
      case WM_ACTIVATE:
         if(WA_INACTIVE != wParam &amp;&amp; g_pKeyboard)
         {
            hr = g_pKeyboard-&gt;Acquire();

            #ifdef _DEBUG
            if(!SUCCEEDED(hr))
               MessageBox(hwnd, &quot;Acquire() for DirectInput keyboard failed.&quot;, &quot;Error&quot;, MB_OK);
            #endif
         }
         return(0);
      case WM_PAINT:
         RenderFrame();
         ValidateRect(hwnd, NULL);

         return(0);
   }
   return(DefWindowProc(hwnd, msg, wParam, lParam));
}
void RenderFrame(void)
{
	float höhe_mauer = 190;
	float x_wall_front1 = -325;
	float z_wall_right1 = -400;
   // give DirectX the vertex information of the scene
   #pragma region Setup Vertices
   #define NUM_VERTICES 220

   #define FRONT_WALL_COLOR 0xa9a9a9;

    struct D3DVERTEX {float x, y, z; DWORD color;} vertices[NUM_VERTICES];

   vertices[0].x = x_wall_front1;
   vertices[0].y = 0; 
   vertices[0].z = 0; 
   vertices[0].color = FRONT_WALL_COLOR;

   vertices[1].x = 0;
   vertices[1].y = 0;
   vertices[1].z = 0; 
   vertices[1].color = FRONT_WALL_COLOR;

   vertices[2].x = 0;
   vertices[2].y = höhe_mauer;
   vertices[2].z = 0; 
   vertices[2].color = FRONT_WALL_COLOR;

   vertices[3].x = x_wall_front1;
   vertices[3].y = 0;
   vertices[3].z = 0; 
   vertices[3].color = FRONT_WALL_COLOR;

   vertices[4].x = 0;
   vertices[4].y = höhe_mauer;
   vertices[4].z = 0; 
   vertices[4].color = FRONT_WALL_COLOR;

   vertices[5].x = x_wall_front1;
   vertices[5].y = höhe_mauer;
   vertices[5].z = 0; 
   vertices[5].color = FRONT_WALL_COLOR;
   LPDIRECT3DVERTEXBUFFER9 pVertexObject = NULL;
   void *pVertexBuffer = NULL;

   if(FAILED(g_pDirect3D_Device-&gt;CreateVertexBuffer(NUM_VERTICES*sizeof(D3DVERTEX), 0, 
             D3DFVF_XYZ|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &amp;pVertexObject, NULL)))
      return;

   if(FAILED(pVertexObject-&gt;Lock(0, NUM_VERTICES*sizeof(D3DVERTEX), &amp;pVertexBuffer, 0)))
      return;
   memcpy(pVertexBuffer, vertices, NUM_VERTICES*sizeof(D3DVERTEX));
   pVertexObject-&gt;Unlock();
   #pragma endregion 

     #pragma region Render Scene
   g_pDirect3D_Device-&gt;Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // clear frame
   if(SUCCEEDED(g_pDirect3D_Device-&gt;BeginScene()))
   {
      CalcMatrices();
      g_pDirect3D_Device-&gt;SetStreamSource(0, pVertexObject, 0, sizeof(D3DVERTEX));
      g_pDirect3D_Device-&gt;SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
      g_pDirect3D_Device-&gt;DrawPrimitive(D3DPT_TRIANGLELIST, 0, NUM_VERTICES/3);
      g_pDirect3D_Device-&gt;EndScene();
   }

   g_pDirect3D_Device-&gt;Present(NULL, NULL, NULL, NULL);
   pVertexObject-&gt;Release();
   #pragma endregion
}

void CalcMatrices(void)
{
   D3DXMATRIXA16 ViewMatrix;
   D3DXVECTOR3 EyePoint(g_Camera.Location.x, g_Camera.Location.y, g_Camera.Location.z);
   D3DXVECTOR3 LookAt(g_Camera.Location.x+cos(g_Camera.Rotation), g_Camera.Location.y+tan(g_Camera.neigen), g_Camera.Location.z+sin(g_Camera.Rotation));
   D3DXVECTOR3 UpVector(0.0f, 1.0f, 0.0f);
   D3DXMatrixLookAtLH(&amp;ViewMatrix, &amp;EyePoint, &amp;LookAt, &amp;UpVector);
   g_pDirect3D_Device-&gt;SetTransform(D3DTS_VIEW, &amp;ViewMatrix); 
}
HRESULT CreateKeyboardDirectInputDevice(HWND hWnd)
{
    HRESULT hr;
    BOOL    bExclusive;
    BOOL    bForeground;
    BOOL    bImmediate;
    BOOL    bDisableWindowsKey;
    DWORD   dwCoopFlags;

    FreeDirectInput();

    bExclusive         = FALSE;
    bForeground        = TRUE;
    bImmediate         = TRUE;
    bDisableWindowsKey = FALSE;

    if( bExclusive )
        dwCoopFlags = DISCL_EXCLUSIVE;
    else
        dwCoopFlags = DISCL_NONEXCLUSIVE;

    if( bForeground )
        dwCoopFlags |= DISCL_FOREGROUND;
    else
        dwCoopFlags |= DISCL_BACKGROUND;

    if( bDisableWindowsKey &amp;&amp; !bExclusive &amp;&amp; bForeground )
        dwCoopFlags |= DISCL_NOWINKEY;

    if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
                                         IID_IDirectInput8, (VOID**)&amp;g_pDI, NULL ) ) )
        return hr;

    if( FAILED( hr = g_pDI-&gt;CreateDevice( GUID_SysKeyboard, &amp;g_pKeyboard, NULL ) ) )
        return hr;

    if( FAILED( hr = g_pKeyboard-&gt;SetDataFormat( &amp;c_dfDIKeyboard ) ) )
        return hr;

      hr = g_pKeyboard-&gt;SetCooperativeLevel( hWnd, dwCoopFlags );
    if( hr == DIERR_UNSUPPORTED &amp;&amp; !bForeground &amp;&amp; bExclusive )
    {
        FreeDirectInput();
        MessageBox( hWnd, &quot;SetCooperativeLevel() returned DIERR_UNSUPPORTED.\n&quot;
                          &quot;For security reasons, background exclusive keyboard\n&quot;
                          &quot;access is not allowed.&quot;, &quot;Keyboard&quot;, MB_OK );
        return S_OK;
    }

    if( FAILED(hr) )
        return hr;

        hr = g_pKeyboard-&gt;Acquire(); 

    return S_OK;
}

HRESULT ReadImmediateData(HWND hWnd)
{
    HRESULT hr;

    if( NULL == g_pKeyboard ) 
        return S_OK;

    ZeroMemory( dx_keyboard_state, sizeof(dx_keyboard_state) );
    hr = g_pKeyboard-&gt;GetDeviceState( sizeof(dx_keyboard_state), dx_keyboard_state );
    if( FAILED(hr) ) 
    {
        hr = g_pKeyboard-&gt;Acquire();
        while( hr == DIERR_INPUTLOST ) 
            hr = g_pKeyboard-&gt;Acquire();
        return S_OK; 
    }

    return S_OK;
}
void HandleKeys(void)
{
...

}

#define SAFE_RELEASE(p) { if(p) { (p)-&gt;Release(); (p)=NULL; } }

VOID FreeDirectInput(void)
{
      if( g_pKeyboard ) 
        g_pKeyboard-&gt;Unacquire();

    // Release any DirectInput objects.
    SAFE_RELEASE( g_pKeyboard );
    SAFE_RELEASE( g_pDI );
}
</code></pre>
<p>Code des Chat-Clients:</p>
<pre><code>#include &quot;Client.h&quot;

#include &lt;conio.h&gt;

Client Client::m_Instance;
bool Client::StartUp()
{
	WSADATA wsa;
	int rc = WSAStartup(MAKEWORD(2, 0), &amp;wsa);
	if(rc == SOCKET_ERROR)
	{
		std::cout &lt;&lt; &quot;Fehler beim Starten des Servers...&quot; &lt;&lt; std::endl;
		return false;
	}
	return true;
}
bool Client::CreateConnectSocket(char* argv[2])
{
	int rc;

	s = socket(AF_INET, SOCK_STREAM, 0);
	if(s == INVALID_SOCKET)
	{
		std::cout &lt;&lt; &quot;Socket konnte nicht erstellt werden.\n&quot;;
		return false;
	}

	addr.sin_addr.s_addr = inet_addr(&quot;192.168.2.107&quot;);
	addr.sin_port        = htons(111);
	addr.sin_family      = AF_INET;

	rc = connect(s, (SOCKADDR*)&amp;addr, sizeof(SOCKADDR));
	if(rc == SOCKET_ERROR)
	{
		std::cout &lt;&lt; &quot;Verbindung fehlgeschlagen.\n&quot;;
		return false;
	}

	return true;
}
int Client::ClientMain(char* argv[2])
{
	if(!StartUp())
		return 1;

	if(!CreateConnectSocket(argv))
		return 2;

	int         rc = 0;
	fd_set      fdSetRead;
	char        buffer[1024];
	char        buffera[1024];
	char        c;
	int         bufpos = 0;
	TIMEVAL     timeout;
	bool        mainloop = true;

	std::cout &lt;&lt; &quot;Alles erfolgreich gestartet und verbunden.\n&quot;;

	while(rc != SOCKET_ERROR &amp;&amp; mainloop)
	{
		while(kbhit())
		{
			c = getch(); 
			if(c==13)
			{ 
				if(strcmp(buffer, &quot;exit&quot;) == 0)
				{
					mainloop = false;
					break;
				}
				rc = send(s,buffer,bufpos, 0); 
			    bufpos = 0; 
			}
			else
				buffer[bufpos++]=c; 
		} 
		buffer[bufpos] = '\0'; 

		FD_ZERO(&amp;fdSetRead);
		FD_SET(s, &amp;fdSetRead);

		timeout.tv_sec  = 0;
		timeout.tv_usec = 0;

		while((rc = select(0, &amp;fdSetRead, 0, 0, &amp;timeout)) &gt; 0)
		{
			rc = recv(s, buffera, 1023, 0);

			if(rc == 0)
			{
				std::cout &lt;&lt; &quot;Der Server hat die Verbindung unterbrochen.\n&quot;;
				break;
			}
			else if(rc == SOCKET_ERROR)
			{
				std::cout &lt;&lt; &quot;Empfangen der Nachricht fehlgeschlagen: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; '\n';
				break;
			}

			buffera[rc] = '\0';
			std::cout &lt;&lt; buffera &lt;&lt; '\n';
		}	

		Sleep(1);
	}

	std::cout &lt;&lt; &quot;Client wird beendet.\n&quot;;

	closesocket(s);
	WSACleanup();

	return 0;
}
</code></pre>
<p>Ich hoffe es kann mir jemand helfen</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/236932/c-graphikprogramm-mit-chat-kreuzen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 15:35:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/236932.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Mar 2009 23:32:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ Graphikprogramm mit chat Kreuzen on Sat, 21 Mar 2009 23:32:21 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich versuche mein Graphikprogramm mit einem Chat clientprogramm zu kreuzen , habe aber keine ahnung wie das geht. Ich hoffe mir kann jemand helfen</p>
<p>Code des Graphikprogramms:</p>
<pre><code>#pragma comment (lib, &quot;wsock32.lib&quot;)

#include &quot;Client.h&quot;
#include &quot;stdio.h&quot;
#include &lt;conio.h&gt;

#include &lt;iostream&gt;
#include &lt;winsock.h&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;

#include &quot;resource.h&quot; 
#include &lt;windows.h&gt;
#include &lt;math.h&gt;
#include &lt;d3d9.h&gt;
#include &lt;d3dx9.h&gt; // DirectX Extensions Utility library

#define DIRECTINPUT_VERSION 0x0800
#include &lt;dinput.h&gt; // DirectX/Direct Input

#define PI 3.141592654f

typedef struct
{

   float x, y, z;
} point_t;

typedef struct
{
	float neigen;
   float Rotation;   
   point_t Location; 
} camera_t;

LPDIRECT3D9          g_pDirect3D = NULL;
LPDIRECT3DDEVICE9    g_pDirect3D_Device = NULL;
LPDIRECTINPUT8       g_pDI = NULL; // The DirectInput object
LPDIRECTINPUTDEVICE8 g_pKeyboard = NULL; // The keyboard device 
BYTE                 dx_keyboard_state[256]; // DirectInput keyboard state buffer 
camera_t             g_Camera;

LRESULT WINAPI WndProc(HWND hwnd,  UINT msg, WPARAM wParam, LPARAM lParam);
void CalcMatrices(void);
void RenderFrame(void);

HRESULT CreateKeyboardDirectInputDevice(HWND hWnd);
void HandleKeys(void);
HRESULT ReadImmediateData(HWND hWnd);
VOID FreeDirectInput(void);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
{
   MSG msg;
   WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC, WndProc, 0, 0, hInstance, 
                    NULL, NULL, NULL, NULL, &quot;DX9_TUTORIAL3_CLASS&quot;, NULL};
   RegisterClassEx(&amp;wc);
   HWND hMainWnd = CreateWindow(&quot;DX9_TUTORIAL3_CLASS&quot;, &quot;DirectX 9 Tutorial 3 - Simple 3D Room&quot;, WS_OVERLAPPEDWINDOW,
                                0, 0, 1024, 768, NULL, NULL, hInstance, NULL);

   g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);
   D3DPRESENT_PARAMETERS PresentParams;
   memset(&amp;PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));
   PresentParams.Windowed = TRUE;
   PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
   PresentParams.EnableAutoDepthStencil = TRUE; // turn on z-buffering
   PresentParams.AutoDepthStencilFormat = D3DFMT_D16;

   g_pDirect3D-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &amp;PresentParams, &amp;g_pDirect3D_Device);
      D3DXMATRIXA16 ProjectionMatrix;
   D3DXMatrixPerspectiveFovLH(&amp;ProjectionMatrix, PI/4, 1.0f, 1.0f, 5000.0f);
   g_pDirect3D_Device-&gt;SetTransform(D3DTS_PROJECTION, &amp;ProjectionMatrix);
    D3DXMATRIXA16 WorldTransformMatrix;
   D3DXMatrixIdentity(&amp;WorldTransformMatrix);
   g_pDirect3D_Device-&gt;SetTransform(D3DTS_WORLD, &amp;WorldTransformMatrix);
     g_pDirect3D_Device-&gt;SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);    g_pDirect3D_Device-&gt;SetRenderState(D3DRS_LIGHTING, FALSE);
   ShowWindow(hMainWnd, nShow);
   UpdateWindow(hMainWnd);
   while(PeekMessage(&amp;msg, NULL, 0, 0, TRUE))
   {
      DispatchMessage(&amp;msg);
      ReadImmediateData(hMainWnd); // get keyboard state
      HandleKeys();
      RenderFrame();
      InvalidateRect(hMainWnd, NULL, FALSE);
   }
   g_pDirect3D_Device-&gt;Release();
   g_pDirect3D-&gt;Release();
   FreeDirectInput();

   return(0);
}
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   HRESULT hr = S_OK;

   switch(msg)
   {
      case WM_CREATE:
         hr = CreateKeyboardDirectInputDevice(hwnd);

         if(FAILED(hr))
         {
            ::MessageBox(hwnd, &quot;Could not create DirectInput device for keyboard.&quot;, &quot;Error&quot;, MB_OK);
            PostQuitMessage(0);
            break;
         }
         g_Camera.Location.x = -64;
         g_Camera.Location.y = 40;
         g_Camera.Location.z = -550;
         g_Camera.Rotation = PI/2.0f;

         return(0);
      case WM_DESTROY:
         PostQuitMessage(0);
         return(0);
      case WM_ACTIVATE:
         if(WA_INACTIVE != wParam &amp;&amp; g_pKeyboard)
         {
            hr = g_pKeyboard-&gt;Acquire();

            #ifdef _DEBUG
            if(!SUCCEEDED(hr))
               MessageBox(hwnd, &quot;Acquire() for DirectInput keyboard failed.&quot;, &quot;Error&quot;, MB_OK);
            #endif
         }
         return(0);
      case WM_PAINT:
         RenderFrame();
         ValidateRect(hwnd, NULL);

         return(0);
   }
   return(DefWindowProc(hwnd, msg, wParam, lParam));
}
void RenderFrame(void)
{
	float höhe_mauer = 190;
	float x_wall_front1 = -325;
	float z_wall_right1 = -400;
   // give DirectX the vertex information of the scene
   #pragma region Setup Vertices
   #define NUM_VERTICES 220

   #define FRONT_WALL_COLOR 0xa9a9a9;

    struct D3DVERTEX {float x, y, z; DWORD color;} vertices[NUM_VERTICES];

   vertices[0].x = x_wall_front1;
   vertices[0].y = 0; 
   vertices[0].z = 0; 
   vertices[0].color = FRONT_WALL_COLOR;

   vertices[1].x = 0;
   vertices[1].y = 0;
   vertices[1].z = 0; 
   vertices[1].color = FRONT_WALL_COLOR;

   vertices[2].x = 0;
   vertices[2].y = höhe_mauer;
   vertices[2].z = 0; 
   vertices[2].color = FRONT_WALL_COLOR;

   vertices[3].x = x_wall_front1;
   vertices[3].y = 0;
   vertices[3].z = 0; 
   vertices[3].color = FRONT_WALL_COLOR;

   vertices[4].x = 0;
   vertices[4].y = höhe_mauer;
   vertices[4].z = 0; 
   vertices[4].color = FRONT_WALL_COLOR;

   vertices[5].x = x_wall_front1;
   vertices[5].y = höhe_mauer;
   vertices[5].z = 0; 
   vertices[5].color = FRONT_WALL_COLOR;
   LPDIRECT3DVERTEXBUFFER9 pVertexObject = NULL;
   void *pVertexBuffer = NULL;

   if(FAILED(g_pDirect3D_Device-&gt;CreateVertexBuffer(NUM_VERTICES*sizeof(D3DVERTEX), 0, 
             D3DFVF_XYZ|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &amp;pVertexObject, NULL)))
      return;

   if(FAILED(pVertexObject-&gt;Lock(0, NUM_VERTICES*sizeof(D3DVERTEX), &amp;pVertexBuffer, 0)))
      return;
   memcpy(pVertexBuffer, vertices, NUM_VERTICES*sizeof(D3DVERTEX));
   pVertexObject-&gt;Unlock();
   #pragma endregion 

     #pragma region Render Scene
   g_pDirect3D_Device-&gt;Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // clear frame
   if(SUCCEEDED(g_pDirect3D_Device-&gt;BeginScene()))
   {
      CalcMatrices();
      g_pDirect3D_Device-&gt;SetStreamSource(0, pVertexObject, 0, sizeof(D3DVERTEX));
      g_pDirect3D_Device-&gt;SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
      g_pDirect3D_Device-&gt;DrawPrimitive(D3DPT_TRIANGLELIST, 0, NUM_VERTICES/3);
      g_pDirect3D_Device-&gt;EndScene();
   }

   g_pDirect3D_Device-&gt;Present(NULL, NULL, NULL, NULL);
   pVertexObject-&gt;Release();
   #pragma endregion
}

void CalcMatrices(void)
{
   D3DXMATRIXA16 ViewMatrix;
   D3DXVECTOR3 EyePoint(g_Camera.Location.x, g_Camera.Location.y, g_Camera.Location.z);
   D3DXVECTOR3 LookAt(g_Camera.Location.x+cos(g_Camera.Rotation), g_Camera.Location.y+tan(g_Camera.neigen), g_Camera.Location.z+sin(g_Camera.Rotation));
   D3DXVECTOR3 UpVector(0.0f, 1.0f, 0.0f);
   D3DXMatrixLookAtLH(&amp;ViewMatrix, &amp;EyePoint, &amp;LookAt, &amp;UpVector);
   g_pDirect3D_Device-&gt;SetTransform(D3DTS_VIEW, &amp;ViewMatrix); 
}
HRESULT CreateKeyboardDirectInputDevice(HWND hWnd)
{
    HRESULT hr;
    BOOL    bExclusive;
    BOOL    bForeground;
    BOOL    bImmediate;
    BOOL    bDisableWindowsKey;
    DWORD   dwCoopFlags;

    FreeDirectInput();

    bExclusive         = FALSE;
    bForeground        = TRUE;
    bImmediate         = TRUE;
    bDisableWindowsKey = FALSE;

    if( bExclusive )
        dwCoopFlags = DISCL_EXCLUSIVE;
    else
        dwCoopFlags = DISCL_NONEXCLUSIVE;

    if( bForeground )
        dwCoopFlags |= DISCL_FOREGROUND;
    else
        dwCoopFlags |= DISCL_BACKGROUND;

    if( bDisableWindowsKey &amp;&amp; !bExclusive &amp;&amp; bForeground )
        dwCoopFlags |= DISCL_NOWINKEY;

    if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
                                         IID_IDirectInput8, (VOID**)&amp;g_pDI, NULL ) ) )
        return hr;

    if( FAILED( hr = g_pDI-&gt;CreateDevice( GUID_SysKeyboard, &amp;g_pKeyboard, NULL ) ) )
        return hr;

    if( FAILED( hr = g_pKeyboard-&gt;SetDataFormat( &amp;c_dfDIKeyboard ) ) )
        return hr;

      hr = g_pKeyboard-&gt;SetCooperativeLevel( hWnd, dwCoopFlags );
    if( hr == DIERR_UNSUPPORTED &amp;&amp; !bForeground &amp;&amp; bExclusive )
    {
        FreeDirectInput();
        MessageBox( hWnd, &quot;SetCooperativeLevel() returned DIERR_UNSUPPORTED.\n&quot;
                          &quot;For security reasons, background exclusive keyboard\n&quot;
                          &quot;access is not allowed.&quot;, &quot;Keyboard&quot;, MB_OK );
        return S_OK;
    }

    if( FAILED(hr) )
        return hr;

        hr = g_pKeyboard-&gt;Acquire(); 

    return S_OK;
}

HRESULT ReadImmediateData(HWND hWnd)
{
    HRESULT hr;

    if( NULL == g_pKeyboard ) 
        return S_OK;

    ZeroMemory( dx_keyboard_state, sizeof(dx_keyboard_state) );
    hr = g_pKeyboard-&gt;GetDeviceState( sizeof(dx_keyboard_state), dx_keyboard_state );
    if( FAILED(hr) ) 
    {
        hr = g_pKeyboard-&gt;Acquire();
        while( hr == DIERR_INPUTLOST ) 
            hr = g_pKeyboard-&gt;Acquire();
        return S_OK; 
    }

    return S_OK;
}
void HandleKeys(void)
{
...

}

#define SAFE_RELEASE(p) { if(p) { (p)-&gt;Release(); (p)=NULL; } }

VOID FreeDirectInput(void)
{
      if( g_pKeyboard ) 
        g_pKeyboard-&gt;Unacquire();

    // Release any DirectInput objects.
    SAFE_RELEASE( g_pKeyboard );
    SAFE_RELEASE( g_pDI );
}
</code></pre>
<p>Code des Chat-Clients:</p>
<pre><code>#include &quot;Client.h&quot;

#include &lt;conio.h&gt;

Client Client::m_Instance;
bool Client::StartUp()
{
	WSADATA wsa;
	int rc = WSAStartup(MAKEWORD(2, 0), &amp;wsa);
	if(rc == SOCKET_ERROR)
	{
		std::cout &lt;&lt; &quot;Fehler beim Starten des Servers...&quot; &lt;&lt; std::endl;
		return false;
	}
	return true;
}
bool Client::CreateConnectSocket(char* argv[2])
{
	int rc;

	s = socket(AF_INET, SOCK_STREAM, 0);
	if(s == INVALID_SOCKET)
	{
		std::cout &lt;&lt; &quot;Socket konnte nicht erstellt werden.\n&quot;;
		return false;
	}

	addr.sin_addr.s_addr = inet_addr(&quot;192.168.2.107&quot;);
	addr.sin_port        = htons(111);
	addr.sin_family      = AF_INET;

	rc = connect(s, (SOCKADDR*)&amp;addr, sizeof(SOCKADDR));
	if(rc == SOCKET_ERROR)
	{
		std::cout &lt;&lt; &quot;Verbindung fehlgeschlagen.\n&quot;;
		return false;
	}

	return true;
}
int Client::ClientMain(char* argv[2])
{
	if(!StartUp())
		return 1;

	if(!CreateConnectSocket(argv))
		return 2;

	int         rc = 0;
	fd_set      fdSetRead;
	char        buffer[1024];
	char        buffera[1024];
	char        c;
	int         bufpos = 0;
	TIMEVAL     timeout;
	bool        mainloop = true;

	std::cout &lt;&lt; &quot;Alles erfolgreich gestartet und verbunden.\n&quot;;

	while(rc != SOCKET_ERROR &amp;&amp; mainloop)
	{
		while(kbhit())
		{
			c = getch(); 
			if(c==13)
			{ 
				if(strcmp(buffer, &quot;exit&quot;) == 0)
				{
					mainloop = false;
					break;
				}
				rc = send(s,buffer,bufpos, 0); 
			    bufpos = 0; 
			}
			else
				buffer[bufpos++]=c; 
		} 
		buffer[bufpos] = '\0'; 

		FD_ZERO(&amp;fdSetRead);
		FD_SET(s, &amp;fdSetRead);

		timeout.tv_sec  = 0;
		timeout.tv_usec = 0;

		while((rc = select(0, &amp;fdSetRead, 0, 0, &amp;timeout)) &gt; 0)
		{
			rc = recv(s, buffera, 1023, 0);

			if(rc == 0)
			{
				std::cout &lt;&lt; &quot;Der Server hat die Verbindung unterbrochen.\n&quot;;
				break;
			}
			else if(rc == SOCKET_ERROR)
			{
				std::cout &lt;&lt; &quot;Empfangen der Nachricht fehlgeschlagen: &quot; &lt;&lt; WSAGetLastError() &lt;&lt; '\n';
				break;
			}

			buffera[rc] = '\0';
			std::cout &lt;&lt; buffera &lt;&lt; '\n';
		}	

		Sleep(1);
	}

	std::cout &lt;&lt; &quot;Client wird beendet.\n&quot;;

	closesocket(s);
	WSACleanup();

	return 0;
}
</code></pre>
<p>Ich hoffe es kann mir jemand helfen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684101</guid><dc:creator><![CDATA[Master-112]]></dc:creator><pubDate>Sat, 21 Mar 2009 23:32:21 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Graphikprogramm mit chat Kreuzen on Sat, 21 Mar 2009 23:33:39 GMT]]></title><description><![CDATA[<p>Nöö...<br />
Falsches Forum,<br />
Falsches Code-Tags,<br />
Falsche Fehlerbeschreibung (bzw KEINE!!)</p>
<p>Viel Spass weiterhin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684102</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sat, 21 Mar 2009 23:33:39 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Graphikprogramm mit chat Kreuzen on Sat, 21 Mar 2009 23:57:09 GMT]]></title><description><![CDATA[<p>Um Firefighter zu ergänzen:</p>
<ul>
<li>Zu viel Code</li>
<li>Keine Eigeninitiative</li>
</ul>
<p>Lies dir bitte durch, <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-200753.html" rel="nofollow">wie man Fragen richtig stellt</a>. Fast alle dieser Punkte hast du nämlich missachtet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684113</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684113</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 21 Mar 2009 23:57:09 GMT</pubDate></item></channel></rss>