void deferred_renderer_render_light(light* l) { matrix_4x4 viewm = camera_view_matrix(CAMERA); matrix_4x4 projm = camera_proj_matrix(CAMERA, graphics_viewport_ratio() ); vector4 light_pos = v4(l->position.x, l->position.y, l->position.z, 1); light_pos = m44_mul_v4(viewm, light_pos); light_pos = m44_mul_v4(projm, light_pos); light_pos = v4_div(light_pos, light_pos.w); glUseProgram(shader_program_handle(PROGRAM_UI)); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, graphics_viewport_width(), graphics_viewport_height(), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); float top = ((-light_pos.y + 1) / 2) * graphics_viewport_height() - 8; float bot = ((-light_pos.y + 1) / 2) * graphics_viewport_height() + 8; float left = ((light_pos.x + 1) / 2) * graphics_viewport_width() - 8; float right = ((light_pos.x + 1) / 2) * graphics_viewport_width() + 8; texture* lightbulb = asset_load_get("$CORANGE/ui/lightbulb.dds"); glActiveTexture(GL_TEXTURE0 + 0 ); glBindTexture(GL_TEXTURE_2D, texture_handle(lightbulb)); glEnable(GL_TEXTURE_2D); glUniform1i(glGetUniformLocation(shader_program_handle(PROGRAM_UI), "diffuse"), 0); glUniform1f(glGetUniformLocation(shader_program_handle(PROGRAM_UI), "alpha_test"), 0.5); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(left, top, -light_pos.z); glTexCoord2f(0.0f, 1.0f); glVertex3f(left, bot, -light_pos.z); glTexCoord2f(1.0f, 1.0f); glVertex3f(right, bot, -light_pos.z); glTexCoord2f(1.0f, 0.0f); glVertex3f(right, top, -light_pos.z); glEnd(); glActiveTexture(GL_TEXTURE0 + 0 ); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glUseProgram(0); }
void particles_render() { #ifdef OPEN_GL_CPU #ifndef CPU_ONLY kernel_memory_read(k_particle_positions, sizeof(vector4) * particle_count, particle_positions); #endif glBindBuffer(GL_ARRAY_BUFFER, positions_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vector4) * particle_count, particle_positions, GL_DYNAMIC_COPY); #ifndef CPU_ONLY kernel_memory_read(k_particle_randoms, sizeof(vector4) * particle_count, particle_randoms); #endif glBindBuffer(GL_ARRAY_BUFFER, randoms_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vector4) * particle_count, particle_randoms, GL_DYNAMIC_COPY); #endif camera* cam = entity_get("camera"); matrix_4x4 viewm = camera_view_matrix(cam); matrix_4x4 projm = camera_proj_matrix(cam, graphics_viewport_ratio() ); m44_to_array(viewm, view_matrix); m44_to_array(projm, proj_matrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(view_matrix); glMatrixMode(GL_PROJECTION); glLoadMatrixf(proj_matrix); glBindBuffer(GL_ARRAY_BUFFER, positions_buffer); glVertexPointer(4, GL_FLOAT, 0, (void*)0); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, randoms_buffer); glColorPointer(4, GL_FLOAT, 0, (void*)0); glEnableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_POINTS, 0, particle_count); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); }
static void deferred_renderer_setup_camera() { matrix_4x4 viewm = camera_view_matrix(CAMERA); matrix_4x4 projm = camera_proj_matrix(CAMERA, graphics_viewport_ratio() ); m44_to_array(viewm, VIEW_MATRIX); m44_to_array(projm, PROJ_MATRIX); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(VIEW_MATRIX); glMatrixMode(GL_PROJECTION); glLoadMatrixf(PROJ_MATRIX); matrix_4x4 lviewm = light_view_matrix(SHADOW_LIGHT); matrix_4x4 lprojm = light_proj_matrix(SHADOW_LIGHT); m44_to_array(lviewm, LIGHT_VIEW_MATRIX); m44_to_array(lprojm, LIGHT_PROJ_MATRIX); }
mat4 camera_proj_matrix(camera* c) { return mat4_perspective(c->fov, c->near_clip, c->far_clip, graphics_viewport_ratio()); }