display/init.c
// Create and fully initialize a display context
Create and fully initialize a display context
Create and fully initialize a display context
struct Display *make_display(int width, int height, const char *title)
{
	struct Display *display = init_display(width, height, title);
	static const char *vert_file = "display/shaders/visualizer.vert";
	static const char *frag_file = "display/shaders/default.frag";
	struct Shader shader = load_shader(vert_file, frag_file);
	display->shader = shader;
	struct VertexArray array = make_vertex_array();
	display->vertex_array = array;
	size_t bars_size = sizeof(struct afloat) * (MAX_DISPLAY_BARS + 1);
	struct Buffer bars_buffer = make_buffer(GL_UNIFORM_BUFFER, 0, bars_size);
	display->bars_ubo = bars_buffer;
	size_t particles = width * height * sizeof(struct afloat);
	struct afloat *particles_buffer = (struct afloat *) malloc(particles);
	for (int i = 0; i < width * height; i++) {
		particles_buffer[i].value = 0.0f;
		particles_buffer[i].x1 = 0.0f;
		particles_buffer[i].x2 = 0.0f;
		particles_buffer[i].x3 = 0.0f;
	}
	display->particles_ubo_f1 = make_buffer(GL_SHADER_STORAGE_BUFFER, 1, particles);
	display->particles_ubo_f2 = make_buffer(GL_SHADER_STORAGE_BUFFER, 2, particles);
	glBindBuffer(GL_UNIFORM_BUFFER, display->particles_ubo_f1.buffer);
	glBufferSubData(GL_UNIFORM_BUFFER, 0, particles, particles_buffer);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);
	glBindBuffer(GL_UNIFORM_BUFFER, display->particles_ubo_f2.buffer);
	glBufferSubData(GL_UNIFORM_BUFFER, 0, particles, particles_buffer);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);
	free(particles_buffer);
	return display;
}
struct Display * make_display ( int width , int height , const char * title ) { struct Display * display = init_display ( width , height , title ) ; static const char * vert_file = " " ; static const char * frag_file = " " ; struct Shader shader = load_shader ( vert_file , frag_file ) ; display -> shader = shader ; struct VertexArray array = make_vertex_array ( ) ; display -> vertex_array = array ; size_t bars_size = sizeof ( struct afloat ) * ( MAX_DISPLAY_BARS + 1 ) ; struct Buffer bars_buffer = make_buffer ( GL_UNIFORM_BUFFER , 0 , bars_size ) ; display -> bars_ubo = bars_buffer ; size_t particles = width * height * sizeof ( struct afloat ) ; struct afloat * particles_buffer = ( struct afloat * ) malloc ( particles ) ; for ( int i = 0 ; i < width * height ; i ++ ) { particles_buffer [ i ] . value = 0.0f ; particles_buffer [ i ] . x1 = 0.0f ; particles_buffer [ i ] . x2 = 0.0f ; particles_buffer [ i ] . x3 = 0.0f ; } display -> particles_ubo_f1 = make_buffer ( GL_SHADER_STORAGE_BUFFER , 1 , particles ) ; display -> particles_ubo_f2 = make_buffer ( GL_SHADER_STORAGE_BUFFER , 2 , particles ) ; glBindBuffer ( GL_UNIFORM_BUFFER , display -> particles_ubo_f1 . buffer ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , particles , particles_buffer ) ; glBindBuffer ( GL_UNIFORM_BUFFER , 0 ) ; glBindBuffer ( GL_UNIFORM_BUFFER , display -> particles_ubo_f2 . buffer ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , particles , particles_buffer ) ; glBindBuffer ( GL_UNIFORM_BUFFER , 0 ) ; free ( particles_buffer ) ; return display ; }
Create and fully initialize a display context
Create and fully initialize a display context
// Load shaders // Create vertex array // Create uniform buffers // Create temporary buffer to initialize particles // Create uniform buffer for particles // Copy particles to buffer // Copy particles to buffer // Free temporary buffer // Return the display context