26 #define _USE_MATH_DEFINES 34 #include <glad/glad.h> 59 r1 = outer_radius - tooth_depth / 2.f;
60 r2 = outer_radius + tooth_depth / 2.f;
62 da = 2.f * (float) M_PI / teeth / 4.
f;
70 for (i = 0; i <= teeth; i++) {
71 angle = i * 2.f * (float) M_PI / teeth;
72 glVertex3f(r0 * (
float) cos(angle), r0 * (
float) sin(angle), width * 0.5
f);
73 glVertex3f(r1 * (
float) cos(angle), r1 * (
float) sin(angle), width * 0.5f);
75 glVertex3f(r0 * (
float) cos(angle), r0 * (
float) sin(angle), width * 0.5f);
76 glVertex3f(r1 * (
float) cos(angle + 3 * da), r1 * (
float) sin(angle + 3 * da), width * 0.5f);
83 da = 2.f * (float) M_PI / teeth / 4.
f;
84 for (i = 0; i < teeth; i++) {
85 angle = i * 2.f * (float) M_PI / teeth;
87 glVertex3f(r1 * (
float) cos(angle), r1 * (
float) sin(angle), width * 0.5
f);
88 glVertex3f(r2 * (
float) cos(angle + da), r2 * (
float) sin(angle + da), width * 0.5f);
89 glVertex3f(r2 * (
float) cos(angle + 2 * da), r2 * (
float) sin(angle + 2 * da), width * 0.5f);
90 glVertex3f(r1 * (
float) cos(angle + 3 * da), r1 * (
float) sin(angle + 3 * da), width * 0.5f);
98 for (i = 0; i <= teeth; i++) {
99 angle = i * 2.f * (float) M_PI / teeth;
100 glVertex3f(r1 * (
float) cos(angle), r1 * (
float) sin(angle), -width * 0.5
f);
101 glVertex3f(r0 * (
float) cos(angle), r0 * (
float) sin(angle), -width * 0.5f);
103 glVertex3f(r1 * (
float) cos(angle + 3 * da), r1 * (
float) sin(angle + 3 * da), -width * 0.5f);
104 glVertex3f(r0 * (
float) cos(angle), r0 * (
float) sin(angle), -width * 0.5f);
111 da = 2.f * (float) M_PI / teeth / 4.
f;
112 for (i = 0; i < teeth; i++) {
113 angle = i * 2.f * (float) M_PI / teeth;
115 glVertex3f(r1 * (
float) cos(angle + 3 * da), r1 * (
float) sin(angle + 3 * da), -width * 0.5
f);
116 glVertex3f(r2 * (
float) cos(angle + 2 * da), r2 * (
float) sin(angle + 2 * da), -width * 0.5f);
117 glVertex3f(r2 * (
float) cos(angle + da), r2 * (
float) sin(angle + da), -width * 0.5f);
118 glVertex3f(r1 * (
float) cos(angle), r1 * (
float) sin(angle), -width * 0.5f);
124 for (i = 0; i < teeth; i++) {
125 angle = i * 2.f * (float) M_PI / teeth;
127 glVertex3f(r1 * (
float) cos(angle), r1 * (
float) sin(angle), width * 0.5
f);
128 glVertex3f(r1 * (
float) cos(angle), r1 * (
float) sin(angle), -width * 0.5f);
129 u = r2 * (float) cos(angle + da) - r1 * (float) cos(angle);
130 v = r2 * (float) sin(angle + da) - r1 * (float) sin(angle);
131 len = (float) sqrt(u * u + v * v);
135 glVertex3f(r2 * (
float) cos(angle + da), r2 * (
float) sin(angle + da), width * 0.5f);
136 glVertex3f(r2 * (
float) cos(angle + da), r2 * (
float) sin(angle + da), -width * 0.5f);
137 glNormal3f((
float) cos(angle), (
float) sin(angle), 0.f);
138 glVertex3f(r2 * (
float) cos(angle + 2 * da), r2 * (
float) sin(angle + 2 * da), width * 0.5f);
139 glVertex3f(r2 * (
float) cos(angle + 2 * da), r2 * (
float) sin(angle + 2 * da), -width * 0.5f);
140 u = r1 * (float) cos(angle + 3 * da) - r2 * (float) cos(angle + 2 * da);
141 v = r1 * (float) sin(angle + 3 * da) - r2 * (float) sin(angle + 2 * da);
143 glVertex3f(r1 * (
float) cos(angle + 3 * da), r1 * (
float) sin(angle + 3 * da), width * 0.5f);
144 glVertex3f(r1 * (
float) cos(angle + 3 * da), r1 * (
float) sin(angle + 3 * da), -width * 0.5f);
145 glNormal3f((
float) cos(angle), (
float) sin(angle), 0.f);
148 glVertex3f(r1 * (
float) cos(0), r1 * (
float) sin(0), width * 0.5
f);
149 glVertex3f(r1 * (
float) cos(0), r1 * (
float) sin(0), -width * 0.5f);
157 for (i = 0; i <= teeth; i++) {
158 angle = i * 2.f * (float) M_PI / teeth;
159 glNormal3f(-(
float) cos(angle), -(
float) sin(angle), 0.f);
160 glVertex3f(r0 * (
float) cos(angle), r0 * (
float) sin(angle), -width * 0.5f);
161 glVertex3f(r0 * (
float) cos(angle), r0 * (
float) sin(angle), width * 0.5f);
258 glFrustum( -xmax, xmax, -xmax*h, xmax*h, znear, zfar );
268 static GLfloat pos[4] = {5.f, 5.f, 10.f, 0.f};
269 static GLfloat red[4] = {0.8f, 0.1f, 0.f, 1.f};
303 int main(
int argc,
char *argv[])
310 fprintf( stderr,
"Failed to initialize GLFW\n" );
311 exit( EXIT_FAILURE );
320 fprintf( stderr,
"Failed to open GLFW window\n" );
322 exit( EXIT_FAILURE );
334 reshape(window, width, height);
357 exit( EXIT_SUCCESS );
The header of the GLFW 3 API.
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
void *(* GLADloadproc)(const char *name)
static GLFWwindow * window
int main(int argc, char *argv[])
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow *window, GLFWframebuffersizefun cbfun)
Sets the framebuffer resize callback for the specified window.
GLfloat GLfloat GLfloat GLfloat h
#define GLFW_TRANSPARENT_FRAMEBUFFER
Window framebuffer transparency hint and attribute.
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
#define GL_AMBIENT_AND_DIFFUSE
#define GL_COLOR_BUFFER_BIT
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
#define GLFW_MOD_SHIFT
If this bit is set one or more Shift keys were held down.
GLint GLsizei GLsizei height
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
void key(GLFWwindow *window, int k, int s, int action, int mods)
void reshape(GLFWwindow *window, int width, int height)
GLAPI int gladLoadGLLoader(GLADloadproc)
#define GL_DEPTH_BUFFER_BIT
static const textual_icon exit
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
static void animate(void)
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
GLFWAPI void glfwPollEvents(void)
Processes all pending events.
static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
struct GLFWwindow GLFWwindow
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
#define GLFW_DEPTH_BITS
Framebuffer bit depth hint.
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.