2#define GF_EXPOSE_TEXTURE
22void gf_graphic_begin_2d(
gf_draw_t* draw) {
23 glDisable(GL_LIGHTING);
24 glDisable(GL_DEPTH_TEST);
25 glMatrixMode(GL_PROJECTION);
29 glMatrixMode(GL_MODELVIEW);
35 glMatrixMode(GL_MODELVIEW);
37 glMatrixMode(GL_PROJECTION);
39 glMatrixMode(GL_MODELVIEW);
40 glEnable(GL_DEPTH_TEST);
41 glEnable(GL_LIGHTING);
44void gf_graphic_clear(
gf_draw_t* draw) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); }
48 double th = (double)texture->height / texture->internal_height;
53 if(dim == 2) gf_graphic_begin_2d(draw);
54 gf_draw_driver_begin_texture_2d(draw, texture);
56 gf_draw_driver_set_color(draw, color);
57 glBegin(GL_TRIANGLE_FAN);
59 for(i = 0; i < npair; i++) {
60 double tx = va_arg(va,
double) * tw;
61 double ty = va_arg(va,
double) * th;
62 double x = va_arg(va,
double);
63 double y = va_arg(va,
double);
68 double z = va_arg(va,
double);
75 gf_draw_driver_end_texture_2d(draw);
76 if(dim == 2) gf_graphic_end_2d(draw);
86 if(dim == 2) gf_graphic_begin_2d(draw);
88 gf_draw_driver_set_color(draw, color);
89 glBegin(GL_TRIANGLE_FAN);
91 for(i = 0; i < npair; i++) {
92 double x = va_arg(va,
double);
93 double y = va_arg(va,
double);
97 double z = va_arg(va,
double);
103 if(dim == 2) gf_graphic_end_2d(draw);
108void gf_graphic_perspective(
gf_draw_t* draw,
double fovy,
double znear,
double zfar) {
109 double aspect = (double)draw->
width / (
double)draw->
height;
110 double f = gf_math_cot(fovy / 180 *
GF_MATH_PI / 2);
114 for(i = 0; i < 16; i++) matrix[i] = 0;
115 matrix[4 * 0 + 0] = f / aspect;
116 matrix[4 * 1 + 1] = f;
117 matrix[4 * 2 + 2] = (zfar + znear) / (znear - zfar);
118 matrix[4 * 3 + 2] = ((double)2 * zfar * znear) / (znear - zfar);
119 matrix[4 * 2 + 3] = -1;
122 glLoadMatrixd(matrix);
136 gf_math_normalize(f);
141 gf_math_normalize(up);
143 gf_math_multiply(s, f, up);
144 gf_math_normalize(s);
146 gf_math_multiply(u, s, f);
148 for(i = 0; i < 16; i++) matrix[i] = 0;
149 matrix[4 * 0 + 0] = s[0];
150 matrix[4 * 1 + 0] = s[1];
151 matrix[4 * 2 + 0] = s[2];
152 matrix[4 * 0 + 1] = u[0];
153 matrix[4 * 1 + 1] = u[1];
154 matrix[4 * 2 + 1] = u[2];
155 matrix[4 * 0 + 2] = -f[0];
156 matrix[4 * 1 + 2] = -f[1];
157 matrix[4 * 2 + 2] = -f[2];
158 matrix[4 * 3 + 3] = 1;
161 glLoadMatrixd(matrix);
#define GF_GRAPHIC_3D
Dimension parameter for 3D.
#define GF_GRAPHIC_2D
Dimension parameter for 2D.
#define GF_EXPORT
Macro for platform-dependent symbol export/import.
Required headers before anything.
double gf_math_vector_t[4]
Vector.
gf_math_vector_t lookat
Where to look at.
gf_math_vector_t camera
Camera location.
int width
Width of window.
int height
Height of window.
int internal_width
Internal width of texture.
int width
Width of texture.