예제 #1
0
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    mat4_identity(view);
    view = mat4_lookAt(eye, center, up, view);

    render_geometry(&g, model, view, projection);

    if (debug)
    {
        render_debug(&g, model, view, projection);
    }

    glutSwapBuffers();
}
예제 #2
0
void GUI::OnRender() {
    if(current_screen == MENU_SCREEN) {
        render_menu(menu);
    } else if(current_screen == MAP_SCREEN) {
        std::vector<std::vector<MapTile> > map_canvas = world_map_gui.get_canvas();
        for(size_t i = 0; i < map_canvas.size(); i++) {
            for(size_t j = 0; j < map_canvas[i].size(); j++) {
                drawChr(j, i, map_canvas[i][j].char_count, ascii, screen, map_canvas[i][j].color);
            }
        }
        drawStr(0, GAME_HEIGHT - 2, std::string("Use the arrow keys to move the cursor.").c_str(),
                ascii, screen, WHITE);
        drawStr(0, GAME_HEIGHT - 1, std::string("Press ENTER to spawn on the selected map tile.").c_str(),
                ascii, screen, WHITE);
    } else if (current_screen == GAME_SCREEN) {
        render_canvas();
        render_target();
        render_characters();
        render_main_char();
        render_animations();
        clear_area(IntPoint(0, UI_START), IntPoint(UI_HEIGHT, UI_WIDTH));
        render_interface();
        render_message();

    } else if(current_screen == DIRECTION_SCREEN)
    {
        drawStr(0, 0, std::string("Pick a direction to perform the action.").c_str(), ascii, screen, WHITE);
    } else if (current_screen == DEATH_SCREEN) {
        clear_screen();
        drawStr(GAME_WIDTH/2 - 12, GAME_HEIGHT/2, std::string("You suck, uninstall bro.").c_str(), ascii, screen, WHITE);
    } else if (current_screen == DEBUG_CONSOLE) {
        render_canvas();
        render_target();
        render_characters();
        render_main_char();
        render_debug();
    }
    if(game.is_paused()) {
        drawStr(GAME_WIDTH-20, 0, std::string("Paused").c_str(), ascii, screen, WHITE);
    }

    SDL_Flip(screen);
}
예제 #3
0
    void asdf_multiplat_t::render() {
        renderer->pre_render();

        {
            spritebatch->begin();
            ASSERT(!CheckGLError(), "gl error after begin");
            main_view->render(glm::vec3(0, 0, 0), glm::mat3(), color_t(1.0f));
            ASSERT(!CheckGLError(), "GL error after main_view->render() ");
            spritebatch->end();
        }

        glUseProgram(0);

        if (render_debug_views)
            render_debug();

        ASSERT(specific, "app.specific not assigned");
        specific->render();

        renderer->post_render();
    }
예제 #4
0
void
run_game(lua_State *L)
{
        uint32_t now = SDL_GetTicks();   /* Current real time. */
        
        /*
         * Compute how much time has passed since last time. Watch out for time
         * wrap-around.
         */
        uint32_t delta_time = (now >= before) ? now - before :
        (uint32_t)-1 - before + now;
        before = now;
        
        /*
         * If there was some huge lag, don't make worlds catch
         * up. Instead, assume last frame took 50ms.
         */
        if (delta_time > 50)
                delta_time = 50;
        
        /* Game speed always normal. */
        uint32_t game_delta_time = delta_time;
        game_time += game_delta_time;	/* Advance game time. */
        
        /* Calculate frames per second. */
        fps_count++;
        if (now - fps_time >= config.FPSUpdateInterval && config.debug) {
                frames_per_second = fps_count*1000.0 / (now - fps_time);
                fps_time = now;
                fps_count = 0;
		extern int total_tile_count;
                log_msg("FPS: %.2f, tiles=%d", 
			frames_per_second,
			total_tile_count);
        }
        
        process_events(L);
        
#if ENABLE_AUDIO
        /* Dynamically adjust volume. */
        audio_adjust_volume();
#endif
        
        /* Step worlds. */
        extern mem_pool mp_world;
        for (World *world = mp_first(&mp_world); world != NULL;
             world = mp_next(world)) {
                if (world->killme)
                        continue;       /* We deal with these below. */
                
                /* Bring world up to present game time. */
                while (game_time >= world->next_step_time) {
                        world->next_step_time += world->step_ms;
                        
                        /*
                         * Step world -- execute body step functions, timers,
                         * collision handlers.
                         */
                        world_step(world, L);
                        
                        /*
                         * Handle user input. To be more responsive, we do this
                         * here between steps too.
                         */
                        process_events(L);
                        
                        if (world->killme)
                                break;	/* No need to keep going. */
                }
        }
        
        /*
         * Deal with worlds that have either been destroyed or created in the
         * loop above. Must do this here so scripts get a chance to set
         * everything up before a frame is rendered.
         */
        for (World *world = mp_first(&mp_world); world != NULL;) {
                if (world->killme) {
                        /*
                         * Remove dying worlds. Take care to get next world
                         * pointer before destruction.
                         */
                        World *tmp = world;
                        world = mp_next(world);
                        world_free(tmp);
                        continue;
                }
                
                /* Perform the initial step on recently created worlds. */
                if (world->static_body.step == 0) {
                        /*
                         * We must give scripts control over what the contents
                         * of the world look like before drawing it. Otherwise
                         * we get such artifacts as camera centered on origin
                         * even though it should be tracking a player character.
                         */
                        world_step(world, L);
                }
                world = mp_next(world);
        }
        
        /*
         * Draw what each camera sees.
         */
        render_clear();
        for (Camera *cam = cam_list; cam != NULL; cam = cam->next) {
                if (!cam->disabled)
                        render(cam);
        }
        
#ifndef NDEBUG
        /* Debug stuff is drawn over normal stuff. */
        if (debug_cam != NULL && debug_cam->objtype == OBJTYPE_CAMERA)
                render_debug(debug_cam);
#endif
}