File: TestSDKExternalWindowWGL.cxx

package info (click to toggle)
f3d 3.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,668 kB
  • sloc: cpp: 99,109; python: 811; sh: 342; xml: 238; java: 101; javascript: 95; makefile: 25
file content (88 lines) | stat: -rw-r--r-- 2,155 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "engine.h"

#include "TestSDKHelpers.h"

#include <windows.h>

#include <GL/gl.h>

std::unique_ptr<f3d::engine> engine;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_PAINT:
      engine->getWindow().render();
      ValidateRect(hwnd, nullptr);
      return 0;
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
  }
  return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int TestSDKExternalWindowWGL(int argc, char* argv[])
{
  HINSTANCE hInstance = GetModuleHandle(NULL);

  // Define window class
  const char* className = "F3DWin32Class";

  WNDCLASS wc = {};
  wc.lpfnWndProc = WindowProc;
  wc.hInstance = hInstance;
  wc.lpszClassName = className;

  // Register window class
  RegisterClass(&wc);

  // Create window
  constexpr int size[] = { 300, 300 };
  HWND hwnd = CreateWindowEx(0, className, "F3D Win32 Example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
    CW_USEDEFAULT, size[0], size[1], nullptr, nullptr, hInstance, nullptr);

  if (hwnd == nullptr)
  {
    return 0;
  }

  ShowWindow(hwnd, SW_HIDE);

  // Initialize OpenGL
  HDC hDC = GetDC(hwnd);

  PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1 };
  pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  pfd.iPixelType = PFD_TYPE_RGBA;
  pfd.cColorBits = 32;
  pfd.cDepthBits = 24;
  pfd.iLayerType = PFD_MAIN_PLANE;

  int pixelFormat = ChoosePixelFormat(hDC, &pfd);
  SetPixelFormat(hDC, pixelFormat, &pfd);

  // Create and enable the OpenGL rendering context (RC)
  HGLRC hGLRC = wglCreateContext(hDC);
  wglMakeCurrent(hDC, hGLRC);

  engine = std::make_unique<f3d::engine>(f3d::engine::createExternalWGL());
  engine->getWindow().setSize(size[0], size[1]);
  engine->getScene().add(std::string(argv[1]) + "/data/cow.vtp");

  if (!TestSDKHelpers::RenderTest(engine->getWindow(), std::string(argv[1]) + "baselines/", argv[2],
        "TestSDKExternalWindowWGL"))
  {
    return EXIT_FAILURE;
  }

  // Disable the RC and delete it
  wglMakeCurrent(nullptr, nullptr);
  wglDeleteContext(hGLRC);

  // Release the DC
  ReleaseDC(hwnd, hDC);

  return 0;
}