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.


Messages - vidjogamer

Pages: [1] 2 3 ... 5
1
Graphics / Re: Sprite Masking in SFML2
« on: May 05, 2012, 01:11:12 am »
Why doesnt this work:

Code: [Select]
sf::CircleShape circle(5,32);
circle.setPosition( sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y );
circle.setFillColor(sf::Color::Transparent);
target.draw(circle,sf::BlendNone);
target.display();


if this works:

Code: [Select]
sf::Vertex point(sf::Vector2f(sf::Mouse::getPosition(window)), sf::Color::Transparent);
target.draw(&point, 1, sf::Points, sf::BlendNone);
target.display();

2
Graphics / Re: SFML 2RC sf::View Not Updating
« on: April 30, 2012, 07:22:50 am »
Oh, looks like I just had to setView() and it works.

Does anyone know why I dont have to call setView for it to work the first time I manipulate the view?

3
Graphics / SFML 2RC sf::View Not Updating
« on: April 30, 2012, 02:46:42 am »
I am trying to zoom and pan my view with the keyboard. I can manipulate the view when I first create my window... just not during the loop.  Am I doing this the wrong way?

#include <stdexcept>
#include <iostream>
#include <vector>
#include <stdlib.h>

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

using namespace std;


int main(int argc, char** argv) {
       
        //set up a clock to keep track of time
        sf::Clock clock;

        sf::RenderWindow *window;       //sfml window object

        //create a new SFML rendering window
        window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "SFML Test");
        sf::View *view;
        view = const_cast<sf::View*>( &window->getView() );
        view->zoom(2);

        //prevent crazy frame rates (and make the framerate pseudo-sync with the physics stepping, though this is a crappy method of doing so)
        window->setVerticalSyncEnabled(true);
       
               
        sf::Texture texture;
        if (!texture.loadFromFile("./images/blah.jpg")) throw runtime_error("could not load blah.png");
        sf::Sprite sprite;
        sprite.setPosition(300,300);
        sprite.setTexture(texture);
        sf::Vector2f spriteSize = sf::Vector2f(sprite.getLocalBounds().width, sprite.getLocalBounds().height);
        sprite.setOrigin(spriteSize.x/2, spriteSize.y/2);
        sprite.setScale(0.1,0.1);
               

        sf::Event sfmlEvent;
        //start the game loop
        while ( window->isOpen() )
        {
                //check for window closing events
                while (window->pollEvent(sfmlEvent)) {
                        if (sfmlEvent.type == sf::Event::Closed) window->close();
                        if (sfmlEvent.type == sf::Event::KeyPressed) {
                                if (sfmlEvent.key.code == sf::Keyboard::Escape) window->close();
                        }
                }

                //get the current "frame time" (seconds elapsed since the previous frame, hopefully close to 1/60 since vsync is enabled)
                float frameTime = clock.restart().asSeconds();
                       
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Comma)) ( view->zoom(1.1) );
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Period)) ( view->zoom(0.9) );

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) ( view->move(-1,0) );
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) ( view->move(1,0) );
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) ( view->move(0,1) );
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) ( view->move(0,-1) );
       
               
                //clear the window's rendering area before drawing
                window->clear();

                window->draw(sprite);

                //update the rendering window with all the latest drawn items
                window->display();
        }

        //clean up before exiting
        delete window;
       
        return EXIT_SUCCESS;
}
 


4
General discussions / sf::Texture implemented in SFML 2
« on: January 24, 2012, 05:52:58 am »
Sorry. I actually deleted that test project. The code was really that simple though. Just initialization and a sound played on the LoadFromFile() line.

I believe that the strange behavior was a result of linking the libs wrong. Maybe linking to release from a debug build. That solved some other strange issues I had in another project, but I have not tested it here.

You would probably know more than I if that could cause such a problem?

5
Graphics / Why does rendering time vary?
« on: January 24, 2012, 05:22:47 am »
So I started doing some more tests for optimization and I just cant figure it out.

This new code does some various tests. Its pretty self explanatory.
Whats interesting to me is that the same operation might take 20 times longer one run to the next. Here is my output: https://legacy.sfmluploads.org/cache/pics/198_Capture.PNG

Take a look at the last test. The one drawing 2000 1x1 pixel sprites.
In my output, the first 3 results are about 90 times slower than the following samples.

I just cant figure out why there would be such a large discrepancy in the numbers. Is there something going on under the hood that would contribute to this? Maybe my logic is just off? Maybe this is just normal? If anyone has any advice to optimize rendering I would love to hear it.

Here are the tests:
Code: [Select]
int main()
{

sf::Image image_1;
image_1.LoadFromFile("1x1.png");
sf::Sprite sprite_1;
sprite_1.SetImage(image_1);

sf::Image image_2048;
image_2048.LoadFromFile("2048x2048.png");
sf::Sprite sprite_2048;
sprite_2048.SetImage(image_2048);

sf::Image image_2048_2;
image_2048_2.LoadFromFile("2048x2048_2.png");
sf::Sprite sprite_2048_2;
sprite_2048_2.SetImage(image_2048_2);


float time = 0;
   
// Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   

sf::Clock clock;

///////////////////////////////////////////////////////////////////////////////////////////////////////

for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<2000; i++)
{
App.Draw(sprite_2048);
}
App.Display();
time = clock.GetElapsedTime();

printf("draw one 2048x2048 2000 times: %f \n", time);
}
printf("\n\n");

///////////////////////////////////////////////////////////////////////////////////////////////////////

for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<1000; i++)
{
App.Draw(sprite_2048);
App.Draw(sprite_2048_2);
}
App.Display();
time = clock.GetElapsedTime();

