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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Ockonal

Pages: [1]
1
Graphics / RenderTexture question
« on: October 23, 2012, 12:23:40 am »
Hello, I have a render texture and now I found that it's turned with 2Pi radians. Now when I want to convert some coords with renderTarget()->convertCoords(x, y) I get them but refer to bottom&right, not left&top.

When I call renderTarget.display() the texture becomes "normal". That's a feature? :)

2
Graphics / sf::View and render target
« on: October 20, 2012, 01:23:02 am »
Hello, I have a few questions about how views are working.

    sf::RenderWindow *mApp;
    sf::View *mCamera;
    sf::RenderTexture *mRenderTarget;

So first, everything is rendered into mRenderTarget and at the end of the game cycle I draw final image to mApp.

Here is the function which initializes camera and reinitializes it when window is resized:

void DisplayManager::InitializeCamera(const sf::FloatRect &rect)
{
    // This is automatically called when window is resized
    mCamera->reset(rect);
    mApp->setView(*mCamera);

    mRenderTarget->create(rect.width, rect.height);
    mRenderTarget->setView(*mCamera);
}
 
And it looks like:
    mRenderTarget->display();
    mApp->draw(sf::Sprite(mRenderTarget->getTexture()));
    mApp->display();

The questions:
Is that code right?
How does views work? When I change some parameters of it I have to reinitialize render target and/or window with same view:

         mCamera->zoom(0.96);
        //mApp>setView(*mCamera);  // Required?
        mRenerTarget->setView(*mCamera);

Should I set view to render target only (everything is drawn onto it first)? And why should I setView again and again after any change to the view object? If sf::Window (abstract) takes in arguments address of the view why doesn't it track the changes inside the object?

And the last: when I want to use sf::Window::convertCoords, should I call it from renderTarget (sf::RenderTextuer) or mApp (sf::RenderWindow)?

Thanks ;)

3
Graphics / Polygon to shader
« on: October 16, 2012, 04:03:15 pm »
Hello, I'm rendering everything to RenderTexture: image and polygon. It looks like 1.png from attachment. The code is:

    sf::Texture img;
    img.loadFromFile("test.png");
    RENDER_TEXTURE->draw(sf::Sprite(img));

    sf::ConvexShape polygon;
    polygon.setPointCount(3);
    polygon.setPoint(0, sf::Vector2f(0, 0));
    polygon.setPoint(1, sf::Vector2f(230, 10));
    polygon.setPoint(2, sf::Vector2f(70, 200));
    polygon.setOutlineColor(sf::Color::Red);
    polygon.setFillColor(sf::Color::Transparent);
    polygon.setOutlineThickness(5);

    RENDER_TEXTURE->draw(polygon);

Now I want to apply some shader for the area inside that polygon. I wrote a simple one:

uniform sampler2D texture;

void main()
{
    vec4 color = texture2D(texture, gl_TexCoord[0].xy);
    if (color.a != 0.)
    {
        color.r += 0.4;
    }

    gl_FragColor = color;
}

And changed the code of polygon drawing to:
shader.setParameter("texture", sf::Shader::CurrentTexture);
RENDER_TEXTURE->draw(polygon, shader);

The result you could see at second attachment. So, the shader is applied only for polygon, not for the whole texture inside it. But what to do if I want to pass that area inside polygon into shader and make it more red?

[attachment deleted by admin]

4
General / Coordinates system
« on: August 07, 2012, 05:57:44 pm »
Hello, I'm using box2d with sfml and they have different coord system. In SFML Y is directed updown, and in Box2D downup. Any ways to change SFML's  one to box2d's?

5
General / 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?

6
Graphics / Line shape
« on: January 30, 2012, 10:11:54 pm »
Hello, after new upgrade in sfml api I founded that sf::Shape::Line, for example was removed. So now the only way to do is to create polygon with 2 points?

7
Window / OIS as an input system
« on: November 07, 2011, 11:57:00 pm »
Hello, I have to include some of input system into sfml because It's not enough to catch them from main cycle but I need in callbacks for events. So I decided to use OIS in my app. Here is the code:

Code: [Select]
   OIS::ParamList params;
    std::string window = boost::lexical_cast<std::string>(mWindow->GetSystemHandle());
    // Logging of window variable shows 6-digits number

    params.insert(std::make_pair(std::string("WINDOW"), window));

    mInputSystem = OIS::InputManager::createInputSystem(params);


mWindow is pointer to the sf::RenderWindow. When running app I get:

Quote
X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  2 (X_ChangeWindowAttributes)
  Serial number of failed request:  7
  Current serial number in output stream:  9


What's wrong?

8
General / How to catch mouse
« on: August 24, 2010, 09:10:52 am »
Hello, by default, mouse isn't catched by application, so I'm able to move cursor out the window area. How can I bind/catch it for my application?

9
General / Mouse press event
« on: August 17, 2010, 10:37:41 am »
Hello, I'm writing Application which uses SFML as input system. I use it with Ogre3d  engine. The part of creating sfml-window:
Code: [Select]
size_t mWindowHandle;
ogreWindow->getCustomAttribute("WINDOW", &mWindowHandle);
boost::shared_ptr<sf::Window> = mInputWindow = boost::shared_ptr<sf::Window>( new sf::Window(mWindowHandle) );


And in global update cycle:
Code: [Select]
sf::Event localEvent;

while(mInputWindow->GetEvent(localEvent))
{
     using namespace Engine::Events;
     sf::Event::EventType type = localEvent.Type;

     if (type == sf::Event::MouseButtonPressed) { cout << "Mouse bbutton pressed!"; }
     else if (type == sf::Event::MouseButtonReleased) { cout << "Mouse button released!"; }
}


The text never writes to the console. All another events work (I tested key events). Also I could work with input handle mInputWindow->GetInput(). Using it I can show the cursor position, show/hide it, etc. All this stuff works.

I tried to do something like (in global cycle too):        
Code: [Select]
if (mInputWindow->GetInput().IsMouseButtonDown(sf::Mouse::Left))
{
   cout << "Left mouse button is pressed!";
}

Thid doesn't work too.
What could it be?

10
Window / Cursor manipulation
« on: July 11, 2010, 07:46:21 pm »
Hello, I'm using SFML with Ogre. I'm taking the handle like this:
Code: [Select]
size_t handle;
OgreWindow->getCustomAttribute("WINDOW", &handle);
sf::Window winHandle;
winHandle.Create(handle);

Now I need to hide cursor and move it to the center of the window:
Code: [Select]
winHandle.SetCursorPosition(GetWidth()/2, GetHeight()/2);
winHandle.ShowMouseCursor(false);

But nothing happens. Native SFML events work fine. What's wrong is there?

Pages: [1]
anything