naev 0.10.4
opengl_render.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
27#include "naev.h"
30#include "opengl_render.h"
31
32#include "camera.h"
33#include "conf.h"
34#include "gui.h"
35#include "log.h"
36#include "ndata.h"
37#include "nstring.h"
38#include "opengl.h"
39
40#define OPENGL_RENDER_VBO_SIZE 256
42static gl_vbo *gl_renderVBO = 0;
43gl_vbo *gl_squareVBO = 0;
44static gl_vbo *gl_squareEmptyVBO = 0;
45gl_vbo *gl_circleVBO = 0;
46static gl_vbo *gl_lineVBO = 0;
47static gl_vbo *gl_triangleVBO = 0;
48static int gl_renderVBOtexOffset = 0;
49static int gl_renderVBOcolOffset = 0;
51void gl_beginSolidProgram(mat4 projection, const glColour *c)
52{
53 glUseProgram(shaders.solid.program);
54 glEnableVertexAttribArray(shaders.solid.vertex);
55 gl_uniformColor(shaders.solid.color, c);
56 gl_uniformMat4(shaders.solid.projection, &projection);
57}
58
59void gl_endSolidProgram (void)
60{
61 glDisableVertexAttribArray(shaders.solid.vertex);
62 glUseProgram(0);
63 gl_checkErr();
64}
65
66void gl_beginSmoothProgram(mat4 projection)
67{
68 glUseProgram(shaders.smooth.program);
69 glEnableVertexAttribArray(shaders.smooth.vertex);
70 glEnableVertexAttribArray(shaders.smooth.vertex_color);
71 gl_uniformMat4(shaders.smooth.projection, &projection);
72}
73
74void gl_endSmoothProgram() {
75 glDisableVertexAttribArray(shaders.smooth.vertex);
76 glDisableVertexAttribArray(shaders.smooth.vertex_color);
77 glUseProgram(0);
78 gl_checkErr();
79}
80
90void gl_renderRect( double x, double y, double w, double h, const glColour *c )
91{
92 /* Set the vertex. */
93 mat4 projection = gl_view_matrix;
94 mat4_translate( &projection, x, y, 0. );
95 mat4_scale( &projection, w, h, 1. );
96
97 gl_renderRectH( &projection, c, 1 );
98}
99
109void gl_renderRectEmpty( double x, double y, double w, double h, const glColour *c )
110{
111 mat4 projection = gl_view_matrix;
112 mat4_translate( &projection, x, y, 0. );
113 mat4_scale( &projection, w, h, 1. );
114
115 gl_renderRectH( &projection, c, 0 );
116}
117
125void gl_renderRectH( const mat4 *H, const glColour *c, int filled )
126{
127 gl_beginSolidProgram(*H, c);
128 if (filled) {
129 gl_vboActivateAttribOffset( gl_squareVBO, shaders.solid.vertex, 0, 2, GL_FLOAT, 0 );
130 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
131 }
132 else {
133 gl_vboActivateAttribOffset( gl_squareEmptyVBO, shaders.solid.vertex, 0, 2, GL_FLOAT, 0 );
134 glDrawArrays( GL_LINE_STRIP, 0, 5 );
135 }
136 gl_endSolidProgram();
137}
138
147void gl_renderCross( double x, double y, double r, const glColour *c )
148{
149 glUseProgram(shaders.crosshairs.program);
150 glUniform1f(shaders.crosshairs.paramf, 1.); /* No outline. */
151 gl_renderShader( x, y, r, r, 0., &shaders.crosshairs, c, 1 );
152}
153
164void gl_renderTriangleEmpty( double x, double y, double a, double s, double length, const glColour *c )
165{
166 mat4 projection = gl_view_matrix;
167 mat4_translate( &projection, x, y, 0. );
168 if (a != 0.)
169 mat4_rotate2d( &projection, a );
170 mat4_scale( &projection, s*length, s, 1. );
171
172 gl_beginSolidProgram(projection, c);
173 gl_vboActivateAttribOffset( gl_triangleVBO, shaders.solid.vertex, 0, 2, GL_FLOAT, 0 );
174 glDrawArrays( GL_LINE_STRIP, 0, 4 );
175 gl_endSolidProgram();
176}
177
194void gl_renderTextureRaw( GLuint texture, uint8_t flags,
195 double x, double y, double w, double h,
196 double tx, double ty, double tw, double th,
197 const glColour *c, double angle )
198{
199 // Half width and height
200 double hw, hh;
201 mat4 projection, tex_mat;
202
203 glUseProgram(shaders.texture.program);
204
205 /* Bind the texture. */
206 glBindTexture( GL_TEXTURE_2D, texture);
207
208 /* Must have colour for now. */
209 if (c == NULL)
210 c = &cWhite;
211
212 hw = w/2.;
213 hh = h/2.;
214
215 /* Set the vertex. */
216 projection = gl_view_matrix;
217 if (angle==0.) {
218 mat4_translate( &projection, x, y, 0. );
219 mat4_scale( &projection, w, h, 1. );
220 }
221 else {
222 mat4_translate( &projection, x+hw, y+hh, 0. );
223 mat4_rotate2d( &projection, angle );
224 mat4_translate( &projection, -hw, -hh, 0. );
225 mat4_scale( &projection, w, h, 1. );
226 }
227 glEnableVertexAttribArray( shaders.texture.vertex );
228 gl_vboActivateAttribOffset( gl_squareVBO, shaders.texture.vertex,
229 0, 2, GL_FLOAT, 0 );
230
231 /* Set the texture. */
232 tex_mat = (flags & OPENGL_TEX_VFLIP) ? mat4_ortho(-1, 1, 2, 0, 1, -1) : mat4_identity();
233 mat4_translate( &tex_mat, tx, ty, 0. );
234 mat4_scale( &tex_mat, tw, th, 1. );
235
236 /* Set shader uniforms. */
237 gl_uniformColor(shaders.texture.color, c);
238 gl_uniformMat4(shaders.texture.projection, &projection);
239 gl_uniformMat4(shaders.texture.tex_mat, &tex_mat);
240
241 /* Draw. */
242 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
243
244 /* Clear state. */
245 glDisableVertexAttribArray( shaders.texture.vertex );
246
247 /* anything failed? */
248 gl_checkErr();
249
250 glUseProgram(0);
251}
252
268void gl_renderTexture( const glTexture* texture,
269 double x, double y, double w, double h,
270 double tx, double ty, double tw, double th,
271 const glColour *c, double angle )
272{
273 gl_renderTextureRaw( texture->texture, texture->flags, x, y, w, h, tx, ty, tw, th, c, angle );
274}
275
295 const glTexture* tb, double inter,
296 double x, double y, double w, double h,
297 double tx, double ty, double tw, double th, const glColour *c )
298{
299 /* No interpolation. */
300 if (tb == NULL) {
301 gl_renderTexture( ta, x, y, w, h, tx, ty, tw, th, c, 0. );
302 return;
303 }
304
305 /* Corner cases. */
306 if (inter >= 1.) {
307 gl_renderTexture( ta, x, y, w, h, tx, ty, tw, th, c, 0. );
308 return;
309 }
310 else if (inter <= 0.) {
311 gl_renderTexture( tb, x, y, w, h, tx, ty, tw, th, c, 0. );
312 return;
313 }
314
315 mat4 projection, tex_mat;
316
317 glUseProgram(shaders.texture_interpolate.program);
318
319 /* Bind the textures. */
320 glActiveTexture( GL_TEXTURE1 );
321 glBindTexture( GL_TEXTURE_2D, tb->texture);
322 glActiveTexture( GL_TEXTURE0 );
323 glBindTexture( GL_TEXTURE_2D, ta->texture);
324 /* Always end with TEXTURE0 active. */
325
326 /* Must have colour for now. */
327 if (c == NULL)
328 c = &cWhite;
329
330 /* Set the vertex. */
331 projection = gl_view_matrix;
332 mat4_translate( &projection, x, y, 0. );
333 mat4_scale( &projection, w, h, 1. );
334 glEnableVertexAttribArray( shaders.texture_interpolate.vertex );
335 gl_vboActivateAttribOffset( gl_squareVBO, shaders.texture_interpolate.vertex, 0, 2, GL_FLOAT, 0 );
336
337 /* Set the texture. */
338 tex_mat = (ta->flags & OPENGL_TEX_VFLIP) ? mat4_ortho(-1, 1, 2, 0, 1, -1) : mat4_identity();
339 mat4_translate( &tex_mat, tx, ty, 0. );
340 mat4_scale( &tex_mat, tw, th, 1. );
341
342 /* Set shader uniforms. */
343 glUniform1i(shaders.texture_interpolate.sampler1, 0);
344 glUniform1i(shaders.texture_interpolate.sampler2, 1);
345 gl_uniformColor(shaders.texture_interpolate.color, c);
346 glUniform1f(shaders.texture_interpolate.inter, inter);
347 gl_uniformMat4(shaders.texture_interpolate.projection, &projection);
348 gl_uniformMat4(shaders.texture_interpolate.tex_mat, &tex_mat);
349
350 /* Draw. */
351 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
352
353 /* Clear state. */
354 glDisableVertexAttribArray( shaders.texture_interpolate.vertex );
355
356 /* anything failed? */
357 gl_checkErr();
358
359 glUseProgram(0);
360}
361
370void gl_gameToScreenCoords( double *nx, double *ny, double bx, double by )
371{
372 double cx,cy, gx,gy, z;
373
374 /* Get parameters. */
375 cam_getPos( &cx, &cy );
376 z = cam_getZoom();
377 gui_getOffset( &gx, &gy );
378
379 /* calculate position - we'll use relative coords to player */
380 *nx = (bx - cx) * z + gx + SCREEN_W/2.;
381 *ny = (by - cy) * z + gy + SCREEN_H/2.;
382}
383
390{
391 double cx,cy, gx,gy, z;
392 mat4 projection = lhs;
393
394 /* Get parameters. */
395 cam_getPos( &cx, &cy );
396 z = cam_getZoom();
397 gui_getOffset( &gx, &gy );
398
399 mat4_translate( &projection, gx + SCREEN_W/2., gy + SCREEN_H/2., 0. );
400 mat4_scale( &projection, z, z, 1. );
401 mat4_translate( &projection, -cx, cy, 0. );
402 return projection;
403}
404
413void gl_screenToGameCoords( double *nx, double *ny, int bx, int by )
414{
415 double cx,cy, gx,gy, z;
416
417 /* Get parameters. */
418 cam_getPos( &cx, &cy );
419 z = cam_getZoom();
420 gui_getOffset( &gx, &gy );
421
422 /* calculate position - we'll use relative coords to player */
423 *nx = (bx - SCREEN_W/2. - gx) / z + cx;
424 *ny = (by - SCREEN_H/2. - gy) / z + cy;
425}
426
440void gl_renderSprite( const glTexture* sprite, double bx, double by,
441 int sx, int sy, const glColour* c )
442{
443 double x,y, w,h, tx,ty, z;
444
445 /* Translate coords. */
446 z = cam_getZoom();
447 gl_gameToScreenCoords( &x, &y, bx - sprite->sw/2., by - sprite->sh/2. );
448
449 /* Scaled sprite dimensions. */
450 w = sprite->sw*z;
451 h = sprite->sh*z;
452
453 /* check if inbounds */
454 if ((x < -w) || (x > SCREEN_W+w) ||
455 (y < -h) || (y > SCREEN_H+h))
456 return;
457
458 /* texture coords */
459 tx = sprite->sw*(double)(sx)/sprite->w;
460 ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->h;
461
462 gl_renderTexture( sprite, x, y, w, h,
463 tx, ty, sprite->srw, sprite->srh, c, 0. );
464}
465
481void gl_renderSpriteScale( const glTexture* sprite, double bx, double by,
482 double scalew, double scaleh,
483 int sx, int sy, const glColour* c )
484{
485 double x,y, w,h, tx,ty, z;
486
487 /* Translate coords. */
488 z = cam_getZoom();
489 gl_gameToScreenCoords( &x, &y, bx - sprite->sw/2., by - sprite->sh/2. );
490
491 /* Scaled sprite dimensions. */
492 w = sprite->sw*z*scalew;
493 h = sprite->sh*z*scaleh;
494
495 /* check if inbounds */
496 if ((x < -w) || (x > SCREEN_W+w) ||
497 (y < -h) || (y > SCREEN_H+h))
498 return;
499
500 /* texture coords */
501 tx = sprite->sw*(double)(sx)/sprite->w;
502 ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->h;
503
504 gl_renderTexture( sprite, x, y, w, h,
505 tx, ty, sprite->srw, sprite->srh, c, 0. );
506}
507
523 double bx, double by, double angle,
524 int sx, int sy, const glColour *c )
525{
526 double x,y, w,h, tx,ty, z;
527
528 /* Translate coords. */
529 z = cam_getZoom();
530 gl_gameToScreenCoords( &x, &y, bx - sprite->sw/2., by - sprite->sh/2. );
531
532 /* Scaled sprite dimensions. */
533 w = sprite->sw*z;
534 h = sprite->sh*z;
535
536 /* check if inbounds */
537 if ((x < -w) || (x > SCREEN_W+w) ||
538 (y < -h) || (y > SCREEN_H+h))
539 return;
540
541 /* texture coords */
542 tx = sprite->sw*(double)(sx)/sprite->w;
543 ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->h;
544
545 gl_renderTexture( sprite, x, y, w, h,
546 tx, ty, sprite->srw, sprite->srh, c, angle );
547}
548
566 double bx, double by,
567 double scalew, double scaleh, double angle,
568 int sx, int sy, const glColour *c )
569{
570 double x,y, w,h, tx,ty, z;
571
572 /* Translate coords. */
573 z = cam_getZoom();
574 gl_gameToScreenCoords( &x, &y, bx - sprite->sw/2., by - sprite->sh/2. );
575
576 /* Scaled sprite dimensions. */
577 w = sprite->sw*z*scalew;
578 h = sprite->sh*z*scaleh;
579
580 /* check if inbounds */
581 if ((x < -w) || (x > SCREEN_W+w) ||
582 (y < -h) || (y > SCREEN_H+h))
583 return;
584
585 /* texture coords */
586 tx = sprite->sw*(double)(sx)/sprite->w;
587 ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->h;
588
589 gl_renderTexture( sprite, x, y, w, h,
590 tx, ty, sprite->srw, sprite->srh, c, angle );
591}
592
611 double inter, double bx, double by,
612 int sx, int sy, const glColour *c )
613{
614 gl_renderSpriteInterpolateScale( sa, sb, inter, bx, by, 1., 1., sx, sy, c );
615}
616
637 double inter, double bx, double by,
638 double scalew, double scaleh,
639 int sx, int sy, const glColour *c )
640{
641 double x,y, w,h, tx,ty, z;
642
643 /* Translate coords. */
644 gl_gameToScreenCoords( &x, &y, bx - scalew * sa->sw/2., by - scaleh * sa->sh/2. );
645
646 /* Scaled sprite dimensions. */
647 z = cam_getZoom();
648 w = sa->sw*z*scalew;
649 h = sa->sh*z*scaleh;
650
651 /* check if inbounds */
652 if ((x < -w) || (x > SCREEN_W+w) ||
653 (y < -h) || (y > SCREEN_H+h))
654 return;
655
656 /* texture coords */
657 tx = sa->sw*(double)(sx)/sa->w;
658 ty = sa->sh*(sa->sy-(double)sy-1)/sa->h;
659
660 gl_renderTextureInterpolate( sa, sb, inter, x, y, w, h,
661 tx, ty, sa->srw, sa->srh, c );
662}
663
674void gl_renderStaticSprite( const glTexture* sprite, double bx, double by,
675 int sx, int sy, const glColour* c )
676{
677 double x,y, tx,ty;
678
679 x = bx;
680 y = by;
681
682 /* texture coords */
683 tx = sprite->sw*(double)(sx)/sprite->w;
684 ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->h;
685
686 /* actual blitting */
687 gl_renderTexture( sprite, x, y, sprite->sw, sprite->sh,
688 tx, ty, sprite->srw, sprite->srh, c, 0. );
689}
690
709 double inter, double bx, double by,
710 int sx, int sy, const glColour *c )
711{
712 gl_renderStaticSpriteInterpolateScale( sa, sb, inter, bx, by, 1., 1., sx, sy, c );
713}
714
735 double inter, double bx, double by,
736 double scalew, double scaleh,
737 int sx, int sy, const glColour *c )
738{
739 double x,y, w,h, tx,ty;
740
741 x = bx;
742 y = by;
743
744 /* Scaled sprite dimensions. */
745 w = sa->sw*scalew;
746 h = sa->sh*scaleh;
747
748 /* check if inbounds */
749 if ((x < -w) || (x > SCREEN_W+w) ||
750 (y < -h) || (y > SCREEN_H+h))
751 return;
752
753 /* texture coords */
754 tx = sa->sw*(double)(sx)/sa->w;
755 ty = sa->sh*(sa->sy-(double)sy-1)/sa->h;
756
757 gl_renderTextureInterpolate( sa, sb, inter, x, y, w, h,
758 tx, ty, sa->srw, sa->srh, c );
759}
760
773void gl_renderScaleSprite( const glTexture* sprite,
774 double bx, double by,
775 int sx, int sy,
776 double bw, double bh, const glColour* c )
777{
778 double x,y, tx,ty;
779
780 x = bx;
781 y = by;
782
783 /* texture coords */
784 tx = sprite->sw*(double)(sx)/sprite->w;
785 ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->h;
786
787 /* actual blitting */
788 gl_renderTexture( sprite, x, y, bw, bh,
789 tx, ty, sprite->srw, sprite->srh, c, 0. );
790}
791
802void gl_renderScale( const glTexture* texture,
803 double bx, double by,
804 double bw, double bh, const glColour* c )
805{
806 double x,y, tx, ty;
807
808 /* here we use absolute coords */
809 x = bx;
810 y = by;
811
812 /* texture dimensions */
813 tx = ty = 0.;
814
815 /* Actual blitting. */
816 gl_renderTexture( texture, x, y, bw, bh,
817 tx, ty, texture->srw, texture->srh, c, 0. );
818}
819
831void gl_renderScaleAspect( const glTexture* texture,
832 double bx, double by, double bw, double bh,
833 const glColour *c )
834{
835 double scale;
836 double nw, nh;
837
838 scale = MIN( bw / texture->w, bh / texture->h );
839
840 nw = scale * texture->w;
841 nh = scale * texture->h;
842
843 bx += (bw-nw)/2.;
844 by += (bh-nh)/2.;
845
846 gl_renderScale( texture, bx, by, nw, nh, c );
847}
848
857void gl_renderStatic( const glTexture* texture,
858 double bx, double by, const glColour* c )
859{
860 double x,y;
861
862 /* here we use absolute coords */
863 x = bx;
864 y = by;
865
866 /* actual blitting */
867 gl_renderTexture( texture, x, y, texture->sw, texture->sh,
868 0., 0., texture->srw, texture->srh, c, 0. );
869}
870
883void gl_renderShader( double x, double y, double w, double h, double r, const SimpleShader *shd, const glColour *c, int center )
884{
885 mat4 projection = gl_view_matrix;
886 mat4_translate( &projection, x, y, 0. );
887 if (r != 0.)
888 mat4_rotate2d( &projection, r );
889 mat4_scale( &projection, w, h, 1. );
890 glUniform2f( shd->dimensions, w, h );
891 gl_renderShaderH( shd, &projection, c, center );
892}
893
902void gl_renderShaderH( const SimpleShader *shd, const mat4 *H, const glColour *c, int center )
903{
904 glEnableVertexAttribArray(shd->vertex);
905 gl_vboActivateAttribOffset( center ? gl_circleVBO : gl_squareVBO, shd->vertex, 0, 2, GL_FLOAT, 0 );
906
907 if (c != NULL)
908 gl_uniformColor(shd->color, c);
909
910 gl_uniformMat4(shd->projection, H);
911
912 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
913
914 glDisableVertexAttribArray(shd->vertex);
915 glUseProgram(0);
916 gl_checkErr();
917}
918
928void gl_renderCircle( double cx, double cy,
929 double r, const glColour *c, int filled )
930{
931 /* Set the vertex. */
932 mat4 projection = gl_view_matrix;
933 mat4_translate( &projection, cx, cy, 0. );
934 mat4_scale( &projection, r, r, 1. );
935
936 /* Draw! */
937 gl_renderCircleH( &projection, c, filled );
938}
939
947void gl_renderCircleH( const mat4 *H, const glColour *c, int filled )
948{
949 // TODO handle shearing and different x/y scaling
950 GLfloat r = H->m[0][0] / gl_view_matrix.m[0][0];
951
952 glUseProgram( shaders.circle.program );
953 glUniform2f( shaders.circle.dimensions, r, r );
954 glUniform1i( shaders.circle.parami, filled );
955 gl_renderShaderH( &shaders.circle, H, c, 1 );
956}
957
967void gl_renderLine( double x1, double y1,
968 double x2, double y2, const glColour *c )
969{
970 double a = atan2( y2-y1, x2-x1 );
971 double s = hypotf( x2-x1, y2-y1 );
972
973 glUseProgram(shaders.sdfsolid.program);
974 glUniform1f(shaders.sdfsolid.paramf, 1.); /* No outline. */
975 gl_renderShader( (x1+x2)/2., (y1+y2)/2., s/2.+0.5, 1.0, a, &shaders.sdfsolid, c, 1 );
976}
977
986void gl_clipRect( int x, int y, int w, int h )
987{
988 double rx, ry, rw, rh;
989 rx = (x + gl_screen.x) / gl_screen.mxscale;
990 ry = (y + gl_screen.y) / gl_screen.myscale;
991 rw = w / gl_screen.mxscale;
992 rh = h / gl_screen.myscale;
993 glScissor( rx, ry, rw, rh );
994 glEnable( GL_SCISSOR_TEST );
995}
996
1000void gl_unclipRect (void)
1001{
1002 glDisable( GL_SCISSOR_TEST );
1003 glScissor( 0, 0, gl_screen.rw, gl_screen.rh );
1004}
1005
1012{
1013 GLfloat vertex[10];
1014
1015 /* Initialize the VBO. */
1016 gl_renderVBO = gl_vboCreateStream( sizeof(GLfloat) *
1017 OPENGL_RENDER_VBO_SIZE*(2 + 2 + 4), NULL );
1018 gl_renderVBOtexOffset = sizeof(GLfloat) * OPENGL_RENDER_VBO_SIZE*2;
1019 gl_renderVBOcolOffset = sizeof(GLfloat) * OPENGL_RENDER_VBO_SIZE*(2+2);
1020
1021 vertex[0] = 0.;
1022 vertex[1] = 0.;
1023 vertex[2] = 1.;
1024 vertex[3] = 0.;
1025 vertex[4] = 0.;
1026 vertex[5] = 1.;
1027 vertex[6] = 1.;
1028 vertex[7] = 1.;
1029 gl_squareVBO = gl_vboCreateStatic( sizeof(GLfloat) * 8, vertex );
1030
1031 vertex[0] = -1.;
1032 vertex[1] = -1.;
1033 vertex[2] = 1.;
1034 vertex[3] = -1.;
1035 vertex[4] = -1.;
1036 vertex[5] = 1.;
1037 vertex[6] = 1.;
1038 vertex[7] = 1.;
1039 gl_circleVBO = gl_vboCreateStatic( sizeof(GLfloat) * 8, vertex );
1040
1041 vertex[0] = 0.;
1042 vertex[1] = 0.;
1043 vertex[2] = 1.;
1044 vertex[3] = 0.;
1045 vertex[4] = 1.;
1046 vertex[5] = 1.;
1047 vertex[6] = 0.;
1048 vertex[7] = 1.;
1049 vertex[8] = 0.;
1050 vertex[9] = 0.;
1051 gl_squareEmptyVBO = gl_vboCreateStatic( sizeof(GLfloat) * 8, vertex );
1052
1053 vertex[0] = 0.;
1054 vertex[1] = 0.;
1055 vertex[2] = 1.;
1056 vertex[3] = 0.;
1057 gl_lineVBO = gl_vboCreateStatic( sizeof(GLfloat) * 4, vertex );
1058
1059 vertex[0] = 0.5*cos(4.*M_PI/3.);
1060 vertex[1] = 0.5*sin(4.*M_PI/3.);
1061 vertex[2] = 0.5*cos(0.);
1062 vertex[3] = 0.5*sin(0.);
1063 vertex[4] = 0.5*cos(2.*M_PI/3.);
1064 vertex[5] = 0.5*sin(2.*M_PI/3.);
1065 vertex[6] = vertex[0];
1066 vertex[7] = vertex[1];
1067 gl_triangleVBO = gl_vboCreateStatic( sizeof(GLfloat) * 8, vertex );
1068
1069 gl_checkErr();
1070
1071 return 0;
1072}
1073
1077void gl_exitRender (void)
1078{
1079 /* Destroy the VBO. */
1081 gl_vboDestroy( gl_squareVBO );
1082 gl_vboDestroy( gl_circleVBO );
1083 gl_vboDestroy( gl_squareEmptyVBO );
1084 gl_vboDestroy( gl_lineVBO );
1085 gl_vboDestroy( gl_triangleVBO );
1086 gl_renderVBO = NULL;
1087}
void cam_getPos(double *x, double *y)
Gets the camera position.
Definition: camera.c:118
double cam_getZoom(void)
Gets the camera zoom.
Definition: camera.c:97
void gui_getOffset(double *x, double *y)
Gets the GUI offset.
Definition: gui.c:2021
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
Definition: mat4.c:99
mat4 mat4_identity(void)
Creates an identity matrix.
Definition: mat4.c:195
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
Definition: mat4.c:82
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
Definition: mat4.c:209
void mat4_rotate2d(mat4 *m, double angle)
Rotates an angle, in radians, around the z axis.
Definition: mat4.c:111
Header file with generic functions and naev-specifics.
#define MIN(x, y)
Definition: naev.h:40
glInfo gl_screen
Definition: opengl.c:51
void gl_exitRender(void)
Cleans up the OpenGL rendering routines.
void gl_renderShader(double x, double y, double w, double h, double r, const SimpleShader *shd, const glColour *c, int center)
Renders a simple shader.
void gl_renderShaderH(const SimpleShader *shd, const mat4 *H, const glColour *c, int center)
Renders a simple shader with a transformation.
static int gl_renderVBOcolOffset
Definition: opengl_render.c:49
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
Definition: opengl_render.c:90
void gl_renderLine(double x1, double y1, double x2, double y2, const glColour *c)
Draws a line.
void gl_gameToScreenCoords(double *nx, double *ny, double bx, double by)
Converts in-game coordinates to screen coordinates.
#define OPENGL_RENDER_VBO_SIZE
Definition: opengl_render.c:40
void gl_renderSpriteInterpolate(const glTexture *sa, const glTexture *sb, double inter, double bx, double by, int sx, int sy, const glColour *c)
Blits a sprite interpolating, position is relative to the player.
int gl_initRender(void)
Initializes the OpenGL rendering routines.
void gl_renderCircleH(const mat4 *H, const glColour *c, int filled)
Draws a circle.
void gl_renderTexture(const glTexture *texture, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c, double angle)
Texture blitting backend.
void gl_renderTriangleEmpty(double x, double y, double a, double s, double length, const glColour *c)
Renders a triangle at a given position.
void gl_unclipRect(void)
Clears the 2d clipping planes.
static int gl_renderVBOtexOffset
Definition: opengl_render.c:48
void gl_renderSpriteScale(const glTexture *sprite, double bx, double by, double scalew, double scaleh, int sx, int sy, const glColour *c)
Blits a sprite, position is relative to the player.
void gl_renderSpriteScaleRotate(const glTexture *sprite, double bx, double by, double scalew, double scaleh, double angle, int sx, int sy, const glColour *c)
Blits a sprite, position is relative to the player with scaling and rotation.
void gl_renderStatic(const glTexture *texture, double bx, double by, const glColour *c)
Blits a texture to a position.
void gl_renderScale(const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
Blits a texture scaling it.
void gl_renderScaleSprite(const glTexture *sprite, double bx, double by, int sx, int sy, double bw, double bh, const glColour *c)
Blits a scaled sprite, position is in absolute screen coordinates.
void gl_renderTextureInterpolate(const glTexture *ta, const glTexture *tb, double inter, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c)
Texture blitting backend for interpolated texture.
void gl_renderScaleAspect(const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
Blits a texture scaling it to fit a rectangle, but conserves aspect ratio.
void gl_renderTextureRaw(GLuint texture, uint8_t flags, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c, double angle)
Texture blitting backend.
void gl_renderSprite(const glTexture *sprite, double bx, double by, int sx, int sy, const glColour *c)
Blits a sprite, position is relative to the player.
void gl_renderStaticSpriteInterpolate(const glTexture *sa, const glTexture *sb, double inter, double bx, double by, int sx, int sy, const glColour *c)
Blits a sprite interpolating, position is relative to the player.
void gl_screenToGameCoords(double *nx, double *ny, int bx, int by)
Converts screen coordinates to in-game coordinates.
void gl_renderStaticSprite(const glTexture *sprite, double bx, double by, int sx, int sy, const glColour *c)
Blits a sprite, position is in absolute screen coordinates.
static gl_vbo * gl_renderVBO
Definition: opengl_render.c:42
void gl_renderRectEmpty(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
void gl_renderCross(double x, double y, double r, const glColour *c)
Renders a cross at a given position.
void gl_renderSpriteRotate(const glTexture *sprite, double bx, double by, double angle, int sx, int sy, const glColour *c)
Blits a sprite, position is relative to the player with rotation.
void gl_renderStaticSpriteInterpolateScale(const glTexture *sa, const glTexture *sb, double inter, double bx, double by, double scalew, double scaleh, int sx, int sy, const glColour *c)
Blits a sprite interpolating, position is relative to the player.
void gl_renderSpriteInterpolateScale(const glTexture *sa, const glTexture *sb, double inter, double bx, double by, double scalew, double scaleh, int sx, int sy, const glColour *c)
Blits a sprite interpolating, position is relative to the player.
void gl_renderRectH(const mat4 *H, const glColour *c, int filled)
Renders a rectangle.
mat4 gl_gameToScreenMatrix(mat4 lhs)
Return a transformation which converts in-game coordinates to screen coordinates.
void gl_clipRect(int x, int y, int w, int h)
Sets up 2d clipping planes around a rectangle.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
void gl_vboDestroy(gl_vbo *vbo)
Destroys a VBO.
Definition: opengl_vbo.c:248
gl_vbo * gl_vboCreateStream(GLsizei size, const void *data)
Creates a stream vbo.
Definition: opengl_vbo.c:147
void gl_vboActivateAttribOffset(gl_vbo *vbo, GLuint index, GLuint offset, GLint size, GLenum type, GLsizei stride)
Activates a VBO's offset.
Definition: opengl_vbo.c:228
gl_vbo * gl_vboCreateStatic(GLsizei size, const void *data)
Creates a stream vbo.
Definition: opengl_vbo.c:181
static const double c[]
Definition: rng.c:264
int y
Definition: opengl.h:38
int x
Definition: opengl.h:37
double myscale
Definition: opengl.h:54
int rh
Definition: opengl.h:47
double mxscale
Definition: opengl.h:53
int rw
Definition: opengl.h:46
Abstraction for rendering sprite sheets.
Definition: opengl_tex.h:34
double sw
Definition: opengl_tex.h:44
double sh
Definition: opengl_tex.h:45
double w
Definition: opengl_tex.h:38
uint8_t flags
Definition: opengl_tex.h:54
double srh
Definition: opengl_tex.h:47
GLuint texture
Definition: opengl_tex.h:50
double sy
Definition: opengl_tex.h:43
double h
Definition: opengl_tex.h:39
double srw
Definition: opengl_tex.h:46
Definition: mat4.h:10