printf("draw two 2048x2048 alternating 1000 each: %f \n", time);
}
printf("\n\n");

///////////////////////////////////////////////////////////////////////////////////////////////////////

for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<1000; i++)
{
App.Draw(sprite_2048);
}
for(int i=0; i<1000; i++)
{
App.Draw(sprite_2048_2);
}

App.Display();
time = clock.GetElapsedTime();

printf("draw two 2048x2048 batched 1000 each: %f \n", time);
}
printf("\n\n");

///////////////////////////////////////////////////////////////////////////////////////////////////////

for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<2000; i++)
{
App.Draw(sprite_1);
}
App.Display();
time = clock.GetElapsedTime();
printf("draw one 1x1 2000 times: %f \n", time);
}
printf("\n\n");

///////////////////////////////////////////////////////////////////////////////////////////////////////

int x;
std::cin>>x;

    return EXIT_SUCCESS;
}

6
Graphics / Why does rendering time vary?
« on: January 23, 2012, 03:25:34 am »
When I run this app, the first few iterations consistently take much less time compared to latter iterations, can anyone explain why?

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>


using namespace std;


int main()
{
float time = 0;
   

    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   
sf::Image image;
image.LoadFromFile("1024x1024.png");
sf::Sprite sprite;
sprite.SetImage(image);
sprite.SetPosition(0,0);

sf::Clock clock;

for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<5000; i++)
{
App.Draw(sprite);
}
App.Display();
time = clock.GetElapsedTime();

printf("time: %f \n", time);
}

int x;
std::cin>>x;

    return EXIT_SUCCESS;
}


This is the output I get:
https://legacy.sfmluploads.org/cache/pics/197_Capture.PNG

7
Window / Funny Window Titles
« on: January 22, 2012, 08:15:28 pm »
Thanks I'll try that out. I thought if I linked Release libs it would run faster.


EDIT:
Ok, tried it. Ran it a few times to test, seems like it works. Does anyone know why that causes a problem under the hood? Am I also incorrect for thinking it would be faster to just use the release libs in debug mode?

8
Window / Funny Window Titles
« on: January 22, 2012, 05:03:56 am »
Hi, I just started a new project and started with one of the tutorials as a base, except my window title isnt showing up correctly.  Its showing as random characters. Any ideas?

Pic: https://legacy.sfmluploads.org/cache/pics/196_Capture.PNG

Code:
Code: [Select]


#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>


using namespace std;
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   
    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
while (App.PollEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear the screen (fill it with black color)
        App.Clear();

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

9
General discussions / sf::Texture implemented in SFML 2
« on: January 18, 2012, 03:55:44 pm »
Is this supposed to cause the speakers to repeatedly beep?
Also it crashes and the file is in the application directory.

Code: [Select]

sf::Texture texture;
texture.LoadFromFile("green_128.png");

10
General discussions / Question about rendering performance.
« on: January 14, 2012, 12:03:30 pm »
So if I have an animated character in my game, but there is only one instance of this character. He gets drawn every frame between the background and foreground tiles. Would it not affect the game? At first thought it would seem the system switches to the background texture, then to the current character texture (regardless of sprite sheet or individual textures it has to change just once), then once more to the foreground texture. For a total of 3 changes per frame. If that is the case I don't see how it makes a difference in that scenario.

So now assume we have a game with many different objects, would I achieve better performance by drawing objects that use the same texture in order then? Or does SFML do this under the hood?

11
General discussions / Question about rendering performance.
« on: January 14, 2012, 05:03:25 am »
Hello, I am just curious what the performance cost would be if each frame of my animated sprite were a separate png vs setting the sub rect of a large sprite sheet each frame.

12
General discussions / SFML 2.0 with opengl
« on: May 05, 2011, 08:31:44 am »
Haha is it a secret? I wanted to know what it was =p

Anyway, if the Renderer isnt going to be the way to do things, I still need to figure out how to get the opengl calls working then. For example, Hiura's animation package does not work correctly. My test animation sprite turns the same color as my text that im rendering.

Code: [Select]

f.my_image->Bind();


// Calculate the texture coordinates
sf::FloatRect rect =
f.my_image->GetTexCoords(f.my_rect);

// Draw the animation's triangles
glBegin(GL_QUADS);
                glTexCoord2f(rect.Left,  rect.Top);
                glVertex2f(0,     0);

                glTexCoord2f(rect.Left,  rect.Height);
glVertex2f(0,     height);

                glTexCoord2f(rect.Width, rect.Height);
glVertex2f(width, height);

glTexCoord2f(rect.Width, rect.Top);
glVertex2f(width, 0) ;
glEnd();


Theres nothing fancy going on with the text. Its just an sf::Text being passed to my RenderWindow's Draw call.

13
General discussions / SFML 2.0 with opengl
« on: May 04, 2011, 08:12:55 pm »
Oh is that so? Taking a different approach?

14
General discussions / SFML 2.0 with opengl
« on: May 04, 2011, 06:36:21 pm »
I started using Hiura's animation package and realized that it had similar problems, I ended up changing the implementation to use the sf::Renderer but theres one call I dont know how to do: glDisable(GL_TEXTURE_2D);

Can I call glDisable from the Renderer? How? I didnt realize it was advised to use a renderer for opengl drawing. When I found it practically all my problems were solved  :roll:

15
General discussions / SFML 2.0 with opengl
« on: May 04, 2011, 03:54:43 pm »
So I ended up just replacing it with an SFML implementation of DebugDraw and it works like a charm. I would like to know if anyone knows why the opengl implementation wasnt working though. I might choose to use some opengl in the near future.

Pages: [1] 2 3 ... 5
anything