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

Pages: [1]
1
General / Integrating SFML with Modern OpenGL
« on: July 27, 2016, 07:39:07 am »
Hey all,

I'm coding on a Macbook, trying to run the following program:

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

int main() {
    sf::RenderWindow app(sf::VideoMode(640, 480), "OpenGL");

    while (app.isOpen()) {
        sf::Event e;
        while (app.pollEvent(e)) {
            if (e.type == sf::Event::Closed) {
                app.close();
            }
        }

        static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 1.0f};
        glClearBufferfv(GL_COLOR, 0, red);
        app.display();
    }

    return 0;
}
 

However, I get the following error:

sb2-1.cpp:25:9: error: use of undeclared identifier 'glClearBufferfv'
        glClearBufferfv(GL_COLOR, 0, red);
        ^
1 error generated.
 

Using glClear() instead of glClearBufferfv() works perfectly well.

Is there something I need to do to make SFML play nice with newer OpenGL besides what's listed in the docs? Thanks!

2
General / XCode Default Project Fails (Solved)
« on: March 28, 2015, 12:05:35 am »
Hey all,

Decided to get SFML up and running again and seem to be having an issue getting the default project up and running; I'm getting an EXC_BAD_ACCESS error on line 81 (window.draw(sprite)), with the particular assembly line throwing the error being

0x100075b15:  callq  *16(%r9)

Anyone have an idea as to why this would be? I've changed literally nothing about any of the source code and followed all of the instructions per the Tutorial in setting up my project. I'm also running Yosemite atm. Thank you for your help!

Best,
Colton

3
General / Trouble with Self-Compiled Static Libs
« on: July 15, 2014, 05:24:08 am »
Hi all!

Thought I'd give SFML another go (it's been a while!). However, I'm running into a stumbling block; whereas I've gotten it to work fine on my Mac, it's been troublesome on Windows. My issue for a long time was that I was just using the wrong compiler version of GCC, so I couldn't compile with the distributed binaries; after tinkering and switching to using CMake to make my own static libraries, I'm finding that I'm still having difficulties getting things to work; here is the simple example I've been trying to compile:

#define SFML_STATIC
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");

    while (window.isOpen())
    {
        sf::Event event;

        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }

        window.clear(sf::Color::Black);

        window.display();
    }

    return 0;
}
 

And here is the output of my CMake-made static library compilation trial:

Code: [Select]
Z:\sfml_dev>g++ > error.log main.cpp -o main.exe -Ic:/sfml/include -Lc:/sfml/lib
 -lsfml-window-s -lsfml-graphics-s -lsfml-system-s -DSFML_STATIC
main.cpp:1:0: warning: "SFML_STATIC" redefined [enabled by default]
 #define SFML_STATIC
 ^
<command-line>:0:0: note: this is the location of the previous definition
c:/sfml/lib/libsfml-graphics-s.a(RenderWindow.cpp.obj):RenderWindow.cpp:(.text+0
x304): undefined reference to `glReadPixels@28'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x10e): undefined reference to `glClearColor@16'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x11d): undefined reference to `glClear@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x3f0): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x3f6): undefined reference to `glPopMatrix@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x402): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x408): undefined reference to `glPopMatrix@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x414): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x41a): undefined reference to `glPopMatrix@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x41f): undefined reference to `glPopClientAttrib@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x4ff): undefined reference to `glViewport@16'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x50e): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x527): undefined reference to `glLoadMatrixf@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x534): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x600): undefined reference to `glBlendFunc@8'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x628): undefined reference to `glBlendFunc@8'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x650): undefined reference to `glBlendFunc@8'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x678): undefined reference to `glBlendFunc@8'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x6a5): undefined reference to `glDisable@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x6b2): undefined reference to `glDisable@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x6bf): undefined reference to `glDisable@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x6cc): undefined reference to `glDisable@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x6f3): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x700): undefined reference to `glEnableClientState@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x70d): undefined reference to `glEnableClientState@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x71a): undefined reference to `glEnableClientState@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x746): undefined reference to `glLoadMatrixf@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x808): undefined reference to `glPushClientAttrib@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x815): undefined reference to `glPushAttrib@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x822): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x828): undefined reference to `glPushMatrix@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x834): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x83a): undefined reference to `glPushMatrix@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x846): undefined reference to `glMatrixMode@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x84c): undefined reference to `glPushMatrix@0'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
xa0c): undefined reference to `glVertexPointer@16'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
xa36): undefined reference to `glColorPointer@16'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
xa60): undefined reference to `glTexCoordPointer@16'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
xa86): undefined reference to `glDrawArrays@12'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
xaf7): undefined reference to `glLoadMatrixf@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
xb4b): undefined reference to `glLoadMatrixf@4'
c:/sfml/lib/libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0
x427): undefined reference to `glPopAttrib@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: c:/sfml/li
b/libsfml-graphics-s.a(RenderTarget.cpp.obj): bad reloc address 0x6 in section `
.text.startup'
collect2.exe: error: ld returned 1 exit status

