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 - Noegddgeon

Pages: 1 [2] 3 4
16
Graphics / Pointer to Rectangle
« on: December 20, 2010, 10:10:36 pm »
Quote from: "Laurent"
If all you did is storing the shape in a variable, and get a lower framerate, you certainly did something wrong ;)


Perhaps I did. Would you mind taking a look at my code and telling me what I could do to get my desired results? :]

Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics",
                    sf::Style::Fullscreen);
int pointCounter = 0;
int randX, randY, r, g, b;

sf::Clock pointTimer;
sf::Shape rect = sf::Shape::Rectangle(0, 0, 1, 1, sf::Color(0, 0, 0));

App.Clear();
pointTimer.Reset();

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

randX = sf::Randomizer::Random(0, 640);
randY = sf::Randomizer::Random(0, 480);
r = sf::Randomizer::Random(0, 255);
g = sf::Randomizer::Random(0, 255);
b = sf::Randomizer::Random(0, 255);

rect.SetPosition(randX, randY);
rect.SetColor(sf::Color(r, g, b));

App.Draw(rect);

pointCounter += 1;

if (pointTimer.GetElapsedTime() >= 10)
{
  cout << "Points Drawn 10 Sec: " << pointCounter << endl;
  return EXIT_SUCCESS;
   }

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


Thank ya, sir. :]

17
Graphics / Pointer to Rectangle
« on: December 20, 2010, 02:38:27 pm »
Quote

Why do you want a pointer? You just want to store the object in a variable so that it is not reconstructed every time.


You're right, haha. I was confusing myself, but I understand now.

And as for the Rectangle itself and trying to adjust its dimensions, I discovered that doing all of this and trying to save time and make the program better is actually making it run a tiny bit slower :p I have it nearly finished with how I would like for it to be, but it's not drawing them visibly. It's enough to let me know how many it's drawing in 10 seconds though, and it's almost 1000 lower than the original. What a shame :[

Thanks for your help! :][/quote]

18
Graphics / Pointer to Rectangle
« on: December 20, 2010, 01:56:43 pm »
Ahhh, okay, thank you :] That much makes sense, but that's an object and not a pointer, isn't it? I'm not even sure if what I want to do will work anymore, but I'm working on it right now and trying to figure it out. :p

Once I've initialized the Rectangle object, how can I alter its dimensions again? I know I can use SetPosition to affect its coordinates, but I don't know how to access its width and height parameters.

19
Graphics / Pointer to Rectangle
« on: December 20, 2010, 01:31:57 pm »
Hello, everybody :]

Is it possible to make a pointer to an sf::Shape::Rectangle object? I know it's a static function, but I'm not altogether familiar with static functions to know what can and cannot be done with them.... I just know that you can access their data without one being instantiated.

My idea was to create a pointer to a single Rectangle (which is to be 1 x 1 in size so as to emulate drawing a pixel) and then point to it using a pointer in the Draw function in my program to randomly redraw it a bunch of times on the screen. What I have as my original idea is this, without pointers:

Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics",
                    sf::Style::Fullscreen);
int pointCounter = 0;
int randX, randY;

sf::Clock pointTimer;

App.Clear();
pointTimer.Reset();

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

randX = sf::Randomizer::Random(0, 640);
randY = sf::Randomizer::Random(0, 480);

App.Draw(sf::Shape::Rectangle(randX, randY, randX + 1, randY + 1,
        sf::Color(sf::Randomizer::Random(0, 255),
          sf::Randomizer::Random(0, 255),
  sf::Randomizer::Random(0, 255))));

pointCounter += 1;

if (pointTimer.GetElapsedTime() >= 10)
{
  cout << "Points Drawn 10 Sec: " << pointCounter << endl;
  return EXIT_SUCCESS;
   }

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


It lets you see how many of the Rectangles were drawn through the console in 10 seconds, and I'm at about 23,000 while in fullscreen and 12,000 in windowed mode. It was my hope that I could increase this number using a pointer to a single Rectangle and then refer to it and adjust its properties every iteration instead of drawing a brand new one. Any thoughts or possible suggestions, or any information as to whether this idea is even plausible to begin with? :] Thank you all very much!

Colton

