timeout.c
Go to the documentation of this file.
1 //========================================================================
2 // Event wait timeout test
3 // Copyright (c) Camilla Löwy <elmindreda@glfw.org>
4 //
5 // This software is provided 'as-is', without any express or implied
6 // warranty. In no event will the authors be held liable for any damages
7 // arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it
11 // freely, subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented; you must not
14 // claim that you wrote the original software. If you use this software
15 // in a product, an acknowledgment in the product documentation would
16 // be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such, and must not
19 // be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source
22 // distribution.
23 //
24 //========================================================================
25 //
26 // This test is intended to verify that waiting for events with timeout works
27 //
28 //========================================================================
29 
30 #include <glad/glad.h>
31 #include <GLFW/glfw3.h>
32 
33 #include <time.h>
34 #include <math.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 
38 static void error_callback(int error, const char* description)
39 {
40  fprintf(stderr, "Error: %s\n", description);
41 }
42 
43 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
44 {
45  if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
47 }
48 
49 static float nrand(void)
50 {
51  return (float) rand() / (float) RAND_MAX;
52 }
53 
54 int main(void)
55 {
57 
58  srand((unsigned int) time(NULL));
59 
61 
62  if (!glfwInit())
63  exit(EXIT_FAILURE);
64 
65  window = glfwCreateWindow(640, 480, "Event Wait Timeout Test", NULL, NULL);
66  if (!window)
67  {
68  glfwTerminate();
69  exit(EXIT_FAILURE);
70  }
71 
72  glfwMakeContextCurrent(window);
75 
76  while (!glfwWindowShouldClose(window))
77  {
78  int width, height;
79  float r = nrand(), g = nrand(), b = nrand();
80  float l = (float) sqrt(r * r + g * g + b * b);
81 
82  glfwGetFramebufferSize(window, &width, &height);
83 
84  glViewport(0, 0, width, height);
85  glClearColor(r / l, g / l, b / l, 1.f);
87  glfwSwapBuffers(window);
88 
90  }
91 
92  glfwDestroyWindow(window);
93 
94  glfwTerminate();
95  exit(EXIT_SUCCESS);
96 }
97 
GLboolean GLboolean GLboolean b
GLboolean GLboolean g
The header of the GLFW 3 API.
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
Definition: context.c:741
void *(* GLADloadproc)(const char *name)
static GLFWwindow * window
Definition: joysticks.c:55
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:309
GLuint64 key
Definition: glext.h:8966
static void error_callback(int error, const char *description)
Definition: timeout.c:38
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:198
GLdouble f
#define GL_COLOR_BUFFER_BIT
GLdouble GLdouble r
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
#define glClear
GLint GLsizei GLsizei height
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
int main(void)
Definition: timeout.c:54
action
Definition: enums.py:62
#define glViewport
GLAPI int gladLoadGLLoader(GLADloadproc)
Definition: glad/glad.c:1697
static const textual_icon exit
Definition: model-views.h:254
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
Definition: window.c:486
#define RAND_MAX
Definition: boing.c:110
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
GLFWAPI void glfwWaitEventsTimeout(double timeout)
Waits with timeout until events are queued and processes them.
Definition: window.c:1088
#define GLFW_TRUE
One.
Definition: glfw3.h:279
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
Definition: window.c:444
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
Definition: window.c:647
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:243
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: timeout.c:43
#define glClearColor
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:791
#define NULL
Definition: tinycthread.c:47
static float nrand(void)
Definition: timeout.c:49
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:304
struct GLFWwindow GLFWwindow
GLint GLsizei width
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:477


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11