I appreciate your time and look forward to getting this finally resolved! :]

Best,
Colton

4
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

5
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 07:50:32 am »
Hello :] I went back to an old Pong game I had written several months ago the other day and finished it up.... well, almost. It was working fairly well, with the title screen, losing screen, winning screen, etc. functioning normally. However, it had no sound effects, so I added a sound effect for when the paddles hit the ball. It took me some trial and error in figuring out how to compile the program once I created a buffer and a Sound object (and I had forgotten to link the audio framework, but I took care of that to seal the compilation deal ;]). However, it's compiled now.... the only problem is, it just shows me the very familiar white screen of infinite loop death. I am compiling this under Xcode 3.1.4 on my MacBook, but I don't think that has anything to do with it. Rather, I think something had to have gotten messed up when I added in the sounds. Here, I'll post the source code... it's a bit lengthy, but I commented a bit. Note: I have learned how to code better than this and I know I should have built classes for it, but this was before I learned anything about OOP. I just wanted to clean this project up and finish it so I could be done with it forever :p Here goes:

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>

// Function prototypes
int distance(int, int, int, int);
void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&);
void calculateBall(int&, int&, sf::Clock&, int&, int&, int&, double&, sf::Sound&);
void drawScore(sf::RenderWindow&, int&, int, int);
void screen(sf::RenderWindow&, sf::Sprite&, sf::View&);

// ENUMS
   enum BallDirection // Different directions/velocities
   {
      UpRight, DownRight, UpLeft, DownLeft
   };
   
   enum PaddleDirection // Different directions/velocities
   {
      Up, Down, Still
   };

// ************ //

// Paddle structure declaration
struct Paddle
{
   int x, y; // Paddle coordinates, upper left
   int botx, boty; // Paddle coordinates, bottom right
   int direction; // Paddle going up or down?
   sf::Clock PaddleTimer; // Movement timer
   
   Paddle(int xcoord, int ycoord, int bottomx, int bottomy, PaddleDirection direc) // Constructor
   {
      x = xcoord;
 y = ycoord;
 botx = bottomx;
 boty = bottomy;
 direction = direc;
   }
};

// Ball structure declaration
struct Ball
{
   int x, y; // Ball's position in the field
   int size; // Ball's size
   int direction; // Ball's current direction/velocity
   double speed; // Speed (less is more)
   sf::Clock BallTimer; // Movement timer
   
   Ball(int xcoord, int ycoord, int ballSize, double ballSpeed = 0.7)
   {
      x = xcoord;
 y = ycoord;
 size = ballSize;
   }
};

// 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;

// Audio variables
sf::SoundBuffer paddleBuffer;
sf::Sound paddleSound;

   // Player and ball declarations
   // **PLAYER 1**
   Paddle Player1(5, 60, 7, 70, Still);
   
   // **PLAYER 2**
   Paddle Player2(184, 60, 186, 70, Still);
   
   // **BALL**
   Ball Ball(80, 80, 2);