20
Graphics / Drawing pixel
« on: December 19, 2010, 08:49:43 am »
I think it is software rendering, yes. I'm trying to do a cross comparison of SDL and SFML because there are a bunch of tutorials available for SDL that I wanted to try with SFML.

Quote

By the way, the best technique is to use OpenGL to render points directly. There should be an API for doing this in SFML 2.


Sweet. I'm going to be embarking on the quest of learning OpenGL sometime in the future :] Should be lotsa fun.

21
Graphics / Drawing pixel
« on: December 19, 2010, 12:15:26 am »
Laurent,

I was going back through some Allegro files I had written from a tutorial book a long time ago and looked at their putPixel function. Is it simply a matter of taste that you decided not to include a similar function in SFML that didn't require a buffer, or is the same amount of work most likely being done by Allegro as SFML, just with more of a straightforward wrapper? Thank you for your time.

Colton

EDIT:

Also, I noticed that using the buffer is actually much slower than drawing Rectangles that are 1 x 1 pixel in size. Perhaps I'm doing it wrong? Here's my functional code:

Code: [Select]

#include <SFML/Graphics.hpp>
#include <cstdlib>

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics");

// Buffer
sf::Image buffer(640, 480, sf::Color(0, 0, 0));

// Sprite buffer
sf::Sprite bufferSprite(buffer);

// Random seed
srand(10);

int randX, randY;
int r, g, b;

App.Clear();

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        randX = rand() % 640;
randY = rand() % 480;

r = rand() % 255;
g = rand() % 255;
b = rand() % 255;

buffer.SetPixel(randX, randY, sf::Color(r, g, b));

App.Draw(bufferSprite);

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


The Allegro putPixel function draws the pixels at lightning speed, so I'd like to know if this would be possible somehow with SFML :]

22
Audio / Evasive Bug... Could Be Anything
« on: December 18, 2010, 09:21:24 am »
Thank you, sir :] I fixed the code and compiled it, but of course, there are new problems to greet me. Now it gets stuck on the strlen thread before the RenderWindow is even deployed, saying I get another EXC_BAD_ACCESS. I wonder if perhaps there's a bug with Mac OS X and the audio framework in weird situations? I ran other applications using the audio framework with success, so I'm confused.

23
Audio / Evasive Bug... Could Be Anything
« on: December 17, 2010, 11:16:19 pm »
Actually, I discovered something else. The programs will compile fine without linking the sfml-audio framework.... however, once I link that framework is when the RenderTarget::Clear function thing pops up and causes the white screen of infinite loop death. Any thoughts on why this might be the case?

EDIT: I also just linked the sndfile framework to it as well, but to no avail. Still does the same thing.... displays EXC_BAD_ACCESS with RenderTarget::Clear() showing as the thread it's stopped at. lolll Does this mean I can't link to the audio framework anymore? XD

EDIT 2: I have a feeling it's all related to the fact that my RenderWindow is global, perhaps, and it's causing some sort of problems. Or at least I'm trying something new. But I tried altering my functions so that they will take an Input argument. However, I'm not exactly sure how I can go about doing this. How do I pass this:

const sf::Input& Input

to a function properly? This is what I made and I'll write the errors as well:

Code: [Select]

// Function prototype
void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&, sf::RenderWindow&, const sf::Input);
*
*
*
// Function call
 // Process input
 getInput(Player1.y, Player1.boty, Player2.y, Player2.boty, Player1.PaddleTimer, Player2.PaddleTimer, App, Input);
*
*
*
// Beginning of the actual function implementation
// Process inputs and move players accordingly
void getInput(int &y1, int &boty1, int &y2, int &boty2, sf::Clock &Pad1, sf::Clock &Pad2, sf::RenderWindow App, const sf::Input& Input)
{
   
   App.GetInput();
   
   if ((Input.IsKeyDown(sf::Key::Up)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 > 0)
      {
    y1--;
    boty1--;
 }
 Pad1.Reset();
   }


Errors:

warning: synthesized method 'sf::Input::Input(const sf::Input&)' first required here
warning:   initializing argument 8 of 'void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&, sf::RenderWindow&, sf::Input)'

Those were both on the line where the function gets called.

I'm familiar with functions and passing by value and by reference but I don't know how to do it with the Input construct, as it seems a little different. Guidance would be much appreciated, and perhaps my theory could then solve the problem :] Thanks a lot!

