crgd12吧 关注:5贴子:104
  • 3回复贴,共1
。。。。


1楼2012-01-03 04:21回复
    void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
    {
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat; /* get the device context (DC) */
    *hDC = GetDC (hWnd); /* set the pixel format for the DC */
    ZeroMemory (&pfd, sizeof (pfd));
    pfd.nSize = sizeof (pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
    PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ChoosePixelFormat (*hDC, &pfd);
    SetPixelFormat (*hDC, iFormat, &pfd); /* create and enable the render context (RC) */
    *hRC = wglCreateContext( *hDC );
    wglMakeCurrent( *hDC, *hRC ); }
    /******************
    * Disable OpenGL
    *
    ******************/ void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
    {
    wglMakeCurrent (NULL, NULL);
    wglDeleteContext (hRC);
    ReleaseDC (hWnd, hDC);
    }


    2楼2012-01-03 08:16
    回复
      #define WIN32_LEAN_AND_MEAN
      #include <windows.h>
      #include <windowsx.h>
      #include <tchar.h>
      #include <d3d9.h>
      LPDIRECT3D9 g_pD3D;
      LPDIRECT3DDEVICE9 g_pD3DDevice; HRESULT InitializeD3D(HWND hWnd)
      { if (NULL == (g_pD3D=Direct3DCreate9(D3D_SDK_VERSION)))
      {
      return FALSE;
      } D3DPRESENT_PARAMETERS d3dpp;
      ZeroMemory(&d3dpp, sizeof(d3dpp));
      d3dpp.Windowed = TRUE;
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
      d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
      {
      return E_FAIL;
      }
      return TRUE;
      } void Render()
      {
      g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(45, 50, 170), 1.0f, 0); if (SUCCEEDED(g_pD3DDevice->BeginScene()))
      {
      g_pD3DDevice->EndScene();
      } g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
      } void Cleanup()
      {
      if (g_pD3DDevice != NULL)
      {
      g_pD3DDevice->Release();
      }
      if (g_pD3D != NULL)
      {
      g_pD3D->Release();
      }
      } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
      {
      switch (message)
      {
      case WM_DESTROY:
      Cleanup();
      PostQuitMessage(0);
      return 0; case WM_PAINT:
      Render();
      ValidateRect(hWnd, NULL);
      return 0;
      } return DefWindowProc(hWnd, message, wParam, lParam);
      }
      int APIENTRY WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
      { WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC,
      WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL,
      NULL, NULL, TEXT("ClassName"), NULL
      };
      RegisterClassEx(&wc); HWND hWnd = CreateWindow(_T("ClassName"), _T("第一个窗口"), WS_OVERLAPPEDWINDOW,
      200, 100, 640, 480,
      NULL, NULL, wc.hInstance, NULL); if (SUCCEEDED(InitializeD3D(hWnd)))
      {
      ShowWindow(hWnd, SW_SHOWDEFAULT);
      UpdateWindow(hWnd); MSG msg;
      ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT)
      {
      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
      }
      else
      {
      Render();
      }
      } } UnregisterClass(_T("ClassName"), wc.hInstance);
      return 0;
      }
      


      3楼2012-01-07 12:46
      回复
        http://www.znflsq.org/?fromuid=105942


        IP属地:贵州来自手机贴吧5楼2017-08-28 19:43
        回复