int main()
{
   // Game start variable
   bool gameStart = true;

   // Score variable
   
   int score1 = 0, score2 = 0;
   
   // Ball's speed
   double ballSpeed = 0.03;
   
   // Load buffer
   paddleBuffer.LoadFromFile("paddle_hit.wav");
   
   // Set sound
   paddleSound.SetBuffer(paddleBuffer);
   
   // Load images
   titleImage.LoadFromFile("pong_title.png");
   winningImage.LoadFromFile("you_win.png");
   losingImage.LoadFromFile("you_lose.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);
   winningImage.SetSmooth(false);
   losingImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   winningSprite.SetImage(winningImage);
   losingSprite.SetImage(losingImage);
   titleSprite.SetPosition(0,0);
   winningSprite.SetPosition(0,0);
   losingSprite.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)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }
 
 // Game loop activities
 
 // Process input
 getInput(Player1.y, Player1.boty, Player2.y, Player2.boty, Player1.PaddleTimer, Player2.PaddleTimer);
 
 // Calculate ball
 calculateBall(Ball.x, Ball.y, Ball.BallTimer, Ball.direction, score1, score2, ballSpeed, paddleSound);
 
 // Clear previous screen
 App.Clear();
 
 // Draw the paddles and the ball
 App.Draw(sf::Shape::Rectangle(Player1.x, Player1.y, Player1.botx, Player1.boty, sf::Color::White));
 App.Draw(sf::Shape::Rectangle(Player2.x, Player2.y, Player2.botx, Player2.boty, sf::Color::White));
 App.Draw(sf::Shape::Circle(Ball.x, Ball.y, Ball.size, sf::Color::Blue));
 
 // Draw scores
 drawScore(App, score1, 30, 5);
 drawScore(App, score2, 160, 5);
 
 // Set the View
 App.SetView(View);
 
 // Lose or Win?
 if (score1 == 10)
 {
    screen(App, winningSprite, View);
score1 = 0;
score2 = 0;
 }
 
 if (score2 == 10)
 {
    screen(App, losingSprite, View);
score1 = 0;
score2 = 0;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
} // end main

// Functions and their declarations

// Distance formula
int distance(int x1, int y1, int x2, int y2)
{
   int temp = pow((x2 - x1), 2) + pow((y2 - y1), 2);
   return sqrt(temp);
}

// Process inputs and move players accordingly
void getInput(int &y1, int &boty1, int &y2, int &boty2, sf::Clock &Pad1, sf::Clock &Pad2)
{
   App.GetInput();
   
   if ((Input.IsKeyDown(sf::Key::Up)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 > 0)
      {
    y1--;
    boty1--;
 }
 Pad1.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::Down)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 < 150)
 {
         y1++;
    boty1++;
 }
 Pad1.Reset();
   }
   
   if ((Input.IsKeyDown(sf::Key::Q)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 > 0)
 {
         y2--;
    boty2--;
 }
 Pad2.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::A)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 < 150)
 {
         y2++;
    boty2++;
 }
 Pad2.Reset();
   }
}

// Calculate ball and its movement
void calculateBall(int &x, int &y, sf::Clock& ballTime, int &direc, int &score1, int &score2, double &ballSpeed, sf::Sound &paddle)
{
   if (ballTime.GetElapsedTime() >= ballSpeed)
   {
      if (direc == UpRight) // Ball traveling up and to the right?
 {
    if (x >= 192)
{
   score1++;
x = y = 80;
ballTime.Reset();
direc = UpLeft;
ballSpeed = 0.03;
}
else if (y <= 3)
{
   direc = DownRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = UpLeft;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y--;
x++;
   ballTime.Reset();
}

return;
 }
 
 if (direc == DownRight) // Ball traveling down and to the right?
 {
    if (x >= 192)
{
       score1++;
   x = y = 80;
   ballTime.Reset();
   direc = UpLeft;
ballSpeed = 0.03;
}
    else if (y >= 158)
{
   direc = UpRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = DownLeft;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y++;
x++;
ballTime.Reset();
}

return;
 }
 
 if (direc == UpLeft) // Ball traveling up and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
ballSpeed = 0.03;
}
else if (y <= 3)
{
   direc = DownLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = UpRight;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   x--;
y--;
ballTime.Reset();
}

return;
 }
 
 if (direc == DownLeft) // Ball traveling down and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
ballSpeed = 0.03;
}
else if (y >= 158)
{
   direc = UpLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = DownRight;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y++;
x--;
ballTime.Reset();
}

return;
 }
 
 else
    return;
   }
}

// Draw the number of the score for either player
void drawScore(sf::RenderWindow &myApp, int &score, int x, int y)
{
   switch (score)
   {
      case 0:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 1:
    myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 2:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
break;
 case 3:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 4:
    myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 5:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y + 4, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
break;
 case 6:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y + 4, x + 5, y + 8, 1, sf::Color::White));
