13 #include <glad/glad.h> 18 #define _USE_MATH_DEFINES 53 #define TORUS_MAJOR 1.5 54 #define TORUS_MINOR 0.5 55 #define TORUS_MAJOR_RES 32 56 #define TORUS_MINOR_RES 32 60 static GLuint torus_list = 0;
77 for (k = 1; k >= 0; k--)
79 s = (i + k) % TORUS_MINOR_RES + 0.5;
91 scale = 1.0 / sqrt(nx*nx + ny*ny + nz*nz);
96 glNormal3f((
float) nx, (
float) ny, (
float) nz);
121 const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
122 const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
123 const GLfloat model_shininess = 20.0f;
165 vec3 eye = { 0.f, 0.f, 1.f };
166 vec3 center = { 0.f, 0.f, 0.f };
167 vec3 up = { 0.f, 1.f, 0.f };
181 x = scale * 0.5f * (float) (steps - 1);
182 y = -scale * 0.5f * (float) (steps - 1);
183 for (i = 0; i < steps; i++)
191 x = -scale * 0.5f * (float) (steps - 1);
192 y = scale * 0.5f * (float) (steps - 1);
193 for (i = 0; i < steps; i++)
215 const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
216 const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
217 const GLfloat light_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
218 const GLfloat light_ambient[4] = {0.2f, 0.2f, 0.3f, 1.0f};
252 glOrtho(-3.0 * aspect, 3.0 * aspect, -3.0, 3.0, 1.0, 50.0);
259 vec3 eye = { 0.f, 10.f, 1
e-3
f };
260 vec3 center = { 0.f, 0.f, 0.f };
261 vec3 up = { 0.f, 1.f, 0.f };
273 vec3 eye = { 0.f, 0.f, 10.f };
274 vec3 center = { 0.f, 0.f, 0.f };
275 vec3 up = { 0.f, 1.f, 0.f };
287 vec3 eye = { 10.f, 0.f, 0.f };
288 vec3 center = { 0.f, 0.f, 0.f };
289 vec3 up = { 0.f, 1.f, 0.f };
313 65.
f * (
float) M_PI / 180.
f,
323 vec3 eye = { 3.f, 1.5f, 3.f };
324 vec3 center = { 0.f, 0.f, 0.f };
325 vec3 up = { 0.f, 1.f, 0.f };
360 glOrtho(0.0, 2.0, 0.0, 2.0, 0.0, 1.0);
409 int wnd_width, wnd_height, fb_width, fb_height;
415 scale = (double) fb_width / (
double) wnd_width;
491 fprintf(stderr,
"Failed to initialize GLFW\n");
501 fprintf(stderr,
"Failed to open GLFW window\n");
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
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)
GLenum GLenum GLenum GLenum GLenum scale
static GLFWwindow * window
GLAPI int GLAD_GL_VERSION_1_3
static void drawGrid(float scale, int steps)
GLAPI int GLAD_GL_ARB_multisample
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
GLdouble GLdouble GLdouble w
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow *window, GLFWframebuffersizefun cbfun)
Sets the framebuffer resize callback for the specified window.
GLfloat GLfloat GLfloat GLfloat h
static void mat4x4_perspective(mat4x4 m, float y_fov, float aspect, float n, float f)
static void drawTorus(void)
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
static void mouseButtonFun(GLFWwindow *window, int button, int action, int mods)
#define GL_COLOR_BUFFER_BIT
GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow *window, GLFWwindowrefreshfun cbfun)
Sets the refresh callback for the specified window.
#define GL_FRONT_AND_BACK
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
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.
static void mat4x4_look_at(mat4x4 m, vec3 eye, vec3 center, vec3 up)
static void drawAllViews(void)
#define GL_MULTISAMPLE_ARB
GLAPI int gladLoadGLLoader(GLADloadproc)
#define GL_DEPTH_BUFFER_BIT
static const textual_icon exit
#define GL_ONE_MINUS_SRC_ALPHA
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
GLFWAPI void glfwWaitEvents(void)
Waits until events are queued and processes them.
static void cursorPosFun(GLFWwindow *window, double x, double y)
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
#define GL_COMPILE_AND_EXECUTE
static void windowRefreshFun(GLFWwindow *window)
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.
#define GLFW_SAMPLES
Framebuffer MSAA samples hint.
static void framebufferSizeFun(GLFWwindow *window, int w, int h)
static void drawScene(void)
struct GLFWwindow GLFWwindow
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.