opengl_learn

Step-by-step introduction to OpenGL
git clone https://0xdd.org/code/opengl_learn.git
Log | Files | Refs | README | LICENSE

ogl.h (2334B)


      1 /*
      2 2018 David DiPaola
      3 licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/)
      4 */
      5 
      6 #ifndef _OGL_H
      7 #define _OGL_H
      8 
      9 #include <GL/glew.h>
     10 
     11 #include <GLFW/glfw3.h>
     12 
     13 
     14 
     15 struct ogl_mat4f {
     16 	GLfloat values[4*4];
     17 };
     18 
     19 struct ogl_vec3f {
     20 	GLfloat x;
     21 	GLfloat y;
     22 	GLfloat z;
     23 };
     24 
     25 struct ogl_quat {
     26 	GLfloat angle;
     27 	struct ogl_vec3f axis;
     28 };
     29 
     30 
     31 
     32 GLFWwindow *
     33 ogl_init(int window_width, int window_height, int vsync, const char * window_title);
     34 
     35 
     36 
     37 GLuint
     38 ogl_program_build(const char * program_vertex_source, const char * program_fragment_source);
     39 
     40 int
     41 ogl_program_uniform_get_ID(
     42 	GLuint programID, const char * uniform_name,
     43 	GLint * out_uniform_ID
     44 );
     45 
     46 int
     47 ogl_program_uniform_set_mat4f(
     48         GLint program_ID, const char * uniform_name, const struct ogl_mat4f matrix
     49 );
     50 
     51 
     52 
     53 GLuint
     54 ogl_arraybuffer_load(const GLvoid * data, GLsizeiptr data_size);
     55 
     56 
     57 
     58 int
     59 ogl_GLfloat_isapproxequal(
     60 	GLfloat a, GLfloat b
     61 );
     62 
     63 void
     64 ogl_GLfloat_print(
     65 	GLfloat f
     66 );
     67 
     68 
     69 
     70 void
     71 ogl_mat4f_identity(
     72         struct ogl_mat4f * out_matrix
     73 );
     74 
     75 int
     76 ogl_mat4f_isapproxequal(
     77 	struct ogl_mat4f a, struct ogl_mat4f b
     78 );
     79 
     80 void
     81 ogl_mat4f_multiply(
     82         struct ogl_mat4f a, struct ogl_mat4f b,
     83 	struct ogl_mat4f * out_c
     84 );
     85 
     86 void
     87 ogl_mat4f_print(
     88 	struct ogl_mat4f matrix, const char * line_prefix, const char * line_suffix
     89 );
     90 
     91 void
     92 ogl_mat4f_rotate(
     93 	struct ogl_mat4f matrix, struct ogl_quat rotation,
     94 	struct ogl_mat4f * out_result
     95 );
     96 
     97 void
     98 ogl_mat4f_scale(
     99 	struct ogl_mat4f matrix, struct ogl_vec3f scale,
    100 	struct ogl_mat4f * out_result
    101 );
    102 
    103 void
    104 ogl_mat4f_translate(
    105 	struct ogl_mat4f matrix, struct ogl_vec3f translation,
    106 	struct ogl_mat4f * out_result
    107 );
    108 
    109 
    110 
    111 void
    112 ogl_vec3f_cross(
    113 	struct ogl_vec3f a, struct ogl_vec3f b,
    114 	struct ogl_vec3f * out_result
    115 );
    116 
    117 void
    118 ogl_vec3f_dot(
    119 	struct ogl_vec3f a, struct ogl_vec3f b,
    120 	GLfloat * out_result
    121 );
    122 
    123 int
    124 ogl_vec3f_isapproxequal(
    125 	struct ogl_vec3f a, struct ogl_vec3f b
    126 );
    127 
    128 GLfloat
    129 ogl_vec3f_magnitude(
    130 	struct ogl_vec3f vector
    131 );
    132 
    133 int
    134 ogl_vec3f_normal(
    135 	struct ogl_vec3f vector,
    136 	struct ogl_vec3f * out_result
    137 );
    138 
    139 void
    140 ogl_vec3f_print(
    141 	struct ogl_vec3f vector
    142 );
    143 
    144 
    145 
    146 void
    147 ogl_lookat(
    148 	struct ogl_vec3f eye, struct ogl_vec3f center, struct ogl_vec3f up,
    149 	struct ogl_mat4f * out_matrix
    150 );
    151 
    152 void
    153 ogl_perspective(
    154 	GLfloat fovy, GLfloat zNear, GLfloat zFar,
    155 	struct ogl_mat4f * out_matrix
    156 );
    157 
    158 #endif
    159