break;
 case 7:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 8:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 9:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
}
}

// 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;
 }
   }
}


Perhaps one of you awesome people can figure out what I must have done wrong..... I've tried to avoid infinite loops as best I can (which usually causes this problem for me), but I may have missed something. All the images and the .wav file are in the right directory (where the program target is). All of the frameworks are linked properly, as well. As always, any help is greatly appreciated and will further my quest to game program and lead me to post more interesting game example questions than Pong in this forum to spice it up ;] Haha, thanks everybody.

Colton

6
Audio / SFML and 8/16-Bit Music?
« on: September 21, 2010, 09:59:01 pm »
Hello, everybody :]

Now that I've gotten SFML's audio abilities to work, I'm somewhat at a loss as to how I can get started making and using my own 8-bit and 16-bit music for games I will make in the future. Is it possible to use that style of music in SFML? I'm assuming I would need midi or some other format. I can imagine how to get it working with .wav and other types of standard audio formats, but those aren't going for the space-saving and programmability that I would like to be using. Essentially, I suppose you could say I'd like to have a programmable sort of music in my games, perhaps using just plain source code, which I've read is how it used to be done, since there was only so much space on game media formats in the past.

Any links, advice, tips, or help of any kind would be greatly appreciated. :] Thank you in advance.

Colton

7
Audio / Audio Doesn't Seem to be Linking?
« on: September 21, 2010, 09:21:15 am »
Hello, everybody.

I'm trying to incorporate the use of the SFML audio package in a little testing application I've put together. Here's the code for the actual program:

Code: [Select]

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

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

sf::SoundBuffer spitBuffer;
spitBuffer.LoadFromFile("Memo.wav");

sf::Sound spit(spitBuffer);
float pitchCount = 1;

    // 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();
        }

        // Clear screen
        App.Clear();
pitchCount += .01;

spit.SetPitch(pitchCount);

spit.Play();

        // Draw apredefined shape
        App.Draw(sf::Shape::Circle(200, 200, 100, sf::Color::Yellow, 10, sf::Color::Blue));

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

    return EXIT_SUCCESS;
}


And here's what I get from my IDE (Xcode):

Line Location Tool:0: collect2: ld returned 1 exit status
Line Location Tool:0: symbol(s) not found
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::SetPitch(float)", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::SoundBuffer::SoundBuffer()", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::Sound(sf::SoundBuffer const&, bool, float, float, sf::Vector3<float> const&)", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::Play()", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::SoundBuffer::~SoundBuffer()", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::SoundBuffer::LoadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::~Sound()", referenced from:

No idea exactly what this means, but I'm assuming it has to do with a linking problem. However, there are no errors with the rest of the code that has to do with the SFML library; in fact, without the Audio package functions and whatnot, the program will run fine and render the circle included in the program. I made sure the .wav file used in the program is also in the right place and everything. I would greatly appreciate some help on how to fix this problem :] I am running Mac OS 10.5.

Thanks in advance!

Colton[/code]

8
Window / Set Background Color Mac OS X
« on: September 08, 2010, 05:31:01 pm »
Hello, everybody. I'm trying to make the background color of my render window transparent, so I tried to use the sf::RenderWindow::SetBackgroundColor function; however, it doesn't appear that the function exists with my documentation and build of SFML (1.6), even though it's on the online reference. Is this function exclusive to a build of SFML after 1.6, or is there something I'm missing? I would appreciate some help :] Thanks in advance.

Colton

9
SFML projects / My First Game
« on: May 09, 2010, 12:26:44 pm »
Hey, everybody. :] Since I'm new at making games and also new with using SFML, I thought I'd share my first (well, second...) game that I've made using it. (The first game could hardly be called a game. It was just a little "game" where you shoot a devil sprite that follows you around. That project was more of an experiment with different techniques that just evolved into a crappy little program eventually. :p

But I made Pong, at least a watered-down version of it. Here's the source, if anyone wants to compile it and have a mess-around with it:

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>

// Function prototypes
int distance(int, int, int, int);
void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&);
void calculateBall(int&, int&, sf::Clock&, int&, int&, int&);

// ENUMS
   enum BallDirection // Different directions/velocities
   {
      UpRight, DownRight, UpLeft, DownLeft
   };
   
   enum PaddleDirection // Different directions/velocities
   {
      Up, Down, Still
   };

