static void draw_frame_text_buffer(struct Renderer *renderer, struct RenderBuffer *render_buffer) { bind_program(renderer->text_program); bind_texture_unit(0); set_uniform_int32("u_Texture", renderer->text_program, 0); bind_texture(renderer->debug_font.texture); draw_text_buffer(&renderer->sprite_batch, &renderer->debug_font, &render_buffer->text); bind_texture(0); bind_program(0); }
static void draw_projectiles(struct GameState *game_state, struct Renderer *renderer) { bind_program(renderer->quad_program); begin_sprite_batch(&renderer->sprite_batch); for (uint32 i = 0; i < game_state->projectile_count; ++i) { struct Projectile *projectile = &game_state->projectiles[i]; draw_quad(&renderer->sprite_batch, projectile->position, projectile->size, vec3_new(0.0f, 1.0f, 0.0f)); } end_sprite_batch(&renderer->sprite_batch); bind_program(0); }
static void draw_ships(struct GameState *game_state, struct Renderer *renderer) { bind_program(renderer->quad_program); begin_sprite_batch(&renderer->sprite_batch); for (uint32 i = 0; i < game_state->ship_count; ++i) { struct Ship *ship = &game_state->ships[i]; draw_quad(&renderer->sprite_batch, ship->position, ship->size, vec3_new(0.5f, 0.5f, 0.5f)); } end_sprite_batch(&renderer->sprite_batch); bind_program(0); }
static void draw_buildings(struct GameState *game_state, struct Renderer *renderer) { bind_program(renderer->quad_program); begin_sprite_batch(&renderer->sprite_batch); for (uint32 i = 0; i < game_state->building_count; ++i) { struct Building *building = &game_state->buildings[i]; draw_quad(&renderer->sprite_batch, building->position, building->size, vec3_new(0.3f, 0.3f, 0.3f)); } end_sprite_batch(&renderer->sprite_batch); bind_program(0); }
void render(void) { float kd[] = {0.87, 0.82, 0.74, 1.0}; float ks[] = {0.9, 0.9, 0.9, 1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, kd); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ks); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0); #ifndef NO_SHADERS bind_program(sdr); #endif glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(1.0, yscale, 1.0); glRotatef(90, 1, 0, 0); if(need_update) { glNewList(dlist, GL_COMPILE); glBegin(GL_TRIANGLES); printf("generating mesh... "); fflush(stdout); msurf_polygonize(msurf); glEnd(); glEndList(); need_update = 0; printf("done\n"); } glCallList(dlist); glPopMatrix(); assert(glGetError() == GL_NO_ERROR); }
void set_font_colour(FontRenderer* fr, float r, float g, float b, float a) { bind_program(&fr->sp); GLfloat colour[4] = {r, g, b, a}; add_vec4_uniform(&fr->sp, "color", colour); }
bool Abstract_shader::render(Gl_img_helper::Disp_mode dmode, Gl_img_helper::Flip_mode fmode, const GLuint* fbo_buffs, int size) { if (bind_program()) { render_quad(vetex_attrib_id(), dmode, fmode, fbo_buffs, size); program.release(); return true; } return false; }
void render_game(struct GameMemory *memory, struct Renderer *renderer, uint32 screen_width, uint32 screen_height) { struct GameState *game_state = (struct GameState *)memory->game_memory; struct RenderBuffer *render_buffer = (struct RenderBuffer *)memory->render_memory; float aspect_ratio = (float)screen_width / (float)screen_height; mat4 projection_matrix = mat4_orthographic(-game_state->camera.zoom/2.0f, game_state->camera.zoom/2.0f, -game_state->camera.zoom/2.0f / aspect_ratio, game_state->camera.zoom/2.0f / aspect_ratio, 0.0f, 1.0f); mat4 view_matrix = mat4_look_at(vec3_new(game_state->camera.position.x, game_state->camera.position.y, 0.0f), vec3_new(game_state->camera.position.x, game_state->camera.position.y, -1.0f), vec3_new(0, 1, 0)); mat4 view_projection_matrix = mat4_mul(projection_matrix, view_matrix); update_ubo(renderer->camera_ubo, sizeof(mat4), &view_projection_matrix); bind_program(renderer->line_program); draw_world_line_buffer(renderer, render_buffer, renderer->line_program); bind_program(0); bind_program(renderer->quad_program); draw_world_quad_buffer(&renderer->sprite_batch, render_buffer); bind_program(0); draw_buildings(game_state, renderer); draw_ships(game_state, renderer); draw_projectiles(game_state, renderer); view_projection_matrix = mat4_orthographic(0, screen_width, screen_height, 0, 0, 1); update_ubo(renderer->camera_ubo, sizeof(mat4), &view_projection_matrix); bind_program(renderer->quad_program); draw_screen_quad_buffer(&renderer->sprite_batch, render_buffer); bind_program(0); draw_frame_text_buffer(renderer, render_buffer); }
void render_text(FontRenderer* r, FontAtlas* a, const char *text, vec4 coords, float sx, float sy) { bind_program(&r->sp); const uint8_t *p; /* Use the texture containing the atlas */ bind_texture(&a->t); add_int_uniform(&r->sp, "tex", 0); glBindVertexArray(r->vao); BufferData b[6* strlen(text)]; int c = 0; float x = coords[0], y = coords[1], z = coords[2]; /* Loop through all characters */ for (p = (const uint8_t *)text; *p; p++) { /* Calculate the vertex and texture coordinates */ float x2 = x + a->c[*p].bl * sx; float y2 = -y - a->c[*p].bt * sy; float w = a->c[*p].bw * sx; float h = a->c[*p].bh * sy; /* Advance the cursor to the start of the next character */ x += a->c[*p].ax * sx; y += a->c[*p].ay * sy; /* Skip glyphs that have no pixels */ if (!w || !h) continue; float tx0, tx1, ty0, ty1, px0, px1, py0, py1; // Clockwise winding with positions named like this // x0,y1 o---o x1,y1 // | /| // | / | // |/ | // x0,y0 o---o x1,y0 px0 = x2; px1 = x2 + w; py0 = -y2 - h; py1 = -y2; tx0 = a->c[*p].tx; tx1 = a->c[*p].tx + a->c[*p].bw / a->w, ty0 = a->c[*p].ty + a->c[*p].bh / a->h; ty1 = a->c[*p].ty; vec3_assign(b[c].pos, px0, py0, z); vec2_assign(b[c++].tex, tx0, ty0); vec3_assign(b[c].pos, px1, py1, z); vec2_assign(b[c++].tex, tx1, ty1); vec3_assign(b[c].pos, px0, py1, z); vec2_assign(b[c++].tex, tx0, ty1); // Second triangle vec3_assign(b[c].pos, px1, py1, z); vec2_assign(b[c++].tex, tx1, ty1); vec3_assign(b[c].pos, px0, py0, z); vec2_assign(b[c++].tex, tx0, ty0); vec3_assign(b[c].pos, px1, py0, z); vec2_assign(b[c++].tex, tx1, ty0); } /* Draw all the character on the screen in one go */ glBindBuffer(GL_ARRAY_BUFFER, r->vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(b), b, GL_DYNAMIC_DRAW); glDrawArrays(GL_TRIANGLES, 0, c); glBindVertexArray(0); }