24
Audio / Evasive Bug... Could Be Anything
« on: December 17, 2010, 10:28:11 pm »
Problem solved, Laurent. You were right :] For some reason, it just must have been some sort of corrupted project... doesn't make any sense, but the fix is fairly easy. I appreciate all your time and assistance. Perhaps you'll see me again soon with something more interesting to ask about ;]

25
Audio / Evasive Bug... Could Be Anything
« on: December 17, 2010, 10:52:31 am »
Of course ;] But the fact that this is such an obvious problem and yet has no solution baffles me. And I've run other applications today which I've previously written that call the Clear() function as well, and with no problems whatsoever. I don't know how one can explain that. And I tried rewriting the code in various ways, all with the same result. I took out the Clear function, and the program ran. Put it back in, all in different places, with the same result.

In any case, Laurent, I appreciate your time, and I did learn a little bit about how to debug in my IDE :]

26
Audio / Evasive Bug... Could Be Anything
« on: December 17, 2010, 03:17:37 am »
I reinstalled SFML and tried running it again but had no success :p Could you try running it on your platform, Laurent, and see if it runs or whether you get a similar or different message, perhaps? :] Thank you for your help. I'm determined to solve this problem.

27
Audio / Evasive Bug... Could Be Anything
« on: December 16, 2010, 11:44:12 am »
Wow, it does the same thing. It's not like I changed any of the library files, so I find this rather peculiar. sf::RenderWindow::Clear, and then a white screen of death.

28
Audio / Evasive Bug... Could Be Anything
« on: December 16, 2010, 01:13:50 am »
Lah-RAUN! (with emphasis ;]) :D

haha, I tried to shrink it down even further, still with the same results and still saying there's something causing an issue with sf::RenderTarget::Clear. I know I'm calling the App.Clear() function in there, but I tried removing all the instances of them and recompiling but it still showed the same error :p

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

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

void screen(sf::RenderWindow&, sf::Sprite&);

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

// Images for screens
sf::Image titleImage;

// Sprites for screens
sf::Sprite titleSprite;

int main()
{
   // Game start variable
   bool gameStart = true;
   
   titleImage.LoadFromFile("pong_title.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   titleSprite.SetPosition(0,0);
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      while (App.GetEvent(Event))
 {
    if (Event.Type == sf::Event::Closed)
   App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
   App.Close();
 }
 
 // Opening screen
 if (gameStart)
 {
    App.Clear();
    screen(App, titleSprite);
gameStart = false;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
}

// Functions and their declarations

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}


Thank you much as always, Mr. Laurent! Hope this is skimpy enough! :p

29
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 12:15:53 pm »
:shock:

This is weird stuff, man.  :cry:  I don't recall ever having changed something, but I'll assume I did without recognizing it. The program did run before I added the sound features though, I can promise that. And when I added the sound features, I don't recall tweaking much in the program other than what I needed just to get the sound to work :p Perhaps my mind and fingers strayed on the keyboard while contemplating how wonderful my Pong remake would be with sound? ;]

Now that it's been narrowed down, it's all within the screen() function still. I would love to know what is causing this problem, as I feel it's one of those incidences that prove to be great learning moments.

Thank you for all your help Laurent. By the way, is it pronounced "LORE-int" or "Lore-ONNN"?

30
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 11:53:31 am »
Okie doke, sir. I have done my best. :] Hope this helps.

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

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

void screen(sf::RenderWindow&, sf::Sprite&, sf::View&);

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// View declaration -- Atari resolution
sf::View View(sf::FloatRect(0, 0, 192, 160));

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

// Images for screens
sf::Image titleImage;
sf::Image winningImage;
sf::Image losingImage;

// Sprites for screens
sf::Sprite titleSprite;
sf::Sprite winningSprite;
sf::Sprite losingSprite;

int main()
{
   // Game start variable
   bool gameStart = true;
   
   titleImage.LoadFromFile("pong_title.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   titleSprite.SetPosition(0,0);
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      while (App.GetEvent(Event))
 {
    if (Event.Type == sf::Event::Closed)
   App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
   App.Close();
 }
 
 App.Clear();
 
 // Opening screen
 if (gameStart)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
}

// Functions and their declarations

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot, sf::View &myView)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.SetView(myView);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}

Pages: 1 [2] 3 4
anything