Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Spark2 in sfml  (Read 1946 times)

0 Members and 1 Guest are viewing this topic.

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Spark2 in sfml
« on: March 10, 2012, 12:39:34 pm »
Hello, I've decided to use Spark2 OpenGL renderer with sfml2.

The initialization code:

Code: [Select]
   mSystem = SPK::System::create(true);
    mSystem->setName("Particles");

    SPK::System::setClampStep(true, 0.1f);
    SPK::System::useAdaptiveStep(0.001f, 0.01f);

    // Load particle texture
    GLuint texture = 0;
    {
        sf::Image image;
        if (!image.LoadFromFile("Media/explosion.bmp"))
            ERR("FAILED TO LOAD TEXTURE");

        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    }

    // Create quad renderer
    mRenderer = SPK::GL::GLQuadRenderer::create();
    mRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
    mRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE, false);
    mRenderer->setTexture(texture);
    mRenderer->setTexturingMode(SPK::TEXTURE_MODE_2D);
    mRenderer->setAtlasDimensions(2, 2);


And some fun with emitters:
Code: [Select]
   SPK::Ref<SPK::SphericEmitter> emitter = SPK::SphericEmitter::create(SPK::Vector3D(0.0f,0.0f,-1.0f),0.0f,3.14159f / 4.0f,SPK::Point::create(),true,-1,100.0f,0.2f,0.5f);

    SPK::Ref<SPK::Group> phantomGroup = mSystem->createGroup(40);
    SPK::Ref<SPK::Group> trailGroup = mSystem->createGroup(1000);

    SPK::Ref<SPK::Plane> ground = SPK::Plane::create(SPK::Vector3D(0.0f,-1.0f,0.0f));

    phantomGroup->setName("Phantom Group");
    phantomGroup->setLifeTime(5.0f,5.0f);
    phantomGroup->setRadius(0.06f);
    phantomGroup->addEmitter(SPK::SphericEmitter::create(SPK::Vector3D(0.0f,1.0f,0.0f),0.0f,3.14159f / 4.0f,SPK::Point::create(SPK::Vector3D(0.0f,-1.0f,0.0f)),true,-1,2.0f,1.2f,2.0f));
    phantomGroup->addModifier(SPK::Gravity::create(SPK::Vector3D(0.0f,-1.0f,0.0f)));
    phantomGroup->addModifier(SPK::Obstacle::create(ground,0.8f));
    phantomGroup->addModifier(SPK::EmitterAttacher::create(trailGroup,emitter,true));

    trailGroup->setName("Trail");
    trailGroup->setLifeTime(0.5f,1.0f);
    trailGroup->setRadius(0.06f);
    trailGroup->setRenderer(mRenderer);
    trailGroup->setColorInterpolator(SPK::ColorSimpleInterpolator::create(0xFF802080,0xFF000000));
    trailGroup->setParamInterpolator(SPK::PARAM_TEXTURE_INDEX,SPK::FloatRandomInitializer::create(0.0f,4.0f));
    trailGroup->setParamInterpolator(SPK::PARAM_ROTATION_SPEED,SPK::FloatRandomInitializer::create(-0.1f,1.0f));
    trailGroup->setParamInterpolator(SPK::PARAM_ANGLE,SPK::FloatRandomInitializer::create(0.0f,2.0f * 3.14159f));
    trailGroup->addModifier(SPK::Rotator::create());
    trailGroup->addModifier(SPK::Destroyer::create(ground));


Now I want to render it, in main cycle:
Code: [Select]
   mSystem->updateParticles(dSeconds)

    SPK::GL::GLRenderer::saveGLStates();

    glDisableClientState(GL_COLOR_ARRAY);
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    // Render particles and set back prev states
    mSystem->renderParticles();

    SPK::GL::GLRenderer::restoreGLStates();


And I see fully black screen.

When I remove code related to emitters and settings texture I see my scene but everything is white. What could it be?
Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Spark2 in sfml
« Reply #1 on: March 10, 2012, 04:53:45 pm »
Quad renderer is not working well  i think, i've already posted it on spark forums, ages ago, waiting an answer :)

Use GLPointRenderer and set the type as POINT_SPRITE :)

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Spark2 in sfml
« Reply #2 on: March 10, 2012, 06:07:09 pm »
Thanks for the reply ;)
The new code is:

Code: [Select]
   mRenderer = SPK::GL::GLPointRenderer::create();
    mRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
    mRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE, false);
    mRenderer->setTexture(texture);
    mRenderer->setType(SPK::POINT_TYPE_SPRITE);


Still have a black screen.
Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor