1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
6 #define CELL_SHEET_X 512
7 #define CELL_SHEET_Y 512
9 SHADER_DEFINE( colour_shader
,
12 "layout (location=0) in vec2 a_co;"
18 " vec4 vert_pos = uPv * uMdl * vec4( a_co.x, 0.0, a_co.y, 1.0 );"
19 " gl_Position = vert_pos;"
24 "uniform vec4 uColour;"
28 " FragColor = uColour;"
31 UNIFORMS({ "uPv", "uMdl", "uColour" })
34 SHADER_DEFINE( tilemap_shader
,
37 "layout (location=0) in vec2 a_co;" // XY
38 "layout (location=1) in vec2 a_offset;" // XY offset
39 "layout (location=2) in vec4 a_data;" // atlas-uv, amt, other
41 "uniform vec2 uOrigin;"
47 "vec2 world_coord = a_co+a_offset+uOrigin;"
48 "gl_Position = uPv * vec4( world_coord.x, 0.0, world_coord.y, 1.0 );"
49 "aCoords = vec4((a_co*0.98+0.01 + vec2(a_data.x,0.0)) * 0.0625, a_data.zw);"
53 "uniform sampler2D uTexTiles;"
54 "uniform sampler2D uTexRipples;"
55 "uniform float uTime;"
62 "vec4 glyph = texture( uTexTiles, aCoords.xy );"
63 "vec4 ripple = texture( uTexRipples, vec2( glyph.x - uTime, glyph.y ));"
64 "float wstatus = -((aCoords.z/128.0)-1.0);" // -1 := None in, 0.0 := Hold middle, 1.0 := All out
65 "float dev = step( 0.0, glyph.x+wstatus ) * step( glyph.x+wstatus, 1.0 );" //+ abs(glyph.y-0.5) );"
66 "vec3 composite = mix( vec3(0.5,0.5,0.5), vec3(0.3,0.6,1.0) + ripple.xyz * 0.1, step( 0.75, glyph.a )*dev ) * glyph.z;"
67 "FragColor = vec4( composite, 1.0 );"
70 UNIFORMS({ "uPv", "uTexTiles", "uTexRipples", "uTime", "uOrigin" })
73 SHADER_DEFINE( fish_shader
,
75 "layout (location=0) in vec2 a_co;" // XY UV
78 "uniform vec3 uPosition;"
80 "out vec2 aTexCoords;"
84 "vec2 world_coord = a_co + uPosition.xy;"
85 "gl_Position = uPv * vec4( world_coord.x, 0.0, world_coord.y, 1.0 );"
86 "aTexCoords = vec2( (a_co.x + uPosition.z) * 0.125, a_co.y );"
89 "uniform sampler2D uTexMain;"
90 "uniform vec3 uColour;"
97 "vec4 maintex = texture( uTexMain, aTexCoords );"
98 "vec3 comp = mix( vec3(0.0,0.03,0.04), uColour, maintex.r );"
99 "FragColor = vec4( comp, maintex.g * 0.7 );"
101 UNIFORMS({ "uPv", "uTexMain", "uColour", "uPosition" })
108 int main( int argc
, char *argv
[] )
110 vg_init( argc
, argv
, "FishLadder" );
113 #define CELL_FLAG_INPUT 0x1
114 #define CELL_FLAG_OUTPUT 0x2
115 #define CELL_FLAG_IO (CELL_FLAG_INPUT|CELL_FLAG_OUTPUT)
116 #define CELL_FLAG_WALL 0x4
117 #define CELL_FLAG_HOVER 0x8
118 #define CELL_FLAG_ITER 0x10
119 #define CELL_FLAG_CANAL 0x20
120 #define CELL_FLAG_SPLIT 0x40 /* Does this cell split and have an incoming vertical connection? */
121 #define CELL_FLAG_WALKABLE (CELL_FLAG_IO|CELL_FLAG_CANAL)
122 #define CELL_FLAG_VISITED 0x80
123 #define CELL_FLAG_UPLVL 0x100
124 #define CELL_FLAG_MERGE 0x200
155 struct cell
*selected
;
184 static void map_free(void)
186 for( int i
= 0; i
< arrlen( map
.io
); i
++ )
188 arrfree( map
.cells
[ map
.io
[i
] ].conditions
);
191 arrfree( map
.cells
);
199 static struct cell
*map_tile( int pos
[2] )
201 return map
.cells
+ pos
[1]*map
.x
+ pos
[0];
204 static struct cell
*map_tile_at( int pos
[2] )
206 if( pos
[0] >= 0 && pos
[0] < map
.x
&& pos
[1] >= 0 && pos
[1] < map
.y
)
207 return map
.cells
+ pos
[1]*map
.x
+ pos
[0];
211 static struct cell
*map_tile_at_cond( int pos
[2], u32 flags
)
213 struct cell
*cell
= map_tile_at( pos
);
214 if( cell
&& (cell
->flags
& flags
) )
220 static void map_tile_coords_from_index( int i
, int coords
[2] )
222 coords
[0] = i
% map
.x
;
223 coords
[1] = (i
- coords
[0])/map
.x
;
226 static void map_stack_refresh(void)
228 for( int i
= 0; i
< map
.x
*map
.y
; i
++ )
229 map
.cells
[i
].flags
&= ~CELL_FLAG_VISITED
;
232 static void map_stack_init( int coords
[2] )
235 map
.stack
.frames
[0].i
= 0;
236 map
.stack
.frames
[0].x
= coords
[0];
237 map
.stack
.frames
[0].y
= coords
[1];
240 static struct cell
*map_stack_next(void)
242 struct cell
*tile
= NULL
;
246 struct vframe
*frame
= &map
.stack
.frames
[ map
.stack
.level
];
248 int output_dirs
[][2] = { {0,1}, {-1,0}, {1,0} };
252 int *dir
= output_dirs
[ frame
->i
];
253 tile
= map_tile_at_cond( (int[2]){frame
->x
+dir
[0], frame
->y
+dir
[1]}, CELL_FLAG_WALKABLE
);
255 if( tile
&& !(tile
->flags
& CELL_FLAG_VISITED
) )
259 frame
[1].x
= frame
[0].x
+dir
[0];
260 frame
[1].y
= frame
[0].y
+dir
[1];
262 tile
->flags
|= CELL_FLAG_VISITED
;
277 if( map
.stack
.level
< 0 )
285 static void map_stack_current_coords( int coords
[2], int offset
)
287 coords
[0] = map
.stack
.frames
[ map
.stack
.level
+offset
].x
;
288 coords
[1] = map
.stack
.frames
[ map
.stack
.level
+offset
].y
;
291 static void map_update_visual(void)
295 static int compute_flow_counter
= 0;
296 compute_flow_counter
^= 0x1;
298 for( int i
= 0; i
< map
.y
*map
.x
; i
++ )
300 struct cell
*cell
= map
.cells
+ i
;
302 cell
->flowing
[compute_flow_counter
] = cell
->flowing
[compute_flow_counter
^0x1];
304 if( !map
.cells
[i
].source_count
)
305 cell
->flowing
[ compute_flow_counter
] = vg_max( cell
->flowing
[ compute_flow_counter
] - 10, 0 );
307 map
.cells
[i
].source_count
= 0;
310 for( int y
= 0; y
< map
.y
; y
++ )
312 for( int x
= 0; x
< map
.x
; x
++ )
314 struct cell
*cur
= map
.cells
+ y
*map
.x
+ x
;
315 u8
*cellbytes
= celldata
+ (y
*map
.x
+x
)*4;
317 if( cur
->flags
& CELL_FLAG_WALKABLE
)
319 struct cell
*a
, *b
, *c
, *d
;
321 a
= map_tile_at_cond( (int[2]){ x
,y
+1 }, CELL_FLAG_WALKABLE
);
322 b
= map_tile_at_cond( (int[2]){ x
+1,y
}, CELL_FLAG_WALKABLE
);
323 c
= map_tile_at_cond( (int[2]){ x
,y
-1 }, CELL_FLAG_WALKABLE
);
324 d
= map_tile_at_cond( (int[2]){ x
-1,y
}, CELL_FLAG_WALKABLE
);
326 u32 config
= (a
?0x1:0x0) | (b
?0x2:0x0) | (c
?0x4:0x0) | (d
?0x8:0x0);
327 cellbytes
[ 0 ] = config
;
329 if( cur
->flags
& CELL_FLAG_OUTPUT
)
330 cur
->flowing
[ compute_flow_counter
] = 128;
334 // TODO: Random background tiles
340 int const k_rate_flow
= 16;
343 for( int i
= 0; i
< arrlen( map
.io
); i
++ )
346 if( map
.cells
[ map
.io
[i
] ].flags
& CELL_FLAG_OUTPUT
)
348 map_tile_coords_from_index( map
.io
[i
], inputcoord
);
349 map_stack_init( inputcoord
);
350 struct cell
*cell
= map_tile_at( inputcoord
);
356 map_stack_current_coords( cr
, 0 );
358 u8
*cellbytes
= celldata
+ (cr
[1]*map
.x
+cr
[0])*4;
360 int outflow
= cell
->flowing
[ compute_flow_counter
^ 0x1 ];
361 int sourcing
= outflow
? 1: 0;
362 int outrate
= outflow
== 128? k_rate_flow
: 0;
364 struct cell
*a
, *b
, *d
;
365 a
= map_tile( (int[2]){ cr
[0], cr
[1]+1 } );
366 b
= map_tile( (int[2]){ cr
[0]+1, cr
[1] } );
367 d
= map_tile( (int[2]){ cr
[0]-1, cr
[1] } );
369 int compute_l
= 0, compute_r
= 0;
371 switch( cellbytes
[0] )
374 case 1: case 5: case 11: case 9: case 3:
375 a
->flowing
[ compute_flow_counter
] += outrate
;
376 a
->source_count
+= sourcing
;
378 case 2: case 6: compute_r
= 1; break;
379 case 8: case 12: compute_l
= 1; break;
380 case 10: case 14: compute_l
= 1; compute_r
= 1; break;
384 if( compute_r
&& (celldata
[ (cr
[1]*map
.x
+cr
[0]+1)*4 ] != 14) )
386 b
->flowing
[ compute_flow_counter
] += outrate
;
387 b
->source_count
+= sourcing
;
390 if( compute_l
&& (celldata
[ (cr
[1]*map
.x
+cr
[0]-1)*4 ] != 14) )
392 d
->flowing
[ compute_flow_counter
] += outrate
;
393 d
->source_count
+= sourcing
;
396 if( cellbytes
[0] == 10 )
399 map_stack_current_coords( crl
, -1 );
407 while( (cell
= map_stack_next()) );
411 for( int i
= 0; i
< map
.y
*map
.x
; i
++ )
413 map
.cells
[i
].flowing
[ compute_flow_counter
] = vg_min( 128, map
.cells
[i
].flowing
[ compute_flow_counter
] );
414 celldata
[ i
*4+2 ] = map
.cells
[i
].flowing
[ compute_flow_counter
];
417 glBindBuffer( GL_ARRAY_BUFFER
, map
.tiles_vbo
);
418 glBufferSubData( GL_ARRAY_BUFFER
, 16*sizeof(float) + 1024*2*sizeof(float), map
.x
*map
.y
*4, celldata
);
421 static int map_load( const char *str
)
430 if( str
[map
.x
] == ';' )
432 else if( !str
[map
.x
] )
434 vg_error( "Unexpected EOF when parsing level!\n" );
439 struct cell
*row
= arraddnptr( map
.cells
, map
.x
);
441 int reg_start
= 0, reg_end
= 0;
457 if( reg_start
< reg_end
)
459 if( *c
>= 'a' && *c
<= 'z' )
461 arrpush( map
.cells
[ map
.io
[ reg_start
] ].conditions
, *c
);
465 if( *c
== ',' || *c
== '\n' )
474 vg_error( "Unkown attrib '%c' (row: %u)\n", *c
, map
.y
);
481 vg_error( "Over-assigned values (row: %u)\n", map
.y
);
489 if( reg_start
!= reg_end
)
491 vg_error( "Not enough values assigned (row: %u, %u of %u)\n", map
.y
, reg_start
, reg_end
);
497 vg_error( "Map row underflow (row: %u, %u<%u)\n", map
.y
, cx
, map
.x
);
501 row
= arraddnptr( map
.cells
, map
.x
);
504 reg_end
= reg_start
= arrlen( map
.io
);
510 vg_error( "Map row overflow (row: %u, %u>%u)\n", map
.y
, cx
, map
.x
);
514 row
[ cx
].conditions
= NULL
;
515 row
[ cx
].flowing
[ 0 ] = 0;
516 row
[ cx
].source_count
= 0;
518 // Parse the various cell types
519 if( *c
== '+' || *c
== '-' )
521 arrpush( map
.io
, cx
+ map
.y
*map
.x
);
522 row
[ cx
++ ].flags
= *c
== '+'? CELL_FLAG_INPUT
: CELL_FLAG_OUTPUT
;
527 row
[ cx
++ ].flags
= CELL_FLAG_WALL
;
531 row
[ cx
++ ].flags
= 0x00;
538 // Origin top left corner
539 map
.origin
[0] = -((float)map
.x
) * 0.5f
;
540 map
.origin
[2] = -((float)map
.y
) * 0.5f
;
542 float *offset_array
= (float *)malloc( map
.x
*map
.y
*2*sizeof(float) );
544 for( int y
= 0; y
< map
.y
; y
++ )
546 for( int x
= 0; x
< map
.x
; x
++ )
548 float *coord
= offset_array
+ (y
*map
.x
+x
)*2;
554 glBindBuffer( GL_ARRAY_BUFFER
, map
.tiles_vbo
);
555 glBufferSubData( GL_ARRAY_BUFFER
, 16*sizeof(float), map
.x
*map
.y
*2*sizeof(float), offset_array
);
557 free( offset_array
);
558 vg_success( "Map loaded! (%u:%u)\n", map
.x
, map
.y
);
562 static int map_tile_availible( int co
[2] )
564 // Extract 5x5 grid surrounding tile
566 for( int y
= vg_max( co
[1]-2, 0 ); y
< vg_min( map
.y
, co
[1]+3 ); y
++ )
567 for( int x
= vg_max( co
[0]-2, 0 ); x
< vg_min( map
.x
, co
[0]+3 ); x
++ )
569 struct cell
*cell
= map_tile( (int[2]){ x
, y
} );
571 if( cell
&& (cell
->flags
& CELL_FLAG_WALKABLE
) )
572 blob
|= 0x1 << ((y
-(co
[1]-2))*5 + x
-(co
[0]-2));
575 // Run filter over center 3x3 grid to check for invalid configurations
576 int kernel
[] = { 0, 1, 2, 5, 6, 7, 10, 11, 12 };
577 for( int i
= 0; i
< vg_list_size(kernel
); i
++ )
579 if( blob
& (0x1 << (6+kernel
[i
])) )
581 // (reference window: 0x1CE7) Illegal moves
590 u32 invalid
[] = { 0x8E2, 0x63, 0xC6, 0xC60, 0x18C0, 0x862, 0x8C2 };
591 u32 window
= blob
>> kernel
[i
];
593 for( int j
= 0; j
< vg_list_size(invalid
); j
++ )
594 if((window
& invalid
[j
]) == invalid
[j
])
605 float ratio
= (float)vg_window_y
/ (float)vg_window_x
;
606 float const size
= 7.5f
;
607 glm_ortho( -size
, size
, -size
*ratio
, size
*ratio
, 0.01f
, 150.f
, m_projection
);
609 glm_mat4_identity( m_view
);
610 glm_translate_z( m_view
, -10.f
);
611 glm_rotate_x( m_view
, 1.5708f
, m_view
);
613 glm_mat4_mul( m_projection
, m_view
, vg_pv
);
615 // Compute map update
616 for( int y
= 0; y
< map
.y
; y
++ )
618 for( int x
= 0; x
< map
.x
; x
++ )
620 struct cell
*tile
, *upper
, *lower
, *l
, *r
;
621 tile
= map_tile_at( (int [2]){ x
, y
} );
622 tile
->flags
&= ~(CELL_FLAG_SPLIT
|CELL_FLAG_MERGE
|CELL_FLAG_UPLVL
);
624 if( tile
->flags
& CELL_FLAG_WALKABLE
)
626 r
= map_tile_at_cond( (int[2]){ x
+1, y
}, CELL_FLAG_WALKABLE
);
627 l
= map_tile_at_cond( (int[2]){ x
-1, y
}, CELL_FLAG_WALKABLE
);
631 upper
= map_tile_at_cond( (int[2]){ x
, y
-1 }, CELL_FLAG_WALKABLE
);
632 lower
= map_tile_at_cond( (int[2]){ x
, y
+1 }, CELL_FLAG_WALKABLE
);
636 tile
->flags
|= CELL_FLAG_MERGE
| CELL_FLAG_UPLVL
;
641 tile
->flags
|= CELL_FLAG_SPLIT
;
642 l
->flags
|= CELL_FLAG_UPLVL
;
643 r
->flags
|= CELL_FLAG_UPLVL
;
650 // Compute classification
654 for( int i = 0; i < arrlen( map.io ); i ++ )
656 struct *cell cell = &map.cells[ map.io ];
659 if( cell->flags & CELL_FLAG_INPUT )
661 map_tile_coords_from_index( map.io, coords );
662 map_stack_init( coords );
666 if( cell->flags & CELL_FLAG_CONNECTOR )
671 while( (cell = map_stack_next()) );
680 vec4 vp
= { 0.f
, 0.f
, vg_window_x
, vg_window_y
};
681 glm_mat4_inv( vg_pv
, pv_inverse
);
682 glm_unprojecti( (vec3
){ vg_mouse_x
, vg_window_y
-vg_mouse_y
, -1.f
}, pv_inverse
, vp
, ray_dir
);
683 glm_unprojecti( (vec3
){ vg_mouse_x
, vg_window_y
-vg_mouse_y
, 0.f
}, pv_inverse
, vp
, ray_origin
);
684 glm_vec3_sub( ray_dir
, ray_origin
, ray_dir
);
686 // Get floor tile intersection
687 float ray_t
= -ray_origin
[1] / ray_dir
[1];
690 glm_vec3_copy( ray_origin
, tile_pos
);
691 glm_vec3_muladds( ray_dir
, ray_t
, tile_pos
);
692 glm_vec3_sub( tile_pos
, map
.origin
, tile_pos
);
694 int tile_x
= floorf( tile_pos
[0] );
695 int tile_y
= floorf( tile_pos
[2] );
697 map
.selected
= map_tile_at( (int [2]){tile_x
, tile_y
} );
701 static int fish_counter
= 0;
704 if( fish_counter
> 20 )
708 // Advance characters
709 for( int i
= 0; i
< map
.num_fishes
; i
++ )
711 struct fish
*fish
= map
.fishes
+ i
;
716 struct cell
*tile
, *next
;
717 tile
= map_tile_at( fish
->co
);
719 if( tile
->flags
& CELL_FLAG_OUTPUT
)
721 vg_info( "Fish got zucced (%d)\n", i
);
727 if( tile
->flags
& CELL_FLAG_SPLIT
)
730 int new_dir
[][2] = { {0,-1},{1,0},{-1,0} };
733 for( int j
= 0; j
< 3; j
++ )
735 test_dir
= new_dir
[ tile
->state
];
736 tile
->state
= (tile
->state
+1)%3;
738 next
= map_tile_at( (int[2]){ fish
->co
[0]+test_dir
[0], fish
->co
[1]+test_dir
[1] } );
739 if( next
&& (next
->flags
& (CELL_FLAG_WALKABLE
)) )
741 fish
->dir
[0] = test_dir
[0];
742 fish
->dir
[1] = test_dir
[1];
749 next
= map_tile_at( (int[2]){ fish
->co
[0]+fish
->dir
[0], fish
->co
[1]+fish
->dir
[1] } );
750 if( !next
|| (next
&& !(next
->flags
& CELL_FLAG_WALKABLE
)) )
758 vg_info( "Fish died! (%d)\n", i
);
764 fish
->co
[0] += fish
->dir
[0];
765 fish
->co
[1] += fish
->dir
[1];
769 for( int i
= 0; i
< arrlen( map
.io
); i
++ )
771 struct cell
*input
= &map
.cells
[ map
.io
[i
] ];
773 if( input
->flags
& CELL_FLAG_INPUT
)
775 if( input
->state
< arrlen( input
->conditions
) )
777 struct fish
*fish
= &map
.fishes
[ map
.num_fishes
];
778 map_tile_coords_from_index( map
.io
[i
], fish
->co
);
780 int output_dirs
[][2] = { {0,-1}, {-1,0}, {1,0} };
783 for( int i
= 0; i
< vg_list_size( output_dirs
); i
++ )
785 int *dir
= output_dirs
[i
];
786 struct cell
*next
= map_tile_at( (int[2]){ fish
->co
[0]+dir
[0], fish
->co
[1]+dir
[1] } );
787 if( next
&& next
->flags
& CELL_FLAG_CANAL
)
789 fish
->dir
[0] = dir
[0];
790 fish
->dir
[1] = dir
[1];
805 vg_info( "There are now %u active fish\n", map
.num_fishes
);
808 if( vg_get_button_down( "go" ) )
813 vg_info( "Ending!\n" );
818 if( vg_get_button_down( "go" ) )
823 for( int i
= 0; i
< map
.x
*map
.y
; i
++ )
824 map
.cells
[ i
].state
= 0;
826 vg_info( "Starting!\n" );
831 map
.select_valid
= map_tile_availible( (int[2]){ tile_x
, tile_y
} );
833 if( map
.select_valid
)
835 if( vg_get_button_down("primary") )
837 if( map
.selected
->flags
& CELL_FLAG_CANAL
)
839 map
.selected
->flags
&= ~(CELL_FLAG_CANAL
);
843 map
.selected
->flags
|= CELL_FLAG_CANAL
;
857 glViewport( 0,0, vg_window_x
, vg_window_y
);
859 //glEnable( GL_DEPTH_TEST );
860 glClearColor( 0.94f
, 0.94f
, 0.94f
, 1.0f
);
861 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
863 glBindVertexArray( map
.tiles_vao
);
867 SHADER_USE( tilemap_shader
);
868 glUniformMatrix4fv( SHADER_UNIFORM( tilemap_shader
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
870 glUniform1i( SHADER_UNIFORM( tilemap_shader
, "uTexTiles" ), 0 );
871 glActiveTexture( GL_TEXTURE0
);
872 glBindTexture( GL_TEXTURE_2D
, map
.tile_texture
);
874 glUniform1i( SHADER_UNIFORM( tilemap_shader
, "uTexRipples" ), 1 );
875 glActiveTexture( GL_TEXTURE1
);
876 glBindTexture( GL_TEXTURE_2D
, map
.flow_texture
);
878 glUniform2f( SHADER_UNIFORM( tilemap_shader
, "uOrigin" ), map
.origin
[0], map
.origin
[2] );
879 glUniform1f( SHADER_UNIFORM( tilemap_shader
, "uTime" ), vg_time
* 0.5f
);
881 glDrawArraysInstanced( GL_TRIANGLES
, 0, 6, map
.x
*map
.y
);
883 SHADER_USE( fish_shader
);
884 glUniformMatrix4fv( SHADER_UNIFORM( fish_shader
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
885 glUniform1i( SHADER_UNIFORM( fish_shader
, "uTexMain" ), 0 );
886 glActiveTexture( GL_TEXTURE0
);
887 glBindTexture( GL_TEXTURE_2D
, fish_texture
);
888 glUniform3f( SHADER_UNIFORM( fish_shader
, "uPosition" ), 0.0f
, 0.0f
, floorf( vg_time
*20.0f
) );
889 glUniform3f( SHADER_UNIFORM( fish_shader
, "uColour" ), 1.0f
, 0.1f
, 0.1f
);
891 glEnable( GL_BLEND
);
892 glBlendFunc( GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
893 glBlendEquation( GL_FUNC_ADD
);
895 glDrawArrays( GL_TRIANGLES
, 0, 6 );
897 glDisable( GL_BLEND
);
900 void vg_register(void)
902 SHADER_INIT( colour_shader
);
903 SHADER_INIT( tilemap_shader
);
904 SHADER_INIT( fish_shader
);
909 glGenVertexArrays( 1, &tile_vao
);
910 glGenBuffers( 1, &tile_vbo
);
914 0.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
,
915 0.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
, 0.0f
,
918 0.0f
, 0.0f
, 0.0f
, 0.0f
921 glBindVertexArray( tile_vao
);
922 glBindBuffer( GL_ARRAY_BUFFER
, tile_vbo
);
931 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
, 2 * sizeof(float), (void*)0 );
932 glEnableVertexAttribArray( 0 );
936 // Create map buffers
937 glGenVertexArrays( 1, &map
.tiles_vao
);
938 glGenBuffers( 1, &map
.tiles_vbo
);
940 glBindVertexArray( map
.tiles_vao
);
941 glBindBuffer( GL_ARRAY_BUFFER
, map
.tiles_vbo
);
942 glBufferData( GL_ARRAY_BUFFER
,
943 sizeof( quad_mesh
) +
944 sizeof( float )*2 * 1024 +
945 sizeof( u8
)*4 * 1024,
950 glBufferSubData( GL_ARRAY_BUFFER
, 0, sizeof( quad_mesh
), quad_mesh
);
953 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(float), (void*)0 );
954 glEnableVertexAttribArray( 0 );
956 // Offset, data arrays (instancing)
957 glVertexAttribPointer( 1, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(float), (void*)(sizeof(quad_mesh
)) );
958 glEnableVertexAttribArray( 1 );
959 glVertexAttribDivisor( 1, 1 );
961 glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE
, GL_FALSE
, 4, (void*)(sizeof(quad_mesh
)+sizeof(float)*2*1024) );
962 glEnableVertexAttribArray( 2 );
963 glVertexAttribDivisor( 2, 1 );
965 map
.tile_texture
= vg_tex2d_rgba( "textures/rivertiles_flowm.tga" );
969 map
.flow_texture
= vg_tex2d_rgba( "textures/rivertiles_ripple.tga" );
973 fish_texture
= vg_tex2d_rgba( "textures/fishe_swim.tga" );
979 "##-#####-##;aaa,aa\n"
986 "##+#####+##;aa,aaa\n"
994 glDeleteVertexArrays( 1, &tile_vao
);
995 glDeleteVertexArrays( 1, &map
.tiles_vao
);
997 glDeleteBuffers( 1, &tile_vbo
);
998 glDeleteBuffers( 1, &map
.tiles_vbo
);
1000 glDeleteTextures( 1, &map
.tile_texture
);
1001 glDeleteTextures( 1, &map
.flow_texture
);