void draw_particles()
  {
    glPushMatrix();
    glMultMatrixf(get_modelview().matrix);
    
    OpenGLState state;
    
    state.bind_texture(surface->get_texture());
    state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    state.enable(GL_BLEND);
    state.activate();    

    glBegin(GL_QUADS);
    for(ParticleSystem::Particles::iterator i = psys.begin(); i != psys.end(); ++i)
    {
      if (i->t != -1.0f)
      {
        float p = 1.0f - psys.get_progress(i->t);
        Color color(psys.get_color_start().r * p + psys.get_color_stop().r * (1.0f - p),
                    psys.get_color_start().g * p + psys.get_color_stop().g * (1.0f - p),
                    psys.get_color_start().b * p + psys.get_color_stop().b * (1.0f - p),
                    psys.get_color_start().a * p + psys.get_color_stop().a * (1.0f - p));

        // scale
        float scale  = psys.get_size_start() + 
          psys.get_progress(i->t) * (psys.get_size_stop() - psys.get_size_start());
          
        float width  = surface->get_width()  * scale;
        float height = surface->get_height() * scale;
              
        // rotate
        float x_rot = width/2;
        float y_rot = height/2; 

        if (i->angle != 0)
        {
          float s = sinf(math::pi * i->angle/180.0f);
          float c = cosf(math::pi * i->angle/180.0f);
          x_rot = (width/2) * c - (height/2) * s;
          y_rot = (width/2) * s + (height/2) * c;
        }

        glColor4f(color.r, color.g, color.b, color.a);
        glTexCoord2f(0, 0);
        glVertex2f(i->x - x_rot, i->y - y_rot);
        glTexCoord2f(1, 0);
        glVertex2f(i->x + y_rot, i->y - x_rot);
        glTexCoord2f(1, 1);
        glVertex2f(i->x + x_rot, i->y + y_rot);
        glTexCoord2f(0, 1);
        glVertex2f(i->x - y_rot, i->y + x_rot);
      }
    }
    glEnd();

    glPopMatrix();
  }
