main.cpp
Go to the documentation of this file.
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #define _CRT_SECURE_NO_WARNINGS
24 #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 1
25 
26 #include "imgui/imgui.h"
27 #include "imgui_impl_glfw.h"
28 #include "imgui_impl_opengl3.h"
29 #include "draw.h"
30 #include "settings.h"
31 #include "test.h"
32 
33 #include <algorithm>
34 #include <stdio.h>
35 #include <thread>
36 #include <chrono>
37 
38 #if defined(_WIN32)
39 #include <crtdbg.h>
40 #endif
41 
44 static Test* s_test = nullptr;
46 static bool s_rightMouseDown = false;
48 
49 void glfwErrorCallback(int error, const char* description)
50 {
51  fprintf(stderr, "GLFW error occured. Code: %d. Description: %s\n", error, description);
52 }
53 
54 static inline bool CompareTests(const TestEntry& a, const TestEntry& b)
55 {
56  int result = strcmp(a.category, b.category);
57  if (result == 0)
58  {
59  result = strcmp(a.name, b.name);
60  }
61 
62  return result < 0;
63 }
64 
65 static void SortTests()
66 {
68 }
69 
70 static void CreateUI(GLFWwindow* window, const char* glslVersion = NULL)
71 {
74 
75  bool success;
76  success = ImGui_ImplGlfw_InitForOpenGL(window, false);
77  if (success == false)
78  {
79  printf("ImGui_ImplGlfw_InitForOpenGL failed\n");
80  assert(false);
81  }
82 
83  success = ImGui_ImplOpenGL3_Init(glslVersion);
84  if (success == false)
85  {
86  printf("ImGui_ImplOpenGL3_Init failed\n");
87  assert(false);
88  }
89 
90  // Search for font file
91  const char* fontPath1 = "data/droid_sans.ttf";
92  const char* fontPath2 = "../data/droid_sans.ttf";
93  const char* fontPath = nullptr;
94  FILE* file1 = fopen(fontPath1, "rb");
95  FILE* file2 = fopen(fontPath2, "rb");
96  if (file1)
97  {
98  fontPath = fontPath1;
99  fclose(file1);
100  }
101 
102  if (file2)
103  {
104  fontPath = fontPath2;
105  fclose(file2);
106  }
107 
108  if (fontPath)
109  {
110  ImGui::GetIO().Fonts->AddFontFromFileTTF(fontPath, 13.0f);
111  }
112 }
113 
114 static void ResizeWindowCallback(GLFWwindow*, int width, int height)
115 {
116  g_camera.m_width = width;
117  g_camera.m_height = height;
118  s_settings.m_windowWidth = width;
119  s_settings.m_windowHeight = height;
120 }
121 
122 static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
123 {
124  ImGui_ImplGlfw_KeyCallback(window, key, scancode, action, mods);
125  if (ImGui::GetIO().WantCaptureKeyboard)
126  {
127  return;
128  }
129 
130  if (action == GLFW_PRESS)
131  {
132  switch (key)
133  {
134  case GLFW_KEY_ESCAPE:
135  // Quit
137  break;
138 
139  case GLFW_KEY_LEFT:
140  // Pan left
141  if (mods == GLFW_MOD_CONTROL)
142  {
143  b2Vec2 newOrigin(2.0f, 0.0f);
144  s_test->ShiftOrigin(newOrigin);
145  }
146  else
147  {
148  g_camera.m_center.x -= 0.5f;
149  }
150  break;
151 
152  case GLFW_KEY_RIGHT:
153  // Pan right
154  if (mods == GLFW_MOD_CONTROL)
155  {
156  b2Vec2 newOrigin(-2.0f, 0.0f);
157  s_test->ShiftOrigin(newOrigin);
158  }
159  else
160  {
161  g_camera.m_center.x += 0.5f;
162  }
163  break;
164 
165  case GLFW_KEY_DOWN:
166  // Pan down
167  if (mods == GLFW_MOD_CONTROL)
168  {
169  b2Vec2 newOrigin(0.0f, 2.0f);
170  s_test->ShiftOrigin(newOrigin);
171  }
172  else
173  {
174  g_camera.m_center.y -= 0.5f;
175  }
176  break;
177 
178  case GLFW_KEY_UP:
179  // Pan up
180  if (mods == GLFW_MOD_CONTROL)
181  {
182  b2Vec2 newOrigin(0.0f, -2.0f);
183  s_test->ShiftOrigin(newOrigin);
184  }
185  else
186  {
187  g_camera.m_center.y += 0.5f;
188  }
189  break;
190 
191  case GLFW_KEY_HOME:
192  // Reset view
193  g_camera.m_zoom = 1.0f;
194  g_camera.m_center.Set(0.0f, 20.0f);
195  break;
196 
197  case GLFW_KEY_Z:
198  // Zoom out
199  g_camera.m_zoom = b2Min(1.1f * g_camera.m_zoom, 20.0f);
200  break;
201 
202  case GLFW_KEY_X:
203  // Zoom in
204  g_camera.m_zoom = b2Max(0.9f * g_camera.m_zoom, 0.02f);
205  break;
206 
207  case GLFW_KEY_R:
208  // Reset test
209  delete s_test;
210  s_test = g_testEntries[s_settings.m_testIndex].createFcn();
211  break;
212 
213  case GLFW_KEY_SPACE:
214  // Launch a bomb.
215  if (s_test)
216  {
217  s_test->LaunchBomb();
218  }
219  break;
220 
221  case GLFW_KEY_O:
222  s_settings.m_singleStep = true;
223  break;
224 
225  case GLFW_KEY_P:
226  s_settings.m_pause = !s_settings.m_pause;
227  break;
228 
230  // Switch to previous test
231  --s_testSelection;
232  if (s_testSelection < 0)
233  {
235  }
236  break;
237 
239  // Switch to next test
240  ++s_testSelection;
242  {
243  s_testSelection = 0;
244  }
245  break;
246 
247  case GLFW_KEY_TAB:
249 
250  default:
251  if (s_test)
252  {
253  s_test->Keyboard(key);
254  }
255  }
256  }
257  else if (action == GLFW_RELEASE)
258  {
259  s_test->KeyboardUp(key);
260  }
261  // else GLFW_REPEAT
262 }
263 
264 static void CharCallback(GLFWwindow* window, unsigned int c)
265 {
266  ImGui_ImplGlfw_CharCallback(window, c);
267 }
268 
269 static void MouseButtonCallback(GLFWwindow* window, int32 button, int32 action, int32 mods)
270 {
271  ImGui_ImplGlfw_MouseButtonCallback(window, button, action, mods);
272 
273  double xd, yd;
274  glfwGetCursorPos(g_mainWindow, &xd, &yd);
275  b2Vec2 ps((float)xd, (float)yd);
276 
277  // Use the mouse to move things around.
278  if (button == GLFW_MOUSE_BUTTON_1)
279  {
280  //<##>
281  //ps.Set(0, 0);
283  if (action == GLFW_PRESS)
284  {
285  if (mods == GLFW_MOD_SHIFT)
286  {
287  s_test->ShiftMouseDown(pw);
288  }
289  else
290  {
291  s_test->MouseDown(pw);
292  }
293  }
294 
295  if (action == GLFW_RELEASE)
296  {
297  s_test->MouseUp(pw);
298  }
299  }
300  else if (button == GLFW_MOUSE_BUTTON_2)
301  {
302  if (action == GLFW_PRESS)
303  {
304  s_clickPointWS = g_camera.ConvertScreenToWorld(ps);
305  s_rightMouseDown = true;
306  }
307 
308  if (action == GLFW_RELEASE)
309  {
310  s_rightMouseDown = false;
311  }
312  }
313 }
314 
315 static void MouseMotionCallback(GLFWwindow*, double xd, double yd)
316 {
317  b2Vec2 ps((float)xd, (float)yd);
318 
320  s_test->MouseMove(pw);
321 
322  if (s_rightMouseDown)
323  {
324  b2Vec2 diff = pw - s_clickPointWS;
325  g_camera.m_center.x -= diff.x;
326  g_camera.m_center.y -= diff.y;
327  s_clickPointWS = g_camera.ConvertScreenToWorld(ps);
328  }
329 }
330 
331 static void ScrollCallback(GLFWwindow* window, double dx, double dy)
332 {
333  ImGui_ImplGlfw_ScrollCallback(window, dx, dy);
334  if (ImGui::GetIO().WantCaptureMouse)
335  {
336  return;
337  }
338 
339  if (dy > 0)
340  {
341  g_camera.m_zoom /= 1.1f;
342  }
343  else
344  {
345  g_camera.m_zoom *= 1.1f;
346  }
347 }
348 
349 static void RestartTest()
350 {
351  delete s_test;
352  s_test = g_testEntries[s_settings.m_testIndex].createFcn();
353 }
354 
355 static void UpdateUI()
356 {
357  int menuWidth = 180;
358  if (g_debugDraw.m_showUI)
359  {
360  ImGui::SetNextWindowPos(ImVec2((float)g_camera.m_width - menuWidth - 10, 10));
361  ImGui::SetNextWindowSize(ImVec2((float)menuWidth, (float)g_camera.m_height - 20));
362 
364 
365  if (ImGui::BeginTabBar("ControlTabs", ImGuiTabBarFlags_None))
366  {
367  if (ImGui::BeginTabItem("Controls"))
368  {
369  ImGui::SliderInt("Vel Iters", &s_settings.m_velocityIterations, 0, 50);
370  ImGui::SliderInt("Pos Iters", &s_settings.m_positionIterations, 0, 50);
371  ImGui::SliderFloat("Hertz", &s_settings.m_hertz, 5.0f, 120.0f, "%.0f hz");
372 
374 
375  ImGui::Checkbox("Sleep", &s_settings.m_enableSleep);
376  ImGui::Checkbox("Warm Starting", &s_settings.m_enableWarmStarting);
377  ImGui::Checkbox("Time of Impact", &s_settings.m_enableContinuous);
378  ImGui::Checkbox("Sub-Stepping", &s_settings.m_enableSubStepping);
379 
381 
382  ImGui::Checkbox("Shapes", &s_settings.m_drawShapes);
383  ImGui::Checkbox("Joints", &s_settings.m_drawJoints);
384  ImGui::Checkbox("AABBs", &s_settings.m_drawAABBs);
385  ImGui::Checkbox("Contact Points", &s_settings.m_drawContactPoints);
386  ImGui::Checkbox("Contact Normals", &s_settings.m_drawContactNormals);
387  ImGui::Checkbox("Contact Impulses", &s_settings.m_drawContactImpulse);
388  ImGui::Checkbox("Friction Impulses", &s_settings.m_drawFrictionImpulse);
389  ImGui::Checkbox("Center of Masses", &s_settings.m_drawCOMs);
390  ImGui::Checkbox("Statistics", &s_settings.m_drawStats);
391  ImGui::Checkbox("Profile", &s_settings.m_drawProfile);
392 
393  ImVec2 button_sz = ImVec2(-1, 0);
394  if (ImGui::Button("Pause (P)", button_sz))
395  {
396  s_settings.m_pause = !s_settings.m_pause;
397  }
398 
399  if (ImGui::Button("Single Step (O)", button_sz))
400  {
401  s_settings.m_singleStep = !s_settings.m_singleStep;
402  }
403 
404  if (ImGui::Button("Restart (R)", button_sz))
405  {
406  RestartTest();
407  }
408 
409  if (ImGui::Button("Quit", button_sz))
410  {
412  }
413 
415  }
416 
419 
421 
422  if (ImGui::BeginTabItem("Tests"))
423  {
424  int categoryIndex = 0;
425  const char* category = g_testEntries[categoryIndex].category;
426  int i = 0;
427  while (i < g_testCount)
428  {
429  bool categorySelected = strcmp(category, g_testEntries[s_settings.m_testIndex].category) == 0;
430  ImGuiTreeNodeFlags nodeSelectionFlags = categorySelected ? ImGuiTreeNodeFlags_Selected : 0;
431  bool nodeOpen = ImGui::TreeNodeEx(category, nodeFlags | nodeSelectionFlags);
432 
433  if (nodeOpen)
434  {
435  while (i < g_testCount && strcmp(category, g_testEntries[i].category) == 0)
436  {
437  ImGuiTreeNodeFlags selectionFlags = 0;
438  if (s_settings.m_testIndex == i)
439  {
440  selectionFlags = ImGuiTreeNodeFlags_Selected;
441  }
442  ImGui::TreeNodeEx((void*)(intptr_t)i, leafNodeFlags | selectionFlags, "%s", g_testEntries[i].name);
443  if (ImGui::IsItemClicked())
444  {
445  delete s_test;
446  s_settings.m_testIndex = i;
447  s_test = g_testEntries[i].createFcn();
448  s_testSelection = i;
449  }
450  ++i;
451  }
452  ImGui::TreePop();
453  }
454  else
455  {
456  while (i < g_testCount && strcmp(category, g_testEntries[i].category) == 0)
457  {
458  ++i;
459  }
460  }
461 
462  if (i < g_testCount)
463  {
464  category = g_testEntries[i].category;
465  categoryIndex = i;
466  }
467  }
469  }
471  }
472 
473  ImGui::End();
474 
475  s_test->UpdateUI();
476  }
477 }
478 
479 //
480 int main(int, char**)
481 {
482 #if defined(_WIN32)
483  // Enable memory-leak reports
484  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
485 #endif
486 
487  char buffer[128];
488 
489  s_settings.Load();
490  SortTests();
491 
493 
494  g_camera.m_width = s_settings.m_windowWidth;
495  g_camera.m_height = s_settings.m_windowHeight;
496 
497  if (glfwInit() == 0)
498  {
499  fprintf(stderr, "Failed to initialize GLFW\n");
500  return -1;
501  }
502 
503 #if __APPLE__
504  const char* glslVersion = "#version 150";
505 #else
506  const char* glslVersion = NULL;
507 #endif
508 
513 
514  sprintf(buffer, "Box2D Testbed Version %d.%d.%d", b2_version.major, b2_version.minor, b2_version.revision);
515 
516  bool fullscreen = false;
517  if (fullscreen)
518  {
519  g_mainWindow = glfwCreateWindow(1920, 1080, buffer, glfwGetPrimaryMonitor(), NULL);
520  }
521  else
522  {
524  }
525 
526  if (g_mainWindow == NULL)
527  {
528  fprintf(stderr, "Failed to open GLFW g_mainWindow.\n");
529  glfwTerminate();
530  return -1;
531  }
532 
534 
535  // Load OpenGL functions using glad
536  int version = gladLoadGL(glfwGetProcAddress);
537  printf("GL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
538  printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
539 
547 
549 
550  CreateUI(g_mainWindow, glslVersion);
551 
552  s_settings.m_testIndex = b2Clamp(s_settings.m_testIndex, 0, g_testCount - 1);
553  s_testSelection = s_settings.m_testIndex;
554  s_test = g_testEntries[s_settings.m_testIndex].createFcn();
555 
556  // Control the frame rate. One draw per monitor refresh.
557  //glfwSwapInterval(1);
558 
559  glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
560 
561  std::chrono::duration<double> frameTime(0.0);
562  std::chrono::duration<double> sleepAdjust(0.0);
563 
565  {
566  std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
567 
569 
570  int bufferWidth, bufferHeight;
571  glfwGetFramebufferSize(g_mainWindow, &bufferWidth, &bufferHeight);
572  glViewport(0, 0, bufferWidth, bufferHeight);
573 
575 
578 
579  ImGui::NewFrame();
580 
581  if (g_debugDraw.m_showUI)
582  {
587  ImGui::End();
588 
589  const TestEntry& entry = g_testEntries[s_settings.m_testIndex];
590  sprintf(buffer, "%s : %s", entry.category, entry.name);
591  s_test->DrawTitle(buffer);
592  }
593 
594  s_test->Step(s_settings);
595 
596  UpdateUI();
597 
598  // ImGui::ShowDemoWindow();
599 
600  if (g_debugDraw.m_showUI)
601  {
602  sprintf(buffer, "%.1f ms", 1000.0 * frameTime.count());
603  g_debugDraw.DrawString(5, g_camera.m_height - 20, buffer);
604  }
605 
606  ImGui::Render();
608 
610 
611  if (s_testSelection != s_settings.m_testIndex)
612  {
613  s_settings.m_testIndex = s_testSelection;
614  delete s_test;
615  s_test = g_testEntries[s_settings.m_testIndex].createFcn();
616  g_camera.m_zoom = 1.0f;
617  g_camera.m_center.Set(0.0f, 20.0f);
618  }
619 
620  glfwPollEvents();
621 
622  // Throttle to cap at 60Hz. This adaptive using a sleep adjustment. This could be improved by
623  // using mm_pause or equivalent for the last millisecond.
624  std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
625  std::chrono::duration<double> target(1.0 / 60.0);
626  std::chrono::duration<double> timeUsed = t2 - t1;
627  std::chrono::duration<double> sleepTime = target - timeUsed + sleepAdjust;
628  if (sleepTime > std::chrono::duration<double>(0))
629  {
630  std::this_thread::sleep_for(sleepTime);
631  }
632 
633  std::chrono::steady_clock::time_point t3 = std::chrono::steady_clock::now();
634  frameTime = t3 - t1;
635 
636  // Compute the sleep adjustment using a low pass filter
637  sleepAdjust = 0.9 * sleepAdjust + 0.1 * (target - frameTime);
638  }
639 
640  delete s_test;
641  s_test = nullptr;
642 
646  glfwTerminate();
647 
648  s_settings.Save();
649 
650  return 0;
651 }
int m_windowWidth
Definition: settings.h:62
bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow *window, bool install_callbacks)
IMGUI_API void SetNextWindowSize(const ImVec2 &size, ImGuiCond cond=0)
Definition: imgui.cpp:6054
bool ImGui_ImplOpenGL3_Init(const char *glsl_version)
#define GL_COLOR_BUFFER_BIT
Definition: gl.h:254
bool m_singleStep
Definition: settings.h:82
TestCreateFcn * createFcn
Definition: test.h:149
bool m_drawFrictionImpulse
Definition: settings.h:73
virtual void UpdateUI()
Definition: test.h:89
T b2Min(T a, T b)
Definition: b2_math.h:626
void LaunchBomb()
Definition: test.cpp:238
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
Definition: window.c:544
#define GLFW_KEY_LEFT
Definition: glfw3.h:419
bool m_pause
Definition: settings.h:81
#define GLFW_MOD_CONTROL
If this bit is set one or more Control keys were held down.
Definition: glfw3.h:504
b2Vec2 ConvertScreenToWorld(const b2Vec2 &screenPoint)
Definition: draw.cpp:36
GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow *window, GLFWwindowsizefun cbfun)
Sets the size callback for the specified window.
Definition: window.c:984
B2_API const b2Vec2 b2Vec2_zero
Useful constant.
static void CharCallback(GLFWwindow *window, unsigned int c)
Definition: main.cpp:264
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
Definition: context.c:741
bool m_drawShapes
Definition: settings.h:67
f
#define glClear
Definition: gl.h:1466
void Load()
Definition: settings.cpp:84
#define GL_DEPTH_BUFFER_BIT
Definition: gl.h:296
static void RestartTest()
Definition: main.cpp:349
void glfwErrorCallback(int error, const char *description)
Definition: main.cpp:49
Definition: imgui.h:164
#define GLFW_OPENGL_FORWARD_COMPAT
OpenGL forward-compatibility hint and attribute.
Definition: glfw3.h:945
IMGUI_API bool IsItemClicked(int mouse_button=0)
Definition: imgui.cpp:4166
#define GLFW_KEY_UP
Definition: glfw3.h:421
#define GLFW_KEY_X
Definition: glfw3.h:401
float x
Definition: b2_math.h:128
float y
Definition: b2_math.h:128
#define GLFW_CONTEXT_VERSION_MAJOR
Context client API major version hint and attribute.
Definition: glfw3.h:921
static void CreateUI(GLFWwindow *window, const char *glslVersion=NULL)
Definition: main.cpp:70
virtual void MouseDown(const b2Vec2 &p)
Definition: test.cpp:144
IMGUI_API void NewFrame()
Definition: imgui.cpp:3287
#define GLFW_KEY_SPACE
Definition: glfw3.h:360
int ImGuiTreeNodeFlags
Definition: imgui.h:143
void ImGui_ImplGlfw_Shutdown()
int32 m_height
Definition: draw.h:56
B2_API b2Version b2_version
Current version.
Definition: b2_settings.cpp:30
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:333
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow *window, GLFWmousebuttonfun cbfun)
Sets the mouse button callback.
Definition: input.c:821
float m_hertz
Definition: settings.h:64
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
int m_positionIterations
Definition: settings.h:66
Definition: test.h:80
IMGUI_API bool TreeNodeEx(const char *label, ImGuiTreeNodeFlags flags=0)
#define GLFW_KEY_P
Definition: glfw3.h:393
#define GLFW_KEY_LEFT_BRACKET
Definition: glfw3.h:404
#define GLFW_KEY_HOME
Definition: glfw3.h:424
void ShiftOrigin(const b2Vec2 &newOrigin)
Definition: test.cpp:450
#define GLFW_OPENGL_PROFILE
OpenGL profile hint and attribute.
Definition: glfw3.h:957
const char * category
Definition: test.h:147
IMGUI_API void EndTabItem()
#define GLFW_KEY_Z
Definition: glfw3.h:403
#define glGetString
Definition: gl.h:1706
static bool s_rightMouseDown
Definition: main.cpp:46
#define GL_VERSION
Definition: gl.h:957
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:1137
A 2D column vector.
Definition: b2_math.h:41
bool m_enableContinuous
Definition: settings.h:78
#define GLFW_RELEASE
The key or mouse button was released.
Definition: glfw3.h:297
void DrawTitle(const char *string)
Definition: test.cpp:106
signed int int32
Definition: b2_types.h:28
static int32 s_testSelection
Definition: main.cpp:43
static void ScrollCallback(GLFWwindow *window, double dx, double dy)
Definition: main.cpp:331
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:222
#define GLAD_VERSION_MAJOR(version)
Definition: gl.h:142
void ImGui_ImplGlfw_KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
virtual void KeyboardUp(int key)
Definition: test.h:91
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:4736
#define GLAD_VERSION_MINOR(version)
Definition: gl.h:143
void ShiftMouseDown(const b2Vec2 &p)
Definition: test.cpp:202
void ImGui_ImplGlfw_NewFrame()
bool m_showUI
Definition: draw.h:92
bool m_drawContactNormals
Definition: settings.h:71
static void MouseMotionCallback(GLFWwindow *, double xd, double yd)
Definition: main.cpp:315
b2Vec2 m_center
Definition: draw.h:53
#define GLFW_MOD_SHIFT
If this bit is set one or more Shift keys were held down.
Definition: glfw3.h:499
void Destroy()
Definition: draw.cpp:623
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:2975
T b2Max(T a, T b)
Definition: b2_math.h:637
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
#define GLFW_KEY_TAB
Definition: glfw3.h:414
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:53
void Create()
Definition: draw.cpp:612
GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow *window, GLFWcharfun cbfun)
Sets the Unicode character callback.
Definition: input.c:801
bool m_drawContactImpulse
Definition: settings.h:72
void ImGui_ImplGlfw_CharCallback(GLFWwindow *window, unsigned int c)
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow *window, GLFWcursorposfun cbfun)
Sets the cursor position callback.
Definition: input.c:832
IMGUI_API ImGuiContext * CreateContext(ImFontAtlas *shared_font_atlas=NULL)
Definition: imgui.cpp:2956
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
IMGUI_API void Separator()
IMGUI_API void End()
Definition: imgui.cpp:5371
T b2Clamp(T a, T low, T high)
Definition: b2_math.h:648
IMGUI_API void EndTabBar()
GLAD_API_CALL int gladLoadGL(GLADloadfunc load)
Definition: gl.c:942
static void SortTests()
Definition: main.cpp:65
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
Definition: window.c:486
bool m_enableWarmStarting
Definition: settings.h:77
IMGUI_API void SetNextWindowPos(const ImVec2 &pos, ImGuiCond cond=0, const ImVec2 &pivot=ImVec2(0, 0))
Definition: imgui.cpp:6045
const char * name
Definition: test.h:148
float m_zoom
Definition: draw.h:54
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
Definition: window.c:151
bool m_drawCOMs
Definition: settings.h:74
virtual void Keyboard(int key)
Definition: test.h:90
IMGUI_API bool SliderInt(const char *label, int *v, int v_min, int v_max, const char *format="%d")
static void MouseButtonCallback(GLFWwindow *window, int32 button, int32 action, int32 mods)
Definition: main.cpp:269
virtual void MouseMove(const b2Vec2 &p)
Definition: test.cpp:228
#define GLFW_KEY_RIGHT_BRACKET
Definition: glfw3.h:406
GLFWAPI void glfwGetCursorPos(GLFWwindow *window, double *xpos, double *ypos)
Retrieves the position of the cursor relative to the client area of the window.
Definition: input.c:637
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData *draw_data)
#define GLFW_KEY_DOWN
Definition: glfw3.h:420
#define GLFW_MOUSE_BUTTON_1
Definition: glfw3.h:537
GLFWwindow * g_mainWindow
Definition: main.cpp:42
IMGUI_API bool SliderFloat(const char *label, float *v, float v_min, float v_max, const char *format="%.3f", float power=1.0f)
IMGUI_API void SetNextWindowBgAlpha(float alpha)
Definition: imgui.cpp:6092
IMGUI_API void TreePop()
static void ResizeWindowCallback(GLFWwindow *, int width, int height)
Definition: main.cpp:114
#define IMGUI_CHECKVERSION()
Definition: imgui.h:50
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: main.cpp:122
void Save()
Definition: settings.cpp:56
TestEntry g_testEntries[MAX_TESTS]
Definition: test.cpp:455
bool m_drawContactPoints
Definition: settings.h:70
#define GLFW_OPENGL_CORE_PROFILE
Definition: glfw3.h:998
GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow *window, GLFWscrollfun cbfun)
Sets the scroll callback.
Definition: input.c:854
int m_testIndex
Definition: settings.h:61
GLFWAPI GLFWmonitor * glfwGetPrimaryMonitor(void)
Returns the primary monitor.
Definition: monitor.c:308
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
Definition: window.c:647
#define GL_TRUE
Definition: gl.h:891
int m_velocityIterations
Definition: settings.h:65
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:267
int32 major
significant changes
Definition: b2_common.h:130
#define GLFW_MOUSE_BUTTON_2
Definition: glfw3.h:538
bool m_drawProfile
Definition: settings.h:76
IMGUI_API bool Checkbox(const char *label, bool *v)
int g_testCount
Definition: test.cpp:456
static Settings s_settings
Definition: main.cpp:45
Camera g_camera
Definition: draw.cpp:33
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:791
bool m_enableSubStepping
Definition: settings.h:79
void DrawString(int x, int y, const char *string,...)
Definition: draw.cpp:772
GLFWAPI void glfwPollEvents(void)
Processes all pending events.
Definition: window.c:1072
int main(int, char **)
Definition: main.cpp:480
static void UpdateUI()
Definition: main.cpp:355
static b2Vec2 s_clickPointWS
Definition: main.cpp:47
virtual void Step(Settings &settings)
Definition: test.cpp:278
#define glClearColor
Definition: gl.h:1476
virtual void MouseUp(const b2Vec2 &p)
Definition: test.cpp:214
int32 minor
incremental changes
Definition: b2_common.h:131
int m_windowHeight
Definition: settings.h:63
static bool CompareTests(const TestEntry &a, const TestEntry &b)
Definition: main.cpp:54
void ImGui_ImplOpenGL3_Shutdown()
bool m_drawStats
Definition: settings.h:75
bool m_drawAABBs
Definition: settings.h:69
#define GLFW_CONTEXT_VERSION_MINOR
Context client API minor version hint and attribute.
Definition: glfw3.h:927
#define GLFW_KEY_R
Definition: glfw3.h:395
#define glViewport
Definition: gl.h:2098
DebugDraw g_debugDraw
Definition: draw.cpp:32
#define GLFW_KEY_RIGHT
Definition: glfw3.h:418
IMGUI_API ImDrawData * GetDrawData()
Definition: imgui.cpp:2988
bool m_drawJoints
Definition: settings.h:68
#define GLFW_KEY_O
Definition: glfw3.h:392
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:304
static Test * s_test
Definition: main.cpp:44
int32 revision
bug fixes
Definition: b2_common.h:132
error
Error code indicating why parse failed.
Definition: sajson.h:643
ImFontAtlas * Fonts
Definition: imgui.h:1290
IMGUI_API bool BeginTabItem(const char *label, bool *p_open=NULL, ImGuiTabItemFlags flags=0)
bool m_enableSleep
Definition: settings.h:80
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
Definition: window.c:291
IMGUI_API void Render()
Definition: imgui.cpp:3780
#define GL_SHADING_LANGUAGE_VERSION
Definition: gl.h:719
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:477
IMGUI_API bool BeginTabBar(const char *str_id, ImGuiTabBarFlags flags=0)
IMGUI_API ImFont * AddFontFromFileTTF(const char *filename, float size_pixels, const ImFontConfig *font_cfg=NULL, const ImWchar *glyph_ranges=NULL)
int32 m_width
Definition: draw.h:55
void ImGui_ImplOpenGL3_NewFrame()


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21