// ************ //

// Paddle structure declaration
struct Paddle
{
   int x, y; // Paddle coordinates, upper left
   int botx, boty; // Paddle coordinates, bottom right
   int direction; // Paddle going up or down?
   sf::Clock PaddleTimer; // Movement timer
   
   Paddle(int xcoord, int ycoord, int bottomx, int bottomy, PaddleDirection direc) // Constructor
   {
      x = xcoord;
 y = ycoord;
 botx = bottomx;
 boty = bottomy;
 direction = direc;
   }
};

// Ball structure declaration
struct Ball
{
   int x, y; // Ball's position in the field
   int size; // Ball's size
   int direction; // Ball's current direction/velocity
   double speed; // Speed (less is more)
   sf::Clock BallTimer; // Movement timer
   
   Ball(int xcoord, int ycoord, int ballSize, double ballSpeed = 0.7)
   {
      x = xcoord;
 y = ycoord;
 size = ballSize;
   }
};

// 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();

   // Player and ball declarations
   // **PLAYER 1**
   Paddle Player1(5, 60, 7, 70, Still);
   
   // **PLAYER 2**
   Paddle Player2(184, 60, 186, 70, Still);
   
   // **BALL**
   Ball Ball(80, 80, 2);

int main()
{
   // Score variable
   
   int score1 = 0, score2 = 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();
 }
 
 // Game loop activities
 
 // Process input
 getInput(Player1.y, Player1.boty, Player2.y, Player2.boty, Player1.PaddleTimer, Player2.PaddleTimer);
 
 // Calculate ball
 calculateBall(Ball.x, Ball.y, Ball.BallTimer, Ball.direction, score1, score2);
 
 // Clear previous screen
 App.Clear();
 
 // Draw the paddles and the ball
 App.Draw(sf::Shape::Rectangle(Player1.x, Player1.y, Player1.botx, Player1.boty, sf::Color::White));
 App.Draw(sf::Shape::Rectangle(Player2.x, Player2.y, Player2.botx, Player2.boty, sf::Color::White));
 App.Draw(sf::Shape::Circle(Ball.x, Ball.y, Ball.size, sf::Color::Blue));
 
 // Set the View
 App.SetView(View);
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
} // end main

// Functions and their declarations

// Distance formula
int distance(int x1, int y1, int x2, int y2)
{
   int temp = pow((x2 - x1), 2) + pow((y2 - y1), 2);
   return sqrt(temp);
}

// Process inputs and move players accordingly
void getInput(int &y1, int &boty1, int &y2, int &boty2, sf::Clock &Pad1, sf::Clock &Pad2)
{
   App.GetInput();
   
   if ((Input.IsKeyDown(sf::Key::Up)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 > 0)
      {
    y1--;
    boty1--;
 }
 Pad1.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::Down)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 < 150)
 {
         y1++;
    boty1++;
 }
 Pad1.Reset();
   }
   
   if ((Input.IsKeyDown(sf::Key::Q)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 > 0)
 {
         y2--;
    boty2--;
 }
 Pad2.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::A)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 < 150)
 {
         y2++;
    boty2++;
 }
 Pad2.Reset();
   }
}

// Calculate ball and its movement
void calculateBall(int &x, int &y, sf::Clock& ballTime, int &direc, int &score1, int &score2)
{
   if (ballTime.GetElapsedTime() >= 0.03)
   {
      if (direc == UpRight) // Ball traveling up and to the right?
 {
    if (x >= 192)
{
   score1++;
x = y = 80;
ballTime.Reset();
direc = UpLeft;
}
else if (y <= 3)
{
   direc = DownRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = UpLeft;
ballTime.Reset();
}
else
{
   y--;
x++;
   ballTime.Reset();
}

return;
 }
 
 if (direc == DownRight) // Ball traveling down and to the right?
 {
    if (x >= 192)
{
       score1++;
   x = y = 80;
   ballTime.Reset();
   direc = UpLeft;
}
    else if (y >= 158)
{
   direc = UpRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = DownLeft;
ballTime.Reset();
}
else
{
   y++;
x++;
ballTime.Reset();
}

return;
 }
 
 if (direc == UpLeft) // Ball traveling up and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
}
else if (y <= 3)
{
   direc = DownLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = UpRight;
ballTime.Reset();
}
else
{
   x--;
y--;
ballTime.Reset();
}

return;
 }
 
 if (direc == DownLeft) // Ball traveling down and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
}
else if (y >= 158)
{
   direc = UpLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = DownRight;
ballTime.Reset();
}
else
{
   y++;
x--;
ballTime.Reset();
}