Пример #2
0
        void large_rocky_body::draw(const simulation_context *sim_context, const drawing_context *draw_context)
        {
            lithosphere *litho = get_lithosphere();

            if (litho)
            {
                vector pos_in_view = get_modelview() * vector::ZERO;

                gsgl::real_t radius = gsgl::max_val(get_polar_radius(), get_equatorial_radius());
                gsgl::real_t dist = pos_in_view.mag();
                gsgl::real_t zdist = -pos_in_view.get_z();
                assert(zdist > 0);

                gsgl::real_t far_plane = zdist + (radius * 1.1f);
                gsgl::real_t near_plane = zdist - (radius * 1.1f);
                if (near_plane <= 0)
                    near_plane = 1;

                display::scoped_perspective proj(*draw_context->screen, draw_context->cam->get_field_of_view(), draw_context->screen->get_aspect_ratio(), near_plane, far_plane);
                display::scoped_color cc(*draw_context->screen, color::WHITE);

                gsgl::real_t screen_width = utils::pixel_size(dist, radius, draw_context->cam->get_field_of_view(), draw_context->screen->get_height());

                if (screen_width < MIN_PIXEL_WIDTH)
                {
                    display::scoped_state state(*draw_context->screen, draw_context->display_flags(this, drawing_context::RENDER_NO_LIGHTING));

                    set_flags(get_draw_results(), node::NODE_DREW_POINT);
                    draw_context->screen->draw_point(vector::ZERO, MIN_PIXEL_WIDTH);
                }
                else
                {
                    display::scoped_state state(*draw_context->screen, draw_context->display_flags(this));

                    draw_context->screen->clear(display::CLEAR_DEPTH);
                    display::scoped_modelview mv(*draw_context->screen, &litho->get_modelview());

                    litho->draw(sim_context, draw_context);
                }

                // draw name
                draw_name(draw_context);
            }
            else
            {
                celestial_body::draw(sim_context, draw_context);
            }

#if 0
            lithosphere *litho = get_lithosphere();
            if (litho)
            {
                glPushAttrib(GL_ALL_ATTRIB_BITS);                                                                   CHECK_GL_ERRORS();
                glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);                                                      CHECK_GL_ERRORS();

                vector ep = utils::pos_in_eye_space(this);

                gsgl::real_t radius = gsgl::max_val(get_polar_radius(), get_equatorial_radius());
                gsgl::real_t dist = ep.mag();
                gsgl::real_t zdist = -ep.get_z();
                gsgl::real_t far_plane = zdist + (radius * 1.1f);
                gsgl::real_t near_plane = zdist - (radius * 1.1f);
                if (near_plane <= 0)
                    near_plane = 1;

                glMatrixMode(GL_PROJECTION);                                                                        CHECK_GL_ERRORS();
                glLoadIdentity();                                                                                   CHECK_GL_ERRORS();
                gluPerspective(draw_context->cam->get_field_of_view(), draw_context->screen->get_aspect_ratio(), near_plane, far_plane);  CHECK_GL_ERRORS();

                // check to see if we're out of range
                gsgl::real_t screen_width = utils::pixel_size(dist, radius, draw_context->cam->get_field_of_view(), draw_context->screen->get_height());

                color::WHITE.bind();

                if (screen_width < MIN_PIXEL_WIDTH)
                {
                    get_draw_results() |= node::NODE_DREW_POINT;
                    draw_point(MIN_PIXEL_WIDTH);
                }
                else
                {
                    glClearDepth(1);                                                                                CHECK_GL_ERRORS();
                    glClear(GL_DEPTH_BUFFER_BIT);                                                                   CHECK_GL_ERRORS();
                    glEnable(GL_DEPTH_TEST);                                                                        CHECK_GL_ERRORS();

                    glEnable(GL_CULL_FACE);                                                                         CHECK_GL_ERRORS();
                    glPolygonMode(GL_FRONT_AND_BACK, (draw_context->render_flags & drawing_context::RENDER_WIREFRAME) ? GL_LINE : GL_FILL);     CHECK_GL_ERRORS();

                    // set up lighting
                    if (!(draw_context->render_flags & drawing_context::RENDER_NO_LIGHTING) && !(get_draw_flags() & NODE_DRAW_UNLIT))
                    {
                        glEnable(GL_LIGHTING);                                                                          CHECK_GL_ERRORS();

                        glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);                                            CHECK_GL_ERRORS();
                        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);                                               CHECK_GL_ERRORS();
                        //glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);

                        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color::WHITE.get_val());                         CHECK_GL_ERRORS();
                        glMaterialfv(GL_FRONT, GL_SPECULAR, color::BLACK.get_val());                                    CHECK_GL_ERRORS();
                        glMaterialfv(GL_FRONT, GL_EMISSION, color::BLACK.get_val());                                    CHECK_GL_ERRORS();
                        glMaterialf(GL_FRONT, GL_SHININESS, 8);                                                         CHECK_GL_ERRORS();
                    }

                    // set up texturing
                    if (!(draw_context->render_flags & drawing_context::RENDER_NO_TEXTURES))
                    {
                        glEnable(GL_TEXTURE_2D);
                    }

                    // draw lithosphere
                    glMatrixMode(GL_MODELVIEW);
                    glPushMatrix();
                    glLoadMatrixf(litho->get_modelview().ptr());
                    
                    litho->draw(sim_context, draw_context);

                    glMatrixMode(GL_MODELVIEW);
                    glPopMatrix();
                }

                glPopClientAttrib();                                                                                CHECK_GL_ERRORS();
                glPopAttrib();                                                                                      CHECK_GL_ERRORS();

                draw_name(draw_context, 1, far_plane);
            }
            else
            {
                celestial_body::draw(sim_context, draw_context);
            }
#endif
        } // large_rocky_body::draw()