return;
 }
 
 else
    return;
   }
}


Any critiques of my code would be appreciated. I'm just now getting into classes and objects so I was more comfortable using structures to bundle all the data together. I'm fairly new at C++, so I expect I have much to learn. One of the things I really want to learn is how to make my code as efficient and memory-conserving as possible.

Appreciate the read, guys, and thanks for making such a great library, Laurent! :]

Colton

10
Graphics / Graphics/Window Scaling
« on: May 03, 2010, 01:50:20 pm »
Hello, everybody :]

I have a question. I'd like to make little games with SFML as I start off which look like Atari and NES games of old. The only problem is that resolutions these days are much higher than those ancient resolutions, and as such it's hard to get the games to look as if they're from that era with so many pixels to operate on.

Is there a way I can work with the correct-resolutioned buffer behind the scenes (Atari, I believe, is 192 x 160) and then scale the final display image to something four times that size that I can play on my computer? I understand that if I play with 192 x 160 unscaled, it'll be tiny and virtually unplayable. There was some way this could be done with SDL, I believe, but I don't remember how it was done and how it would translate over to SFML.

I hope my question doesn't make me sound mentally incompetent, but I'm just beginning to get into games programming and there is much, much, much that I do not know and would like to learn from you kind people. :] Thank you very much for your time.

Colton

11
Graphics / Multiple Key Inputs
« on: May 01, 2010, 09:35:50 pm »
Hello, everybody :]

I'm trying to get used to 2D game programming using the SFML library. My latest little tester program is just a skeleton at this point to enable one to shoot a little dot in four directions, depending on the last direction they moved in was.

I've noticed that when I move, I can only move in one direction at a time and it will also lock up sometimes if I press more than one key. I would like to know how I can change my code (or what I can add to it) to enable me to move in more than one direction and also to be able to move and fire my bullet at the same time. Below is the code for the part of my program that accepts input for the player structure:

Code: [Select]

void getInput(int &x, int &y, bool &shot, int &timer, int &direc)
{
   App.GetEvent(Event);
   
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up))
   {
      y--;
 if (!shot)
    direc = 1;
   }
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Right))
   {
      x++;
 if (!shot)
    direc = 2;
   }
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Left))
   {
      x--;
 if (!shot)
    direc = 4;
   }
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down))
   {
      y++;
 if (!shot)
    direc = 3;
   }
   
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space))
   {
      if (timer <= 0)
 {
         shot = true;
timer = 500;
 }
   }
}


I would greatly appreciate any help in figuring out how to fix this. Thank you very much.

Colton

12
General / SFML from Command Line Mac OS X
« on: October 02, 2009, 09:42:52 am »
Hello, everybody. I tried getting SFML to work on my Macbook with OS 10.5 running, however it would not work with XCode for reasons that Ceylo explained had to be related to me not installing the code properly. I was wondering if anyone could explain to me how I could compile a .cpp file using SFML from the Command Line. I know how to compile straight C++ code like this:

c++ sfmltest1.cpp -o sfmltest

I tried making a program with Allegro and there was something I had to add at the end after that to link it with the library (forgot what it was, though). Anyways, I would appreciate help in this very much. :]

Colton

13
General / Mac OS X 10.5 Executable Problem
« on: September 29, 2009, 08:59:06 am »
Hello, everybody. I just discovered SFML the other day and decided to set it up on my Macbook, which is running OS X 10.5. I am using XCode 3 to create the program, and I followed all of the instructions on the tutorials page as far as setting up frameworks and the like. I tried to build the example in the threads tutorial on the website, the first one shown, as a Command Line Utility. It says that it built successfully; however, once I try to Build and Go, it says that there's no executable found at path /Users/coltonogden/testapp/build/Release/testapp. I did a check on it, and I found that there was indeed no folder called Release where it should have been located.

Does anyone know how I can fix this problem, or whether there's something I haven't done or have done incorrectly? I would greatly appreciate the help. :]

Colton

Pages: [1]
anything