Changed internal naming convention (local variables now start with a lower case character)
Removed the AudioResource class git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1166 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
7cc00085d8
commit
45b150648d
245 changed files with 7865 additions and 8065 deletions
|
@ -15,10 +15,10 @@
|
|||
/// \param Window : Target window to initialize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Initialize(sf::Window& Window)
|
||||
void Initialize(sf::Window& window)
|
||||
{
|
||||
// Activate the window
|
||||
Window.SetActive();
|
||||
window.SetActive();
|
||||
|
||||
// Setup OpenGL states
|
||||
// Set color and depth clear value
|
||||
|
@ -43,10 +43,10 @@ void Initialize(sf::Window& Window)
|
|||
/// \param ElapsedTime : Time elapsed since the last draw
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Draw(sf::Window& Window, float ElapsedTime)
|
||||
void Draw(sf::Window& window, float elapsedTime)
|
||||
{
|
||||
// Activate the window
|
||||
Window.SetActive();
|
||||
window.SetActive();
|
||||
|
||||
// Clear color and depth buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -55,9 +55,9 @@ void Draw(sf::Window& Window, float ElapsedTime)
|
|||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.f, 0.f, -200.f);
|
||||
glRotatef(ElapsedTime * 50, 1.f, 0.f, 0.f);
|
||||
glRotatef(ElapsedTime * 30, 0.f, 1.f, 0.f);
|
||||
glRotatef(ElapsedTime * 90, 0.f, 0.f, 1.f);
|
||||
glRotatef(elapsedTime * 50, 1.f, 0.f, 0.f);
|
||||
glRotatef(elapsedTime * 30, 0.f, 1.f, 0.f);
|
||||
glRotatef(elapsedTime * 90, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw a cube
|
||||
glBegin(GL_QUADS);
|
||||
|
@ -111,81 +111,81 @@ void Draw(sf::Window& Window, float ElapsedTime)
|
|||
int main()
|
||||
{
|
||||
// Open a connection with the X server
|
||||
Display* Disp = XOpenDisplay(NULL);
|
||||
if (!Disp)
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
if (!display)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Get the default screen
|
||||
int Screen = DefaultScreen(Disp);
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
// Let's create the main window
|
||||
XSetWindowAttributes Attributes;
|
||||
Attributes.background_pixel = BlackPixel(Disp, Screen);
|
||||
Attributes.event_mask = KeyPressMask;
|
||||
Window Win = XCreateWindow(Disp, RootWindow(Disp, Screen),
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.background_pixel = BlackPixel(display, screen);
|
||||
attributes.event_mask = KeyPressMask;
|
||||
Window window = XCreateWindow(Disp, RootWindow(display, screen),
|
||||
0, 0, 650, 330, 0,
|
||||
DefaultDepth(Disp, Screen),
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(Disp, Screen),
|
||||
CWBackPixel | CWEventMask, &Attributes);
|
||||
if (!Win)
|
||||
DefaultVisual(display, screen),
|
||||
CWBackPixel | CWEventMask, &attributes);
|
||||
if (!window)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Set the window's name
|
||||
XStoreName(Disp, Win, "SFML Window");
|
||||
XStoreName(display, window , "SFML Window");
|
||||
|
||||
// Let's create the windows which will serve as containers for our SFML views
|
||||
Window View1 = XCreateWindow(Disp, Win,
|
||||
Window view1 = XCreateWindow(display, window,
|
||||
10, 10, 310, 310, 0,
|
||||
DefaultDepth(Disp, Screen),
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(Disp, Screen),
|
||||
DefaultVisual(display, screen),
|
||||
0, NULL);
|
||||
Window View2 = XCreateWindow(Disp, Win,
|
||||
Window view2 = XCreateWindow(display, window,
|
||||
330, 10, 310, 310, 0,
|
||||
DefaultDepth(Disp, Screen),
|
||||
DefaultDepth(display, screen),
|
||||
InputOutput,
|
||||
DefaultVisual(Disp, Screen),
|
||||
DefaultVisual(display, screen),
|
||||
0, NULL);
|
||||
|
||||
// Show our windows
|
||||
XMapWindow(Disp, Win);
|
||||
XFlush(Disp);
|
||||
XMapWindow(display, window);
|
||||
XFlush(display);
|
||||
|
||||
// Create our SFML views
|
||||
sf::Window SFMLView1(View1);
|
||||
sf::Window SFMLView2(View2);
|
||||
sf::Window SFMLView1(view1);
|
||||
sf::Window SFMLView2(view2);
|
||||
|
||||
// Create a clock for measuring elapsed time
|
||||
sf::Clock Clock;
|
||||
sf::Clock clock;
|
||||
|
||||
// Initialize our views
|
||||
Initialize(SFMLView1);
|
||||
Initialize(SFMLView2);
|
||||
|
||||
// Start the event loop
|
||||
bool IsRunning = true;
|
||||
while (IsRunning)
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
while (XPending(Disp))
|
||||
while (XPending(display))
|
||||
{
|
||||
// Get the next pending event
|
||||
XEvent Event;
|
||||
XNextEvent(Disp, &Event);
|
||||
XEvent event;
|
||||
XNextEvent(display, &event);
|
||||
|
||||
// Process it
|
||||
switch (Event.type)
|
||||
switch (event.type)
|
||||
{
|
||||
// Any key is pressed : quit
|
||||
case KeyPress :
|
||||
IsRunning = false;
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw something into our views
|
||||
Draw(SFMLView1, Clock.GetElapsedTime());
|
||||
Draw(SFMLView2, Clock.GetElapsedTime() * 0.3f);
|
||||
Draw(SFMLView1, clock.GetElapsedTime());
|
||||
Draw(SFMLView2, clock.GetElapsedTime() * 0.3f);
|
||||
|
||||
// Display the views on screen
|
||||
SFMLView1.Display();
|
||||
|
@ -193,7 +193,7 @@ int main()
|
|||
}
|
||||
|
||||
// Close the display
|
||||
XCloseDisplay(Disp);
|
||||
XCloseDisplay(display);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
/// Print a FTP response into a standard output stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::ostream& operator <<(std::ostream& Stream, const sf::Ftp::Response& Response)
|
||||
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response)
|
||||
{
|
||||
return Stream << Response.GetStatus() << Response.GetMessage();
|
||||
return stream << response.GetStatus() << response.GetMessage();
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,36 +26,36 @@ std::ostream& operator <<(std::ostream& Stream, const sf::Ftp::Response& Respons
|
|||
int main()
|
||||
{
|
||||
// Choose the server address
|
||||
sf::IPAddress Address;
|
||||
sf::IPAddress address;
|
||||
do
|
||||
{
|
||||
std::cout << "Enter the FTP server address : ";
|
||||
std::cin >> Address;
|
||||
std::cin >> address;
|
||||
}
|
||||
while (!Address.IsValid());
|
||||
while (!address.IsValid());
|
||||
|
||||
// Connect to the server
|
||||
sf::Ftp Server;
|
||||
sf::Ftp::Response ConnectResponse = Server.Connect(Address);
|
||||
std::cout << ConnectResponse << std::endl;
|
||||
if (!ConnectResponse.IsOk())
|
||||
sf::Ftp server;
|
||||
sf::Ftp::Response connectResponse = server.Connect(address);
|
||||
std::cout << connectResponse << std::endl;
|
||||
if (!connectResponse.IsOk())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Ask for user name and password
|
||||
std::string UserName, Password;
|
||||
std::string user, password;
|
||||
std::cout << "User name : ";
|
||||
std::cin >> UserName;
|
||||
std::cin >> user;
|
||||
std::cout << "Password : ";
|
||||
std::cin >> Password;
|
||||
std::cin >> password;
|
||||
|
||||
// Login to the server
|
||||
sf::Ftp::Response LoginResponse = Server.Login(UserName, Password);
|
||||
std::cout << LoginResponse << std::endl;
|
||||
if (!LoginResponse.IsOk())
|
||||
sf::Ftp::Response loginResponse = server.Login(user, password);
|
||||
std::cout << loginResponse << std::endl;
|
||||
if (!loginResponse.IsOk())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Main menu
|
||||
int Choice = 0;
|
||||
int choice = 0;
|
||||
do
|
||||
{
|
||||
// Main FTP menu
|
||||
|
@ -74,10 +74,10 @@ int main()
|
|||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Your choice: ";
|
||||
std::cin >> Choice;
|
||||
std::cin >> choice;
|
||||
std::cout << std::endl;
|
||||
|
||||
switch (Choice)
|
||||
switch (choice)
|
||||
{
|
||||
default :
|
||||
{
|
||||
|
@ -91,95 +91,95 @@ int main()
|
|||
case 1 :
|
||||
{
|
||||
// Print current server directory
|
||||
sf::Ftp::DirectoryResponse Response = Server.GetWorkingDirectory();
|
||||
std::cout << Response << std::endl;
|
||||
std::cout << "Current directory is " << Response.GetDirectory() << std::endl;
|
||||
sf::Ftp::DirectoryResponse response = server.GetWorkingDirectory();
|
||||
std::cout << response << std::endl;
|
||||
std::cout << "Current directory is " << response.GetDirectory() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2 :
|
||||
{
|
||||
// Print content of current server directory
|
||||
sf::Ftp::ListingResponse Response = Server.GetDirectoryListing();
|
||||
std::cout << Response << std::endl;
|
||||
for (std::size_t i = 0; i < Response.GetCount(); ++i)
|
||||
std::cout << Response.GetFilename(i) << std::endl;
|
||||
sf::Ftp::ListingResponse response = server.GetDirectoryListing();
|
||||
std::cout << response << std::endl;
|
||||
for (std::size_t i = 0; i < response.GetCount(); ++i)
|
||||
std::cout << response.GetFilename(i) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 3 :
|
||||
{
|
||||
// Change the current directory
|
||||
std::string Directory;
|
||||
std::string directory;
|
||||
std::cout << "Choose a directory: ";
|
||||
std::cin >> Directory;
|
||||
std::cout << Server.ChangeDirectory(Directory) << std::endl;
|
||||
std::cin >> directory;
|
||||
std::cout << server.ChangeDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4 :
|
||||
{
|
||||
// Create a new directory
|
||||
std::string Directory;
|
||||
std::string directory;
|
||||
std::cout << "Name of the directory to create: ";
|
||||
std::cin >> Directory;
|
||||
std::cout << Server.MakeDirectory(Directory) << std::endl;
|
||||
std::cin >> directory;
|
||||
std::cout << server.MakeDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5 :
|
||||
{
|
||||
// Remove an existing directory
|
||||
std::string Directory;
|
||||
std::string directory;
|
||||
std::cout << "Name of the directory to remove: ";
|
||||
std::cin >> Directory;
|
||||
std::cout << Server.DeleteDirectory(Directory) << std::endl;
|
||||
std::cin >> directory;
|
||||
std::cout << server.DeleteDirectory(directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 6 :
|
||||
{
|
||||
// Rename a file
|
||||
std::string SrcFilename, DstFilename;
|
||||
std::string source, destination;
|
||||
std::cout << "Name of the file to rename: ";
|
||||
std::cin >> SrcFilename;
|
||||
std::cin >> source;
|
||||
std::cout << "New name: ";
|
||||
std::cin >> DstFilename;
|
||||
std::cout << Server.RenameFile(SrcFilename, DstFilename) << std::endl;
|
||||
std::cin >> destination;
|
||||
std::cout << server.RenameFile(source, destination) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7 :
|
||||
{
|
||||
// Remove an existing directory
|
||||
std::string Filename;
|
||||
std::string filename;
|
||||
std::cout << "Name of the file to remove: ";
|
||||
std::cin >> Filename;
|
||||
std::cout << Server.DeleteFile(Filename) << std::endl;
|
||||
std::cin >> filename;
|
||||
std::cout << server.DeleteFile(filename) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 8 :
|
||||
{
|
||||
// Download a file from server
|
||||
std::string Filename, Directory;
|
||||
std::cout << "Path of the file to download (relative to current directory): ";
|
||||
std::cin >> Filename;
|
||||
std::string filename, directory;
|
||||
std::cout << "filename of the file to download (relative to current directory): ";
|
||||
std::cin >> filename;
|
||||
std::cout << "Directory to download the file to: ";
|
||||
std::cin >> Directory;
|
||||
std::cout << Server.Download(Filename, Directory) << std::endl;
|
||||
std::cin >> directory;
|
||||
std::cout << server.Download(filename, directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 9 :
|
||||
{
|
||||
// Upload a file to server
|
||||
std::string Filename, Directory;
|
||||
std::string filename, directory;
|
||||
std::cout << "Path of the file to upload (absolute or relative to working directory): ";
|
||||
std::cin >> Filename;
|
||||
std::cin >> filename;
|
||||
std::cout << "Directory to upload the file to (relative to current directory): ";
|
||||
std::cin >> Directory;
|
||||
std::cout << Server.Upload(Filename, Directory) << std::endl;
|
||||
std::cin >> directory;
|
||||
std::cout << server.Upload(filename, directory) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -190,11 +190,11 @@ int main()
|
|||
}
|
||||
}
|
||||
|
||||
} while (Choice != 0);
|
||||
} while (choice != 0);
|
||||
|
||||
// Disconnect from the server
|
||||
std::cout << "Disconnecting from server..." << std::endl;
|
||||
std::cout << Server.Disconnect() << std::endl;
|
||||
std::cout << server.Disconnect() << std::endl;
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
|
|
|
@ -16,26 +16,26 @@
|
|||
int main()
|
||||
{
|
||||
// Create main window
|
||||
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL");
|
||||
App.PreserveOpenGLStates(true);
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
|
||||
window.PreserveOpenGLStates(true);
|
||||
|
||||
// Create a sprite for the background
|
||||
sf::Image BackgroundImage;
|
||||
if (!BackgroundImage.LoadFromFile("datas/opengl/background.jpg"))
|
||||
sf::Image backgroundImage;
|
||||
if (!backgroundImage.LoadFromFile("datas/opengl/background.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite Background(BackgroundImage);
|
||||
sf::Sprite background(backgroundImage);
|
||||
|
||||
// Load an OpenGL texture.
|
||||
// We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
|
||||
// but here we want more control on it (generate mipmaps, ...) so we create a new one from the image pixels
|
||||
GLuint Texture = 0;
|
||||
GLuint texture = 0;
|
||||
{
|
||||
sf::Image Image;
|
||||
if (!Image.LoadFromFile("datas/opengl/texture.jpg"))
|
||||
sf::Image image;
|
||||
if (!image.LoadFromFile("datas/opengl/texture.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
@ -52,98 +52,98 @@ int main()
|
|||
|
||||
// Bind our texture
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, Texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
// Create a clock for measuring the time elapsed
|
||||
sf::Clock Clock;
|
||||
sf::Clock clock;
|
||||
|
||||
// Start game loop
|
||||
while (App.IsOpened())
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
sf::Event Event;
|
||||
while (App.GetEvent(Event))
|
||||
sf::Event event;
|
||||
while (window.GetEvent(event))
|
||||
{
|
||||
// Close window : exit
|
||||
if (Event.Type == sf::Event::Closed)
|
||||
App.Close();
|
||||
if (event.Type == sf::Event::Closed)
|
||||
window.Close();
|
||||
|
||||
// Escape key : exit
|
||||
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
|
||||
App.Close();
|
||||
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
|
||||
window.Close();
|
||||
|
||||
// Adjust the viewport when the window is resized
|
||||
if (Event.Type == sf::Event::Resized)
|
||||
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
|
||||
if (event.Type == sf::Event::Resized)
|
||||
glViewport(0, 0, event.Size.Width, event.Size.Height);
|
||||
}
|
||||
|
||||
// Draw background
|
||||
App.Draw(Background);
|
||||
window.Draw(background);
|
||||
|
||||
// Clear depth buffer
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// We get the position of the mouse cursor, so that we can move the box accordingly
|
||||
float CursorX = App.GetInput().GetMouseX() * 200.f / App.GetWidth() - 100.f;
|
||||
float CursorY = -App.GetInput().GetMouseY() * 200.f / App.GetHeight() + 100.f;
|
||||
float x = window.GetInput().GetMouseX() * 200.f / window.GetWidth() - 100.f;
|
||||
float y = -window.GetInput().GetMouseY() * 200.f / window.GetHeight() + 100.f;
|
||||
|
||||
// Apply some transformations
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(CursorX, CursorY, -100.f);
|
||||
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
|
||||
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
|
||||
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
|
||||
glTranslatef(x, y, -100.f);
|
||||
glRotatef(clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
|
||||
glRotatef(clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
|
||||
glRotatef(clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw a cube
|
||||
float Size = 20.f;
|
||||
float size = 20.f;
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(0, 0); glVertex3f(-Size, -Size, -Size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-Size, Size, -Size);
|
||||
glTexCoord2f(1, 1); glVertex3f( Size, Size, -Size);
|
||||
glTexCoord2f(1, 0); glVertex3f( Size, -Size, -Size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
|
||||
glTexCoord2f(1, 1); glVertex3f( size, size, -size);
|
||||
glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
|
||||
|
||||
glTexCoord2f(0, 0); glVertex3f(-Size, -Size, Size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-Size, Size, Size);
|
||||
glTexCoord2f(1, 1); glVertex3f( Size, Size, Size);
|
||||
glTexCoord2f(1, 0); glVertex3f( Size, -Size, Size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-size, size, size);
|
||||
glTexCoord2f(1, 1); glVertex3f( size, size, size);
|
||||
glTexCoord2f(1, 0); glVertex3f( size, -size, size);
|
||||
|
||||
glTexCoord2f(0, 0); glVertex3f(-Size, -Size, -Size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-Size, Size, -Size);
|
||||
glTexCoord2f(1, 1); glVertex3f(-Size, Size, Size);
|
||||
glTexCoord2f(1, 0); glVertex3f(-Size, -Size, Size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
|
||||
glTexCoord2f(1, 1); glVertex3f(-size, size, size);
|
||||
glTexCoord2f(1, 0); glVertex3f(-size, -size, size);
|
||||
|
||||
glTexCoord2f(0, 0); glVertex3f(Size, -Size, -Size);
|
||||
glTexCoord2f(0, 1); glVertex3f(Size, Size, -Size);
|
||||
glTexCoord2f(1, 1); glVertex3f(Size, Size, Size);
|
||||
glTexCoord2f(1, 0); glVertex3f(Size, -Size, Size);
|
||||
glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
|
||||
glTexCoord2f(0, 1); glVertex3f(size, size, -size);
|
||||
glTexCoord2f(1, 1); glVertex3f(size, size, size);
|
||||
glTexCoord2f(1, 0); glVertex3f(size, -size, size);
|
||||
|
||||
glTexCoord2f(0, 1); glVertex3f(-Size, -Size, Size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-Size, -Size, -Size);
|
||||
glTexCoord2f(1, 0); glVertex3f( Size, -Size, -Size);
|
||||
glTexCoord2f(1, 1); glVertex3f( Size, -Size, Size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-size, -size, size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
|
||||
glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
|
||||
glTexCoord2f(1, 1); glVertex3f( size, -size, size);
|
||||
|
||||
glTexCoord2f(0, 1); glVertex3f(-Size, Size, Size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-Size, Size, -Size);
|
||||
glTexCoord2f(1, 0); glVertex3f( Size, Size, -Size);
|
||||
glTexCoord2f(1, 1); glVertex3f( Size, Size, Size);
|
||||
glTexCoord2f(0, 1); glVertex3f(-size, size, size);
|
||||
glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
|
||||
glTexCoord2f(1, 0); glVertex3f( size, size, -size);
|
||||
glTexCoord2f(1, 1); glVertex3f( size, size, size);
|
||||
|
||||
glEnd();
|
||||
|
||||
// Draw some text on top of our OpenGL object
|
||||
sf::String Text("SFML / OpenGL demo");
|
||||
Text.SetPosition(250.f, 450.f);
|
||||
Text.SetColor(sf::Color(255, 255, 255, 170));
|
||||
App.Draw(Text);
|
||||
sf::String text("SFML / OpenGL demo");
|
||||
text.SetPosition(250.f, 450.f);
|
||||
text.SetColor(sf::Color(255, 255, 255, 170));
|
||||
window.Draw(text);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
|
||||
// Don't forget to destroy our texture
|
||||
glDeleteTextures(1, &Texture);
|
||||
glDeleteTextures(1, &texture);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -19,171 +19,171 @@ int main()
|
|||
const float PI = 3.14159f;
|
||||
|
||||
// Create the window of the application
|
||||
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Pong");
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "SFML Pong");
|
||||
|
||||
// Load the sounds used in the game
|
||||
sf::SoundBuffer BallSoundBuffer;
|
||||
if (!BallSoundBuffer.LoadFromFile("datas/pong/ball.wav"))
|
||||
sf::SoundBuffer ballSoundBuffer;
|
||||
if (!ballSoundBuffer.LoadFromFile("datas/pong/ball.wav"))
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
sf::Sound BallSound(BallSoundBuffer);
|
||||
sf::Sound ballSound(ballSoundBuffer);
|
||||
|
||||
// Load the images used in the game
|
||||
sf::Image BackgroundImage, LeftPaddleImage, RightPaddleImage, BallImage;
|
||||
if (!BackgroundImage.LoadFromFile("datas/pong/background.jpg") ||
|
||||
!LeftPaddleImage.LoadFromFile("datas/pong/paddle_left.png") ||
|
||||
!RightPaddleImage.LoadFromFile("datas/pong/paddle_right.png") ||
|
||||
!BallImage.LoadFromFile("datas/pong/ball.png"))
|
||||
sf::Image backgroundImage, leftPaddleImage, rightPaddleImage, ballImage;
|
||||
if (!backgroundImage.LoadFromFile("datas/pong/background.jpg") ||
|
||||
!leftPaddleImage.LoadFromFile("datas/pong/paddle_left.png") ||
|
||||
!rightPaddleImage.LoadFromFile("datas/pong/paddle_right.png") ||
|
||||
!ballImage.LoadFromFile("datas/pong/ball.png"))
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Load the text font
|
||||
sf::Font Cheeseburger;
|
||||
if (!Cheeseburger.LoadFromFile("datas/post-fx/cheeseburger.ttf"))
|
||||
sf::Font font;
|
||||
if (!ballImage.LoadFromFile("datas/post-fx/cheeseburger.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Initialize the end text
|
||||
sf::String End;
|
||||
End.SetFont(Cheeseburger);
|
||||
End.SetSize(60.f);
|
||||
End.Move(150.f, 200.f);
|
||||
End.SetColor(sf::Color(50, 50, 250));
|
||||
sf::String end;
|
||||
end.SetFont(font);
|
||||
end.SetSize(60.f);
|
||||
end.Move(150.f, 200.f);
|
||||
end.SetColor(sf::Color(50, 50, 250));
|
||||
|
||||
// Create the sprites of the background, the paddles and the ball
|
||||
sf::Sprite Background(BackgroundImage);
|
||||
sf::Sprite LeftPaddle(LeftPaddleImage);
|
||||
sf::Sprite RightPaddle(RightPaddleImage);
|
||||
sf::Sprite Ball(BallImage);
|
||||
sf::Sprite background(backgroundImage);
|
||||
sf::Sprite leftPaddle(leftPaddleImage);
|
||||
sf::Sprite rightPaddle(rightPaddleImage);
|
||||
sf::Sprite ball(ballImage);
|
||||
|
||||
LeftPaddle.Move(10, (App.GetView().GetSize().y - LeftPaddle.GetSize().y) / 2);
|
||||
RightPaddle.Move(App.GetView().GetSize().x - RightPaddle.GetSize().x - 10, (App.GetView().GetSize().y - RightPaddle.GetSize().y) / 2);
|
||||
Ball.Move((App.GetView().GetSize().x - Ball.GetSize().x) / 2, (App.GetView().GetSize().y - Ball.GetSize().y) / 2);
|
||||
leftPaddle.Move(10, (window.GetView().GetSize().y - leftPaddle.GetSize().y) / 2);
|
||||
rightPaddle.Move(window.GetView().GetSize().x - rightPaddle.GetSize().x - 10, (window.GetView().GetSize().y - rightPaddle.GetSize().y) / 2);
|
||||
ball.Move((window.GetView().GetSize().x - ball.GetSize().x) / 2, (window.GetView().GetSize().y - ball.GetSize().y) / 2);
|
||||
|
||||
// Define the paddles properties
|
||||
sf::Clock AITimer;
|
||||
const float AITime = 0.1f;
|
||||
float LeftPaddleSpeed = 400.f;
|
||||
float RightPaddleSpeed = 400.f;
|
||||
float leftPaddleSpeed = 400.f;
|
||||
float rightPaddleSpeed = 400.f;
|
||||
|
||||
// Define the ball properties
|
||||
float BallSpeed = 400.f;
|
||||
float BallAngle;
|
||||
float ballSpeed = 400.f;
|
||||
float ballAngle;
|
||||
do
|
||||
{
|
||||
// Make sure the ball initial angle is not too much vertical
|
||||
BallAngle = sf::Randomizer::Random(0.f, 2 * PI);
|
||||
} while (std::abs(std::cos(BallAngle)) < 0.7f);
|
||||
ballAngle = sf::Randomizer::Random(0.f, 2 * PI);
|
||||
} while (std::abs(std::cos(ballAngle)) < 0.7f);
|
||||
|
||||
bool IsPlaying = true;
|
||||
while (App.IsOpened())
|
||||
bool isPlaying = true;
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Handle events
|
||||
sf::Event Event;
|
||||
while (App.GetEvent(Event))
|
||||
sf::Event event;
|
||||
while (window.GetEvent(event))
|
||||
{
|
||||
// Window closed or escape key pressed : exit
|
||||
if ((Event.Type == sf::Event::Closed) ||
|
||||
((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
|
||||
if ((event.Type == sf::Event::Closed) ||
|
||||
((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape)))
|
||||
{
|
||||
App.Close();
|
||||
window.Close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsPlaying)
|
||||
if (isPlaying)
|
||||
{
|
||||
// Move the player's paddle
|
||||
if (App.GetInput().IsKeyDown(sf::Key::Up) && (LeftPaddle.GetPosition().y > 5.f))
|
||||
LeftPaddle.Move(0.f, -LeftPaddleSpeed * App.GetFrameTime());
|
||||
if (App.GetInput().IsKeyDown(sf::Key::Down) && (LeftPaddle.GetPosition().y < App.GetView().GetSize().y - LeftPaddle.GetSize().y - 5.f))
|
||||
LeftPaddle.Move(0.f, LeftPaddleSpeed * App.GetFrameTime());
|
||||
if (window.GetInput().IsKeyDown(sf::Key::Up) && (leftPaddle.GetPosition().y > 5.f))
|
||||
leftPaddle.Move(0.f, -leftPaddleSpeed * window.GetFrameTime());
|
||||
if (window.GetInput().IsKeyDown(sf::Key::Down) && (leftPaddle.GetPosition().y < window.GetView().GetSize().y - leftPaddle.GetSize().y - 5.f))
|
||||
leftPaddle.Move(0.f, leftPaddleSpeed * window.GetFrameTime());
|
||||
|
||||
// Move the computer's paddle
|
||||
if (((RightPaddleSpeed < 0.f) && (RightPaddle.GetPosition().y > 5.f)) ||
|
||||
((RightPaddleSpeed > 0.f) && (RightPaddle.GetPosition().y < App.GetView().GetSize().y - RightPaddle.GetSize().y - 5.f)))
|
||||
if (((rightPaddleSpeed < 0.f) && (rightPaddle.GetPosition().y > 5.f)) ||
|
||||
((rightPaddleSpeed > 0.f) && (rightPaddle.GetPosition().y < window.GetView().GetSize().y - rightPaddle.GetSize().y - 5.f)))
|
||||
{
|
||||
RightPaddle.Move(0.f, RightPaddleSpeed * App.GetFrameTime());
|
||||
rightPaddle.Move(0.f, rightPaddleSpeed * window.GetFrameTime());
|
||||
}
|
||||
|
||||
// Update the computer's paddle direction according to the ball position
|
||||
if (AITimer.GetElapsedTime() > AITime)
|
||||
{
|
||||
AITimer.Reset();
|
||||
if ((RightPaddleSpeed < 0) && (Ball.GetPosition().y + Ball.GetSize().y > RightPaddle.GetPosition().y + RightPaddle.GetSize().y))
|
||||
RightPaddleSpeed = -RightPaddleSpeed;
|
||||
if ((RightPaddleSpeed > 0) && (Ball.GetPosition().y < RightPaddle.GetPosition().y))
|
||||
RightPaddleSpeed = -RightPaddleSpeed;
|
||||
if ((rightPaddleSpeed < 0) && (ball.GetPosition().y + ball.GetSize().y > rightPaddle.GetPosition().y + rightPaddle.GetSize().y))
|
||||
rightPaddleSpeed = -rightPaddleSpeed;
|
||||
if ((rightPaddleSpeed > 0) && (ball.GetPosition().y < rightPaddle.GetPosition().y))
|
||||
rightPaddleSpeed = -rightPaddleSpeed;
|
||||
}
|
||||
|
||||
// Move the ball
|
||||
float Factor = BallSpeed * App.GetFrameTime();
|
||||
Ball.Move(std::cos(BallAngle) * Factor, std::sin(BallAngle) * Factor);
|
||||
float factor = ballSpeed * window.GetFrameTime();
|
||||
ball.Move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
|
||||
|
||||
// Check collisions between the ball and the screen
|
||||
if (Ball.GetPosition().x < 0.f)
|
||||
if (ball.GetPosition().x < 0.f)
|
||||
{
|
||||
IsPlaying = false;
|
||||
End.SetText("You lost !\n(press escape to exit)");
|
||||
isPlaying = false;
|
||||
end.SetText("You lost !\n(press escape to exit)");
|
||||
}
|
||||
if (Ball.GetPosition().x + Ball.GetSize().x > App.GetView().GetSize().x)
|
||||
if (ball.GetPosition().x + ball.GetSize().x > window.GetView().GetSize().x)
|
||||
{
|
||||
IsPlaying = false;
|
||||
End.SetText("You won !\n(press escape to exit)");
|
||||
isPlaying = false;
|
||||
end.SetText("You won !\n(press escape to exit)");
|
||||
}
|
||||
if (Ball.GetPosition().y < 0.f)
|
||||
if (ball.GetPosition().y < 0.f)
|
||||
{
|
||||
BallSound.Play();
|
||||
BallAngle = -BallAngle;
|
||||
Ball.SetY(0.1f);
|
||||
ballSound.Play();
|
||||
ballAngle = -ballAngle;
|
||||
ball.SetY(0.1f);
|
||||
}
|
||||
if (Ball.GetPosition().y + Ball.GetSize().y > App.GetView().GetSize().y)
|
||||
if (ball.GetPosition().y + ball.GetSize().y > window.GetView().GetSize().y)
|
||||
{
|
||||
BallSound.Play();
|
||||
BallAngle = -BallAngle;
|
||||
Ball.SetY(App.GetView().GetSize().y - Ball.GetSize().y - 0.1f);
|
||||
ballSound.Play();
|
||||
ballAngle = -ballAngle;
|
||||
ball.SetY(window.GetView().GetSize().y - ball.GetSize().y - 0.1f);
|
||||
}
|
||||
|
||||
// Check the collisions between the ball and the paddles
|
||||
// Left Paddle
|
||||
if (Ball.GetPosition().x < LeftPaddle.GetPosition().x + LeftPaddle.GetSize().x &&
|
||||
Ball.GetPosition().x > LeftPaddle.GetPosition().x + (LeftPaddle.GetSize().x / 2.0f) &&
|
||||
Ball.GetPosition().y + Ball.GetSize().y >= LeftPaddle.GetPosition().y &&
|
||||
Ball.GetPosition().y <= LeftPaddle.GetPosition().y + LeftPaddle.GetSize().y)
|
||||
if (ball.GetPosition().x < leftPaddle.GetPosition().x + leftPaddle.GetSize().x &&
|
||||
ball.GetPosition().x > leftPaddle.GetPosition().x + (leftPaddle.GetSize().x / 2.0f) &&
|
||||
ball.GetPosition().y + ball.GetSize().y >= leftPaddle.GetPosition().y &&
|
||||
ball.GetPosition().y <= leftPaddle.GetPosition().y + leftPaddle.GetSize().y)
|
||||
{
|
||||
BallSound.Play();
|
||||
BallAngle = PI - BallAngle;
|
||||
Ball.SetX(LeftPaddle.GetPosition().x + LeftPaddle.GetSize().x + 0.1f);
|
||||
ballSound.Play();
|
||||
ballAngle = PI - ballAngle;
|
||||
ball.SetX(leftPaddle.GetPosition().x + leftPaddle.GetSize().x + 0.1f);
|
||||
}
|
||||
|
||||
// Right Paddle
|
||||
if (Ball.GetPosition().x + Ball.GetSize().x > RightPaddle.GetPosition().x &&
|
||||
Ball.GetPosition().x + Ball.GetSize().x < RightPaddle.GetPosition().x + (RightPaddle.GetSize().x / 2.0f) &&
|
||||
Ball.GetPosition().y + Ball.GetSize().y >= RightPaddle.GetPosition().y &&
|
||||
Ball.GetPosition().y <= RightPaddle.GetPosition().y + RightPaddle.GetSize().y)
|
||||
if (ball.GetPosition().x + ball.GetSize().x > rightPaddle.GetPosition().x &&
|
||||
ball.GetPosition().x + ball.GetSize().x < rightPaddle.GetPosition().x + (rightPaddle.GetSize().x / 2.0f) &&
|
||||
ball.GetPosition().y + ball.GetSize().y >= rightPaddle.GetPosition().y &&
|
||||
ball.GetPosition().y <= rightPaddle.GetPosition().y + rightPaddle.GetSize().y)
|
||||
{
|
||||
BallSound.Play();
|
||||
BallAngle = PI - BallAngle;
|
||||
Ball.SetX(RightPaddle.GetPosition().x - Ball.GetSize().x - 0.1f);
|
||||
ballSound.Play();
|
||||
ballAngle = PI - ballAngle;
|
||||
ball.SetX(rightPaddle.GetPosition().x - ball.GetSize().x - 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
window.Clear();
|
||||
|
||||
// Draw the background, paddles and ball sprites
|
||||
App.Draw(Background);
|
||||
App.Draw(LeftPaddle);
|
||||
App.Draw(RightPaddle);
|
||||
App.Draw(Ball);
|
||||
window.Draw(background);
|
||||
window.Draw(leftPaddle);
|
||||
window.Draw(rightPaddle);
|
||||
window.Draw(ball);
|
||||
|
||||
// If the game is over, display the end message
|
||||
if (!IsPlaying)
|
||||
App.Draw(End);
|
||||
if (!isPlaying)
|
||||
window.Draw(end);
|
||||
|
||||
// Display things on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -25,136 +25,136 @@ int main()
|
|||
}
|
||||
|
||||
// Create the main window
|
||||
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML PostFX");
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML PostFX");
|
||||
|
||||
// Load a background image to display
|
||||
sf::Image BackgroundImage;
|
||||
if (!BackgroundImage.LoadFromFile("datas/post-fx/background.jpg"))
|
||||
sf::Image backgroundImage;
|
||||
if (!backgroundImage.LoadFromFile("datas/post-fx/background.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite Background(BackgroundImage);
|
||||
sf::Sprite background(backgroundImage);
|
||||
|
||||
// Load a sprite which we'll move into the scene
|
||||
sf::Image EntityImage;
|
||||
if (!EntityImage.LoadFromFile("datas/post-fx/sprite.png"))
|
||||
sf::Image entityImage;
|
||||
if (!entityImage.LoadFromFile("datas/post-fx/sprite.png"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite Entity(EntityImage);
|
||||
sf::Sprite entity(entityImage);
|
||||
|
||||
// Load the text font
|
||||
sf::Font Cheeseburger;
|
||||
if (!Cheeseburger.LoadFromFile("datas/post-fx/cheeseburger.ttf"))
|
||||
sf::Font font;
|
||||
if (!font.LoadFromFile("datas/post-fx/cheeseburger.ttf"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Load the image needed for the wave effect
|
||||
sf::Image WaveImage;
|
||||
if (!WaveImage.LoadFromFile("datas/post-fx/wave.jpg"))
|
||||
sf::Image waveImage;
|
||||
if (!waveImage.LoadFromFile("datas/post-fx/wave.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Load all effects
|
||||
std::map<std::string, sf::PostFX> Effects;
|
||||
if (!Effects["nothing"].LoadFromFile("datas/post-fx/nothing.sfx")) return EXIT_FAILURE;
|
||||
if (!Effects["blur"].LoadFromFile("datas/post-fx/blur.sfx")) return EXIT_FAILURE;
|
||||
if (!Effects["colorize"].LoadFromFile("datas/post-fx/colorize.sfx")) return EXIT_FAILURE;
|
||||
if (!Effects["fisheye"].LoadFromFile("datas/post-fx/fisheye.sfx")) return EXIT_FAILURE;
|
||||
if (!Effects["wave"].LoadFromFile("datas/post-fx/wave.sfx")) return EXIT_FAILURE;
|
||||
if (!Effects["pixelate"].LoadFromFile("datas/post-fx/pixelate.sfx")) return EXIT_FAILURE;
|
||||
std::map<std::string, sf::PostFX>::iterator CurrentEffect = Effects.find("nothing");
|
||||
std::map<std::string, sf::PostFX> effects;
|
||||
if (!effects["nothing"].LoadFromFile("datas/post-fx/nothing.sfx")) return EXIT_FAILURE;
|
||||
if (!effects["blur"].LoadFromFile("datas/post-fx/blur.sfx")) return EXIT_FAILURE;
|
||||
if (!effects["colorize"].LoadFromFile("datas/post-fx/colorize.sfx")) return EXIT_FAILURE;
|
||||
if (!effects["fisheye"].LoadFromFile("datas/post-fx/fisheye.sfx")) return EXIT_FAILURE;
|
||||
if (!effects["wave"].LoadFromFile("datas/post-fx/wave.sfx")) return EXIT_FAILURE;
|
||||
if (!effects["pixelate"].LoadFromFile("datas/post-fx/pixelate.sfx")) return EXIT_FAILURE;
|
||||
std::map<std::string, sf::PostFX>::iterator currentEffect = effects.find("nothing");
|
||||
|
||||
// Do specific initializations
|
||||
Effects["nothing"].SetTexture("framebuffer", NULL);
|
||||
Effects["blur"].SetTexture("framebuffer", NULL);
|
||||
Effects["blur"].SetParameter("offset", 0.f);
|
||||
Effects["colorize"].SetTexture("framebuffer", NULL);
|
||||
Effects["colorize"].SetParameter("color", 1.f, 1.f, 1.f);
|
||||
Effects["fisheye"].SetTexture("framebuffer", NULL);
|
||||
Effects["wave"].SetTexture("framebuffer", NULL);
|
||||
Effects["wave"].SetTexture("wave", &WaveImage);
|
||||
Effects["pixelate"].SetTexture("framebuffer", NULL);
|
||||
effects["nothing"].SetTexture("framebuffer", NULL);
|
||||
effects["blur"].SetTexture("framebuffer", NULL);
|
||||
effects["blur"].SetParameter("offset", 0.f);
|
||||
effects["colorize"].SetTexture("framebuffer", NULL);
|
||||
effects["colorize"].SetParameter("color", 1.f, 1.f, 1.f);
|
||||
effects["fisheye"].SetTexture("framebuffer", NULL);
|
||||
effects["wave"].SetTexture("framebuffer", NULL);
|
||||
effects["wave"].SetTexture("wave", &waveImage);
|
||||
effects["pixelate"].SetTexture("framebuffer", NULL);
|
||||
|
||||
// Define a string for displaying current effect description
|
||||
sf::String CurFXStr;
|
||||
CurFXStr.SetText("Current effect is \"" + CurrentEffect->first + "\"");
|
||||
CurFXStr.SetFont(Cheeseburger);
|
||||
CurFXStr.SetPosition(20.f, 0.f);
|
||||
CurFXStr.SetColor(sf::Color(150, 70, 110));
|
||||
sf::String curFXStr;
|
||||
curFXStr.SetText("Current effect is \"" + currentEffect->first + "\"");
|
||||
curFXStr.SetFont(font);
|
||||
curFXStr.SetPosition(20.f, 0.f);
|
||||
curFXStr.SetColor(sf::Color(150, 70, 110));
|
||||
|
||||
// Define a string for displaying help
|
||||
sf::String InfoStr;
|
||||
InfoStr.SetText("Move your mouse to change the effect parameters\nPress numpad + and - to change effect\nWarning : some effects may not work\ndepending on your graphics card");
|
||||
InfoStr.SetFont(Cheeseburger);
|
||||
InfoStr.SetPosition(20.f, 460.f);
|
||||
InfoStr.SetColor(sf::Color(200, 100, 150));
|
||||
sf::String infoStr;
|
||||
infoStr.SetText("Move your mouse to change the effect parameters\nPress numpad + and - to change effect\nWarning : some effects may not work\ndepending on your graphics card");
|
||||
infoStr.SetFont(font);
|
||||
infoStr.SetPosition(20.f, 460.f);
|
||||
infoStr.SetColor(sf::Color(200, 100, 150));
|
||||
|
||||
// Create a clock to measure the total time elapsed
|
||||
sf::Clock Clock;
|
||||
sf::Clock clock;
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
sf::Event Event;
|
||||
while (App.GetEvent(Event))
|
||||
sf::Event event;
|
||||
while (window.GetEvent(event))
|
||||
{
|
||||
// Close window : exit
|
||||
if (Event.Type == sf::Event::Closed)
|
||||
App.Close();
|
||||
if (event.Type == sf::Event::Closed)
|
||||
window.Close();
|
||||
|
||||
if (Event.Type == sf::Event::KeyPressed)
|
||||
if (event.Type == sf::Event::KeyPressed)
|
||||
{
|
||||
// Escape key : exit
|
||||
if (Event.Key.Code == sf::Key::Escape)
|
||||
App.Close();
|
||||
if (event.Key.Code == sf::Key::Escape)
|
||||
window.Close();
|
||||
|
||||
// Add key : next effect
|
||||
if (Event.Key.Code == sf::Key::Add)
|
||||
if (event.Key.Code == sf::Key::Add)
|
||||
{
|
||||
CurrentEffect++;
|
||||
if (CurrentEffect == Effects.end())
|
||||
CurrentEffect = Effects.begin();
|
||||
CurFXStr.SetText("Current effect is \"" + CurrentEffect->first + "\"");
|
||||
currentEffect++;
|
||||
if (currentEffect == effects.end())
|
||||
currentEffect = effects.begin();
|
||||
curFXStr.SetText("Current effect is \"" + currentEffect->first + "\"");
|
||||
}
|
||||
|
||||
// Subtract key : previous effect
|
||||
if (Event.Key.Code == sf::Key::Subtract)
|
||||
if (event.Key.Code == sf::Key::Subtract)
|
||||
{
|
||||
if (CurrentEffect == Effects.begin())
|
||||
CurrentEffect = Effects.end();
|
||||
CurrentEffect--;
|
||||
CurFXStr.SetText("Current effect is \"" + CurrentEffect->first + "\"");
|
||||
if (currentEffect == effects.begin())
|
||||
currentEffect = effects.end();
|
||||
currentEffect--;
|
||||
curFXStr.SetText("Current effect is \"" + currentEffect->first + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the mouse position in the range [0, 1]
|
||||
float X = App.GetInput().GetMouseX() / static_cast<float>(App.GetWidth());
|
||||
float Y = App.GetInput().GetMouseY() / static_cast<float>(App.GetHeight());
|
||||
float mouseX = window.GetInput().GetMouseX() / static_cast<float>(window.GetWidth());
|
||||
float mouseY = window.GetInput().GetMouseY() / static_cast<float>(window.GetHeight());
|
||||
|
||||
// Update the current effect
|
||||
if (CurrentEffect->first == "blur") CurrentEffect->second.SetParameter("offset", X * Y * 0.05f);
|
||||
else if (CurrentEffect->first == "colorize") CurrentEffect->second.SetParameter("color", 0.3f, X, Y);
|
||||
else if (CurrentEffect->first == "fisheye") CurrentEffect->second.SetParameter("mouse", X, 1.f - Y);
|
||||
else if (CurrentEffect->first == "wave") CurrentEffect->second.SetParameter("offset", X, Y);
|
||||
else if (CurrentEffect->first == "pixelate") CurrentEffect->second.SetParameter("mouse", X, Y);
|
||||
if (currentEffect->first == "blur") currentEffect->second.SetParameter("offset", mouseX * mouseY * 0.05f);
|
||||
else if (currentEffect->first == "colorize") currentEffect->second.SetParameter("color", 0.3f, mouseX, mouseY);
|
||||
else if (currentEffect->first == "fisheye") currentEffect->second.SetParameter("mouse", mouseX, 1.f - mouseY);
|
||||
else if (currentEffect->first == "wave") currentEffect->second.SetParameter("offset", mouseX, mouseY);
|
||||
else if (currentEffect->first == "pixelate") currentEffect->second.SetParameter("mouse", mouseX, mouseY);
|
||||
|
||||
// Animate the sprite
|
||||
float EntityX = (cos(Clock.GetElapsedTime() * 1.3f) + 1.2f) * 300;
|
||||
float EntityY = (cos(Clock.GetElapsedTime() * 0.8f) + 1.2f) * 200;
|
||||
Entity.SetPosition(EntityX, EntityY);
|
||||
Entity.Rotate(App.GetFrameTime() * 100);
|
||||
float entityX = (cos(clock.GetElapsedTime() * 1.3f) + 1.2f) * 300;
|
||||
float entityY = (cos(clock.GetElapsedTime() * 0.8f) + 1.2f) * 200;
|
||||
entity.SetPosition(entityX, entityY);
|
||||
entity.Rotate(window.GetFrameTime() * 100);
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
window.Clear();
|
||||
|
||||
// Draw background, sprite and apply the post-fx
|
||||
App.Draw(Background);
|
||||
App.Draw(Entity);
|
||||
App.Draw(CurrentEffect->second);
|
||||
window.Draw(background);
|
||||
window.Draw(entity);
|
||||
window.Draw(currentEffect->second);
|
||||
|
||||
// Draw interface strings
|
||||
App.Draw(CurFXStr);
|
||||
App.Draw(InfoStr);
|
||||
window.Draw(curFXStr);
|
||||
window.Draw(infoStr);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -169,37 +169,36 @@ int main()
|
|||
void DisplayError()
|
||||
{
|
||||
// Create the main window
|
||||
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML PostFX");
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML PostFX");
|
||||
|
||||
// Define a string for displaying the error message
|
||||
sf::String ErrorStr("Sorry, your system doesn't support post-effects");
|
||||
ErrorStr.SetPosition(100.f, 250.f);
|
||||
ErrorStr.SetColor(sf::Color(200, 100, 150));
|
||||
sf::String error("Sorry, your system doesn't support post-effects");
|
||||
error.SetPosition(100.f, 250.f);
|
||||
error.SetColor(sf::Color(200, 100, 150));
|
||||
|
||||
// Start the game loop
|
||||
bool Running = true;
|
||||
while (Running)
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
sf::Event Event;
|
||||
while (App.GetEvent(Event))
|
||||
sf::Event event;
|
||||
while (window.GetEvent(event))
|
||||
{
|
||||
// Close window : exit
|
||||
if (Event.Type == sf::Event::Closed)
|
||||
Running = false;
|
||||
if (event.Type == sf::Event::Closed)
|
||||
window.Close();
|
||||
|
||||
// Escape key : exit
|
||||
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
|
||||
Running = false;
|
||||
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
|
||||
window.Close();
|
||||
}
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
window.Clear();
|
||||
|
||||
// Draw the error message
|
||||
App.Draw(ErrorStr);
|
||||
window.Draw(error);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ public :
|
|||
/// Construct the canvas
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
MyCanvas(QWidget* Parent = NULL) :
|
||||
QSFMLCanvas(QSize(100, 100), 0, Parent)
|
||||
MyCanvas(QWidget* parent = NULL) :
|
||||
QSFMLCanvas(QSize(100, 100), 0, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -48,19 +48,19 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
virtual void OnUpdate()
|
||||
{
|
||||
sf::Event Event;
|
||||
while (GetEvent(Event))
|
||||
sf::Event event;
|
||||
while (GetEvent(event))
|
||||
{
|
||||
// Stick the sprite to the mouse cursor
|
||||
if (Event.Type == sf::Event::MouseMoved)
|
||||
if (event.Type == sf::Event::MouseMoved)
|
||||
{
|
||||
mySprite.SetPosition(ConvertCoords(Event.MouseMove.X, Event.MouseMove.Y));
|
||||
mySprite.SetPosition(ConvertCoords(event.MouseMove.X, event.MouseMove.Y));
|
||||
}
|
||||
|
||||
// Adjust the size of the default view when the widget is resized
|
||||
if (Event.Type == sf::Event::Resized)
|
||||
if (event.Type == sf::Event::Resized)
|
||||
{
|
||||
GetDefaultView().Reset(sf::FloatRect(0, 0, Event.Size.Width, Event.Size.Height));
|
||||
GetDefaultView().Reset(sf::FloatRect(0, 0, event.Size.Width, event.Size.Height));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,26 +90,26 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication App(argc, argv);
|
||||
QApplication application(argc, argv);
|
||||
|
||||
// Create the main frame
|
||||
QFrame* MainFrame = new QFrame;
|
||||
MainFrame->setWindowTitle("Qt SFML");
|
||||
MainFrame->resize(400, 400);
|
||||
MainFrame->show();
|
||||
QFrame* mainFrame = new QFrame;
|
||||
mainFrame->setWindowTitle("Qt SFML");
|
||||
mainFrame->resize(400, 400);
|
||||
mainFrame->show();
|
||||
|
||||
// Create a label for showing some text
|
||||
QLabel* Label = new QLabel("This is a SFML window\nembedded into a Qt frame :", MainFrame);
|
||||
Label->setFont(QFont("courier new", 14, 1, false));
|
||||
QLabel* label = new QLabel("This is a SFML window\nembedded into a Qt frame :", mainFrame);
|
||||
label->setFont(QFont("courier new", 14, 1, false));
|
||||
|
||||
// Create a SFML view inside the main frame
|
||||
MyCanvas* SFMLView = new MyCanvas(MainFrame);
|
||||
MyCanvas* SFMLView = new MyCanvas(mainFrame);
|
||||
|
||||
// Create the main layout
|
||||
QVBoxLayout* Layout = new QVBoxLayout;
|
||||
Layout->addWidget(Label, 0);
|
||||
Layout->addWidget(SFMLView, 1);
|
||||
MainFrame->setLayout(Layout);
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
layout->addWidget(label, 0);
|
||||
layout->addWidget(SFMLView, 1);
|
||||
mainFrame->setLayout(layout);
|
||||
|
||||
return App.exec();
|
||||
return application.exec();
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Construct the QSFMLCanvas
|
||||
////////////////////////////////////////////////////////////
|
||||
QSFMLCanvas::QSFMLCanvas(const QSize& Size, unsigned int FrameTime, QWidget* Parent) :
|
||||
QWidget(Parent)
|
||||
QSFMLCanvas::QSFMLCanvas(const QSize& size, unsigned int frameTime, QWidget* parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
// Resize the widget
|
||||
resize(Size);
|
||||
resize(size);
|
||||
|
||||
// Setup some states to allow direct rendering into the widget
|
||||
setAttribute(Qt::WA_PaintOnScreen);
|
||||
|
@ -30,7 +30,7 @@ QWidget(Parent)
|
|||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
// Setup the timer
|
||||
myTimer.setInterval(FrameTime);
|
||||
myTimer.setInterval(frameTime);
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,9 +77,9 @@ QPaintEngine* QSFMLCanvas::paintEngine() const
|
|||
/// we use it to catch the Polish event and initialize
|
||||
/// our SFML window
|
||||
////////////////////////////////////////////////////////////
|
||||
bool QSFMLCanvas::event(QEvent* Event)
|
||||
bool QSFMLCanvas::event(QEvent* event)
|
||||
{
|
||||
if (Event->type() == QEvent::Polish)
|
||||
if (event->type() == QEvent::Polish)
|
||||
{
|
||||
// Under X11, we need to flush the commands sent to the server to ensure that
|
||||
// SFML will get an updated view of the windows
|
||||
|
@ -98,7 +98,7 @@ bool QSFMLCanvas::event(QEvent* Event)
|
|||
myTimer.start();
|
||||
}
|
||||
|
||||
return QWidget::event(Event);
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Construct the QSFMLCanvas
|
||||
///
|
||||
/// \param Size : Initial size of the widget
|
||||
/// \param FrameTime : Frame duration, in milliseconds (0 by default)
|
||||
/// \param Parent : Parent of the widget (NULL by default)
|
||||
/// \param size : Initial size of the widget
|
||||
/// \param frameTime : Frame duration, in milliseconds (0 by default)
|
||||
/// \param parent : Parent of the widget (NULL by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
QSFMLCanvas(const QSize& Size, unsigned int FrameTime = 0, QWidget* Parent = NULL);
|
||||
QSFMLCanvas(const QSize& size, unsigned int frameTime = 0, QWidget* parent = NULL);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
|
@ -62,8 +62,10 @@ private :
|
|||
/// we use it to catch the Polish event and initialize
|
||||
/// our SFML window
|
||||
///
|
||||
/// \param event : Event's attributes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool event(QEvent* Event);
|
||||
virtual bool event(QEvent* event);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Called when the widget needs to be painted ;
|
||||
|
|
|
@ -25,33 +25,33 @@ void DoServerUDP(unsigned short Port);
|
|||
int main()
|
||||
{
|
||||
// Choose a random port for opening sockets (ports < 1024 are reserved)
|
||||
const unsigned short Port = 2435;
|
||||
const unsigned short port = 2435;
|
||||
|
||||
// TCP or UDP ?
|
||||
char Protocol;
|
||||
char protocol;
|
||||
std::cout << "Do you want to use TCP ('t') or UDP ('u') ? ";
|
||||
std::cin >> Protocol;
|
||||
std::cin >> protocol;
|
||||
|
||||
// Client or server ?
|
||||
char Who;
|
||||
char who;
|
||||
std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
|
||||
std::cin >> Who;
|
||||
std::cin >> who;
|
||||
|
||||
if (Who == 's')
|
||||
if (who == 's')
|
||||
{
|
||||
// Run as a server
|
||||
if (Protocol == 't')
|
||||
DoServerTCP(Port);
|
||||
if (protocol == 't')
|
||||
DoServerTCP(port);
|
||||
else
|
||||
DoServerUDP(Port);
|
||||
DoServerUDP(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run as a client
|
||||
if (Protocol == 't')
|
||||
DoClientTCP(Port);
|
||||
if (protocol == 't')
|
||||
DoClientTCP(port);
|
||||
else
|
||||
DoClientUDP(Port);
|
||||
DoClientUDP(port);
|
||||
}
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
|
|
|
@ -10,44 +10,44 @@
|
|||
/// Create a client and connect it to a running server
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoClientTCP(unsigned short Port)
|
||||
void DoClientTCP(unsigned short port)
|
||||
{
|
||||
// Ask for server address
|
||||
sf::IPAddress ServerAddress;
|
||||
sf::IPAddress serverAddress;
|
||||
do
|
||||
{
|
||||
std::cout << "Type address or name of the server to connect to : ";
|
||||
std::cin >> ServerAddress;
|
||||
std::cin >> serverAddress;
|
||||
}
|
||||
while (!ServerAddress.IsValid());
|
||||
while (!serverAddress.IsValid());
|
||||
|
||||
// Create a TCP socket for communicating with server
|
||||
sf::SocketTCP Client;
|
||||
sf::SocketTCP client;
|
||||
|
||||
// Connect to the specified server
|
||||
if (Client.Connect(Port, ServerAddress) != sf::Socket::Done)
|
||||
if (client.Connect(port, serverAddress) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Connected to server " << ServerAddress << std::endl;
|
||||
std::cout << "Connected to server " << serverAddress << std::endl;
|
||||
|
||||
// Receive a message from the client
|
||||
char Message[128];
|
||||
std::size_t Received;
|
||||
if (Client.Receive(Message, sizeof(Message), Received) != sf::Socket::Done)
|
||||
char message[128];
|
||||
std::size_t received;
|
||||
if (client.Receive(message, sizeof(message), received) != sf::Socket::Done)
|
||||
return;
|
||||
|
||||
// Show it
|
||||
std::cout << "Message received from server : \"" << Message << "\"" << std::endl;
|
||||
std::cout << "Message received from server : \"" << message << "\"" << std::endl;
|
||||
|
||||
// Define a message to send back to the server
|
||||
char ToSend[] = "Hi, I'm a client !";
|
||||
char toSend[] = "Hi, I'm a client !";
|
||||
|
||||
// Send the message
|
||||
if (Client.Send(ToSend, sizeof(ToSend)) != sf::Socket::Done)
|
||||
if (client.Send(toSend, sizeof(toSend)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to server : \"" << ToSend << "\"" << std::endl;
|
||||
std::cout << "Message sent to server : \"" << toSend << "\"" << std::endl;
|
||||
|
||||
// Close the socket when we're done
|
||||
Client.Close();
|
||||
client.Close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,39 +55,39 @@ void DoClientTCP(unsigned short Port)
|
|||
/// Launch a server and wait for incoming connections
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoServerTCP(unsigned short Port)
|
||||
void DoServerTCP(unsigned short port)
|
||||
{
|
||||
// Create a TCP socket for communicating with clients
|
||||
sf::SocketTCP Server;
|
||||
sf::SocketTCP server;
|
||||
|
||||
// Listen to a port for incoming connections
|
||||
if (!Server.Listen(Port))
|
||||
if (!server.Listen(port))
|
||||
return;
|
||||
std::cout << "Server is listening to port " << Port << ", waiting for connections... " << std::endl;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||
|
||||
// Wait for a connection
|
||||
sf::IPAddress ClientAddress;
|
||||
sf::SocketTCP Client;
|
||||
if (Server.Accept(Client, &ClientAddress) != sf::Socket::Done)
|
||||
sf::IPAddress clientAddress;
|
||||
sf::SocketTCP client;
|
||||
if (server.Accept(client, &clientAddress) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Client connected : " << ClientAddress << std::endl;
|
||||
std::cout << "Client connected : " << clientAddress << std::endl;
|
||||
|
||||
// Send a message to the client
|
||||
char ToSend[] = "Hi, I'm the server";
|
||||
if (Client.Send(ToSend, sizeof(ToSend)) != sf::Socket::Done)
|
||||
char toSend[] = "Hi, I'm the server";
|
||||
if (client.Send(toSend, sizeof(toSend)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client : \"" << ToSend << "\"" << std::endl;
|
||||
std::cout << "Message sent to the client : \"" << toSend << "\"" << std::endl;
|
||||
|
||||
// Receive a message back from the client
|
||||
char Message[128];
|
||||
std::size_t Received;
|
||||
if (Client.Receive(Message, sizeof(Message), Received) != sf::Socket::Done)
|
||||
char message[128];
|
||||
std::size_t received;
|
||||
if (client.Receive(message, sizeof(message), received) != sf::Socket::Done)
|
||||
return;
|
||||
|
||||
// Show the message
|
||||
std::cout << "Message received from the client : \"" << Message << "\"" << std::endl;
|
||||
std::cout << "Message received from the client : \"" << message << "\"" << std::endl;
|
||||
|
||||
// Close the sockets when we're done
|
||||
Client.Close();
|
||||
Server.Close();
|
||||
client.Close();
|
||||
server.Close();
|
||||
}
|
||||
|
|
|
@ -14,28 +14,28 @@
|
|||
void PlaySound()
|
||||
{
|
||||
// Load a sound buffer from a wav file
|
||||
sf::SoundBuffer Buffer;
|
||||
if (!Buffer.LoadFromFile("datas/sound/footsteps.wav"))
|
||||
sf::SoundBuffer buffer;
|
||||
if (!buffer.LoadFromFile("datas/sound/footsteps.wav"))
|
||||
return;
|
||||
|
||||
// Display sound informations
|
||||
std::cout << "footsteps.wav :" << std::endl;
|
||||
std::cout << " " << Buffer.GetDuration() << " sec" << std::endl;
|
||||
std::cout << " " << Buffer.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << Buffer.GetChannelsCount() << " channels" << std::endl;
|
||||
std::cout << " " << buffer.GetDuration() << " sec" << std::endl;
|
||||
std::cout << " " << buffer.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << buffer.GetChannelsCount() << " channels" << std::endl;
|
||||
|
||||
// Create a sound instance and play it
|
||||
sf::Sound Sound(Buffer);
|
||||
Sound.Play();
|
||||
sf::Sound sound(buffer);
|
||||
sound.Play();
|
||||
|
||||
// Loop while the sound is playing
|
||||
while (Sound.GetStatus() == sf::Sound::Playing)
|
||||
while (sound.GetStatus() == sf::Sound::Playing)
|
||||
{
|
||||
// Leave some CPU time for other processes
|
||||
sf::Sleep(0.1f);
|
||||
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec ";
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset() << " sec ";
|
||||
}
|
||||
std::cout << std::endl << std::endl;
|
||||
}
|
||||
|
@ -48,27 +48,27 @@ void PlaySound()
|
|||
void PlayMusic()
|
||||
{
|
||||
// Load an ogg music file
|
||||
sf::Music Music;
|
||||
if (!Music.OpenFromFile("datas/sound/lepidoptera.ogg"))
|
||||
sf::Music music;
|
||||
if (!music.OpenFromFile("datas/sound/lepidoptera.ogg"))
|
||||
return;
|
||||
|
||||
// Display music informations
|
||||
std::cout << "lepidoptera.ogg :" << std::endl;
|
||||
std::cout << " " << Music.GetDuration() << " sec" << std::endl;
|
||||
std::cout << " " << Music.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << Music.GetChannelsCount() << " channels" << std::endl;
|
||||
std::cout << " " << music.GetDuration() << " sec" << std::endl;
|
||||
std::cout << " " << music.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << music.GetChannelsCount() << " channels" << std::endl;
|
||||
|
||||
// Play it
|
||||
Music.Play();
|
||||
music.Play();
|
||||
|
||||
// Loop while the music is playing
|
||||
while (Music.GetStatus() == sf::Music::Playing)
|
||||
while (music.GetStatus() == sf::Music::Playing)
|
||||
{
|
||||
// Leave some CPU time for other processes
|
||||
sf::Sleep(0.1f);
|
||||
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Music.GetPlayingOffset() << " sec ";
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.GetPlayingOffset() << " sec ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ int main()
|
|||
}
|
||||
|
||||
// Choose the sample rate
|
||||
unsigned int SampleRate;
|
||||
unsigned int sampleRate;
|
||||
std::cout << "Please choose the sample rate for sound capture (44100 is CD quality) : ";
|
||||
std::cin >> SampleRate;
|
||||
std::cin >> sampleRate;
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
// Wait for user input...
|
||||
|
@ -33,50 +33,50 @@ int main()
|
|||
std::cin.ignore(10000, '\n');
|
||||
|
||||
// Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
|
||||
sf::SoundBufferRecorder Recorder;
|
||||
sf::SoundBufferRecorder recorder;
|
||||
|
||||
// Audio capture is done in a separate thread, so we can block the main thread while it is capturing
|
||||
Recorder.Start(SampleRate);
|
||||
recorder.Start(sampleRate);
|
||||
std::cout << "Recording... press enter to stop";
|
||||
std::cin.ignore(10000, '\n');
|
||||
Recorder.Stop();
|
||||
recorder.Stop();
|
||||
|
||||
// Get the buffer containing the captured data
|
||||
const sf::SoundBuffer& Buffer = Recorder.GetBuffer();
|
||||
const sf::SoundBuffer& buffer = recorder.GetBuffer();
|
||||
|
||||
// Display captured sound informations
|
||||
std::cout << "Sound information :" << std::endl;
|
||||
std::cout << " " << Buffer.GetDuration() << " seconds" << std::endl;
|
||||
std::cout << " " << Buffer.GetSampleRate() << " samples / seconds" << std::endl;
|
||||
std::cout << " " << Buffer.GetChannelsCount() << " channels" << std::endl;
|
||||
std::cout << " " << buffer.GetDuration() << " seconds" << std::endl;
|
||||
std::cout << " " << buffer.GetSampleRate() << " samples / seconds" << std::endl;
|
||||
std::cout << " " << buffer.GetChannelsCount() << " channels" << std::endl;
|
||||
|
||||
// Choose what to do with the recorded sound data
|
||||
char Choice;
|
||||
char choice;
|
||||
std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
|
||||
std::cin >> Choice;
|
||||
std::cin >> choice;
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
if (Choice == 's')
|
||||
if (choice == 's')
|
||||
{
|
||||
// Choose the filename
|
||||
std::string Filename;
|
||||
std::string filename;
|
||||
std::cout << "Choose the file to create : ";
|
||||
std::getline(std::cin, Filename);
|
||||
std::getline(std::cin, filename);
|
||||
|
||||
// Save the buffer
|
||||
Buffer.SaveToFile(Filename);
|
||||
buffer.SaveToFile(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a sound instance and play it
|
||||
sf::Sound Sound(Buffer);
|
||||
Sound.Play();
|
||||
sf::Sound sound(buffer);
|
||||
sound.Play();
|
||||
|
||||
// Wait until finished
|
||||
while (Sound.GetStatus() == sf::Sound::Playing)
|
||||
while (sound.GetStatus() == sf::Sound::Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.GetPlayingOffset() << " sec";
|
||||
|
||||
// Leave some CPU time for other threads
|
||||
sf::Sleep(0.1f);
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
const sf::Uint8 AudioData = 1;
|
||||
const sf::Uint8 EndOfStream = 2;
|
||||
const sf::Uint8 audioData = 1;
|
||||
const sf::Uint8 endOfStream = 2;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -25,8 +25,8 @@ public :
|
|||
/// \param Socket : Socket that holds the connection with the server
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NetworkRecorder(sf::SocketTCP Socket) :
|
||||
mySocket(Socket)
|
||||
NetworkRecorder(sf::SocketTCP socket) :
|
||||
mySocket(socket)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -37,15 +37,15 @@ private :
|
|||
/// /see SoundRecorder::ProcessSamples
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount)
|
||||
virtual bool OnProcessSamples(const sf::Int16* samples, std::size_t samplesCount)
|
||||
{
|
||||
// Pack the audio samples into a network packet
|
||||
sf::Packet PacketOut;
|
||||
PacketOut << AudioData;
|
||||
PacketOut.Append(Samples, SamplesCount * sizeof(sf::Int16));
|
||||
sf::Packet packet;
|
||||
packet << audioData;
|
||||
packet.Append(samples, samplesCount * sizeof(sf::Int16));
|
||||
|
||||
// Send the audio packet to the server
|
||||
return mySocket.Send(PacketOut) == sf::Socket::Done;
|
||||
return mySocket.Send(packet) == sf::Socket::Done;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -60,7 +60,7 @@ private :
|
|||
/// start sending him audio data
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoClient(unsigned short Port)
|
||||
void DoClient(unsigned short port)
|
||||
{
|
||||
// Check that the device can capture audio
|
||||
if (sf::SoundRecorder::CanCapture() == false)
|
||||
|
@ -70,21 +70,21 @@ void DoClient(unsigned short Port)
|
|||
}
|
||||
|
||||
// Ask for server address
|
||||
sf::IPAddress ServerAddress;
|
||||
sf::IPAddress serverAddress;
|
||||
do
|
||||
{
|
||||
std::cout << "Type address or name of the server to connect to : ";
|
||||
std::cin >> ServerAddress;
|
||||
std::cin >> serverAddress;
|
||||
}
|
||||
while (!ServerAddress.IsValid());
|
||||
while (!serverAddress.IsValid());
|
||||
|
||||
// Create a TCP socket for communicating with server
|
||||
sf::SocketTCP Socket;
|
||||
sf::SocketTCP socket;
|
||||
|
||||
// Connect to the specified server
|
||||
if (Socket.Connect(Port, ServerAddress) != sf::Socket::Done)
|
||||
if (socket.Connect(port, serverAddress) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Connected to server " << ServerAddress << std::endl;
|
||||
std::cout << "Connected to server " << serverAddress << std::endl;
|
||||
|
||||
// Wait for user input...
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
@ -92,19 +92,19 @@ void DoClient(unsigned short Port)
|
|||
std::cin.ignore(10000, '\n');
|
||||
|
||||
// Create a instance of our custom recorder
|
||||
NetworkRecorder Recorder(Socket);
|
||||
NetworkRecorder recorder(socket);
|
||||
|
||||
// Start capturing audio data
|
||||
Recorder.Start(44100);
|
||||
recorder.Start(44100);
|
||||
std::cout << "Recording... press enter to stop";
|
||||
std::cin.ignore(10000, '\n');
|
||||
Recorder.Stop();
|
||||
recorder.Stop();
|
||||
|
||||
// Send a "end-of-stream" packet
|
||||
sf::Packet PacketOut;
|
||||
PacketOut << EndOfStream;
|
||||
Socket.Send(PacketOut);
|
||||
sf::Packet packet;
|
||||
packet << endOfStream;
|
||||
socket.Send(packet);
|
||||
|
||||
// Close the socket when we're done
|
||||
Socket.Close();
|
||||
socket.Close();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
const sf::Uint8 AudioData = 1;
|
||||
const sf::Uint8 EndOfStream = 2;
|
||||
const sf::Uint8 audioData = 1;
|
||||
const sf::Uint8 endOfStream = 2;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -47,19 +47,19 @@ public :
|
|||
/// Run the server, stream audio data from the client
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Start(unsigned short Port)
|
||||
void Start(unsigned short port)
|
||||
{
|
||||
if (!myHasFinished)
|
||||
{
|
||||
// Listen to the given port for incoming connections
|
||||
if (!myListener.Listen(Port))
|
||||
if (!myListener.Listen(port))
|
||||
return;
|
||||
std::cout << "Server is listening to port " << Port << ", waiting for connections... " << std::endl;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||
|
||||
// Wait for a connection
|
||||
sf::IPAddress ClientAddress;
|
||||
myListener.Accept(myClient, &ClientAddress);
|
||||
std::cout << "Client connected : " << ClientAddress << std::endl;
|
||||
sf::IPAddress clientAddress;
|
||||
myListener.Accept(myClient, &clientAddress);
|
||||
std::cout << "Client connected : " << clientAddress << std::endl;
|
||||
|
||||
// Start playback
|
||||
Play();
|
||||
|
@ -80,7 +80,7 @@ private :
|
|||
/// /see SoundStream::OnGetData
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool OnGetData(sf::SoundStream::Chunk& Data)
|
||||
virtual bool OnGetData(sf::SoundStream::Chunk& data)
|
||||
{
|
||||
// We have reached the end of the buffer and all audio data have been played : we can stop playback
|
||||
if ((myOffset >= mySamples.size()) && myHasFinished)
|
||||
|
@ -93,13 +93,13 @@ private :
|
|||
// Copy samples into a local buffer to avoid synchronization problems
|
||||
// (don't forget that we run in two separate threads)
|
||||
{
|
||||
sf::Lock Lock(myMutex);
|
||||
sf::Lock lock(myMutex);
|
||||
myTempBuffer.assign(mySamples.begin() + myOffset, mySamples.end());
|
||||
}
|
||||
|
||||
// Fill audio data to pass to the stream
|
||||
Data.Samples = &myTempBuffer[0];
|
||||
Data.NbSamples = myTempBuffer.size();
|
||||
data.Samples = &myTempBuffer[0];
|
||||
data.NbSamples = myTempBuffer.size();
|
||||
|
||||
// Update the playing offset
|
||||
myOffset += myTempBuffer.size();
|
||||
|
@ -111,9 +111,9 @@ private :
|
|||
/// /see SoundStream::OnSeek
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void OnSeek(float TimeOffset)
|
||||
virtual void OnSeek(float timeOffset)
|
||||
{
|
||||
myOffset = static_cast<std::size_t>(TimeOffset * GetSampleRate() * GetChannelsCount());
|
||||
myOffset = static_cast<std::size_t>(timeOffset * GetSampleRate() * GetChannelsCount());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -125,28 +125,28 @@ private :
|
|||
while (!myHasFinished)
|
||||
{
|
||||
// Get waiting audio data from the network
|
||||
sf::Packet PacketIn;
|
||||
if (myClient.Receive(PacketIn) != sf::Socket::Done)
|
||||
sf::Packet packet;
|
||||
if (myClient.Receive(packet) != sf::Socket::Done)
|
||||
break;
|
||||
|
||||
// Extract the message ID
|
||||
sf::Uint8 Id;
|
||||
PacketIn >> Id;
|
||||
sf::Uint8 id;
|
||||
packet >> id;
|
||||
|
||||
if (Id == AudioData)
|
||||
if (id == audioData)
|
||||
{
|
||||
// Extract audio samples from the packet, and append it to our samples buffer
|
||||
const sf::Int16* Samples = reinterpret_cast<const sf::Int16*>(PacketIn.GetData() + 1);
|
||||
std::size_t NbSamples = (PacketIn.GetDataSize() - 1) / sizeof(sf::Int16);
|
||||
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(packet.GetData() + 1);
|
||||
std::size_t nbSamples = (packet.GetDataSize() - 1) / sizeof(sf::Int16);
|
||||
|
||||
// Don't forget that the other thread can access the samples array at any time
|
||||
// (so we protect any operation on it with the mutex)
|
||||
{
|
||||
sf::Lock Lock(myMutex);
|
||||
std::copy(Samples, Samples + NbSamples, std::back_inserter(mySamples));
|
||||
sf::Lock lock(myMutex);
|
||||
std::copy(samples, samples + nbSamples, std::back_inserter(mySamples));
|
||||
}
|
||||
}
|
||||
else if (Id == EndOfStream)
|
||||
else if (id == endOfStream)
|
||||
{
|
||||
// End of stream reached : we stop receiving audio data
|
||||
std::cout << "Audio data has been 100% received !" << std::endl;
|
||||
|
@ -179,14 +179,14 @@ private :
|
|||
/// a connected client
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoServer(unsigned short Port)
|
||||
void DoServer(unsigned short port)
|
||||
{
|
||||
// Build an audio stream to play sound data as it is received through the network
|
||||
NetworkAudioStream AudioStream;
|
||||
AudioStream.Start(Port);
|
||||
NetworkAudioStream audioStream;
|
||||
audioStream.Start(port);
|
||||
|
||||
// Loop until the sound playback is finished
|
||||
while (AudioStream.GetStatus() != sf::SoundStream::Stopped)
|
||||
while (audioStream.GetStatus() != sf::SoundStream::Stopped)
|
||||
{
|
||||
// Leave some CPU time for other threads
|
||||
sf::Sleep(0.1f);
|
||||
|
@ -199,10 +199,10 @@ void DoServer(unsigned short Port)
|
|||
std::cin.ignore(10000, '\n');
|
||||
|
||||
// Replay the sound (just to make sure replaying the received data is OK)
|
||||
AudioStream.Play();
|
||||
audioStream.Play();
|
||||
|
||||
// Loop until the sound playback is finished
|
||||
while (AudioStream.GetStatus() != sf::SoundStream::Stopped)
|
||||
while (audioStream.GetStatus() != sf::SoundStream::Stopped)
|
||||
{
|
||||
// Leave some CPU time for other threads
|
||||
sf::Sleep(0.1f);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
|||
// Function prototypes
|
||||
// (I'm too lazy to put them into separate headers...)
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoClient(unsigned short Port);
|
||||
void DoServer(unsigned short Port);
|
||||
void DoClient(unsigned short port);
|
||||
void DoServer(unsigned short port);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -24,22 +24,22 @@ void DoServer(unsigned short Port);
|
|||
int main()
|
||||
{
|
||||
// Choose a random port for opening sockets (ports < 1024 are reserved)
|
||||
const unsigned short Port = 2435;
|
||||
const unsigned short port = 2435;
|
||||
|
||||
// Client or server ?
|
||||
char Who;
|
||||
char who;
|
||||
std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
|
||||
std::cin >> Who;
|
||||
std::cin >> who;
|
||||
|
||||
if (Who == 's')
|
||||
if (who == 's')
|
||||
{
|
||||
// Run as a server
|
||||
DoServer(Port);
|
||||
DoServer(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run as a client
|
||||
DoClient(Port);
|
||||
DoClient(port);
|
||||
}
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
#include <windows.h>
|
||||
#include <cmath>
|
||||
|
||||
HWND Button;
|
||||
HWND button;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Function called whenever one of our windows receives a message
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam)
|
||||
LRESULT CALLBACK OnEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (Message)
|
||||
switch (message)
|
||||
{
|
||||
// Quit when we close the main window
|
||||
case WM_CLOSE :
|
||||
|
@ -27,7 +27,7 @@ LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam
|
|||
// Quit when we click the "quit" button
|
||||
case WM_COMMAND :
|
||||
{
|
||||
if (reinterpret_cast<HWND>(LParam) == Button)
|
||||
if (reinterpret_cast<HWND>(lParam) == button)
|
||||
{
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
|
@ -35,7 +35,7 @@ LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam
|
|||
}
|
||||
}
|
||||
|
||||
return DefWindowProc(Handle, Message, WParam, LParam);
|
||||
return DefWindowProc(handle, message, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,55 +47,55 @@ LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam
|
|||
/// \return Error code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT)
|
||||
INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
|
||||
{
|
||||
// Define a class for our main window
|
||||
WNDCLASS WindowClass;
|
||||
WindowClass.style = 0;
|
||||
WindowClass.lpfnWndProc = &OnEvent;
|
||||
WindowClass.cbClsExtra = 0;
|
||||
WindowClass.cbWndExtra = 0;
|
||||
WindowClass.hInstance = Instance;
|
||||
WindowClass.hIcon = NULL;
|
||||
WindowClass.hCursor = 0;
|
||||
WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
|
||||
WindowClass.lpszMenuName = NULL;
|
||||
WindowClass.lpszClassName = TEXT("SFML App");
|
||||
RegisterClass(&WindowClass);
|
||||
WNDCLASS windowClass;
|
||||
windowClass.style = 0;
|
||||
windowClass.lpfnWndProc = &OnEvent;
|
||||
windowClass.cbClsExtra = 0;
|
||||
windowClass.cbWndExtra = 0;
|
||||
windowClass.hInstance = instance;
|
||||
windowClass.hIcon = NULL;
|
||||
windowClass.hCursor = 0;
|
||||
windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
|
||||
windowClass.lpszMenuName = NULL;
|
||||
windowClass.lpszClassName = TEXT("SFML App");
|
||||
RegisterClass(&windowClass);
|
||||
|
||||
// Let's create the main window
|
||||
HWND Window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, Instance, NULL);
|
||||
HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, instance, NULL);
|
||||
|
||||
// Add a button for exiting
|
||||
Button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, Window, NULL, Instance, NULL);
|
||||
button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, NULL, instance, NULL);
|
||||
|
||||
// Let's create two SFML views
|
||||
HWND View1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, Window, NULL, Instance, NULL);
|
||||
HWND View2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, Window, NULL, Instance, NULL);
|
||||
sf::RenderWindow SFMLView1(View1);
|
||||
sf::RenderWindow SFMLView2(View2);
|
||||
HWND view1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, NULL, instance, NULL);
|
||||
HWND view2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, NULL, instance, NULL);
|
||||
sf::RenderWindow SFMLView1(view1);
|
||||
sf::RenderWindow SFMLView2(view2);
|
||||
|
||||
// Load some images to display
|
||||
sf::Image Image1, Image2;
|
||||
if (!Image1.LoadFromFile("datas/win32/image1.jpg") || !Image2.LoadFromFile("datas/win32/image2.jpg"))
|
||||
sf::Image image1, image2;
|
||||
if (!image1.LoadFromFile("datas/win32/image1.jpg") || !image2.LoadFromFile("datas/win32/image2.jpg"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Sprite Sprite1(Image1);
|
||||
sf::Sprite Sprite2(Image2);
|
||||
Sprite1.SetOrigin(Sprite1.GetSize() / 2.f);
|
||||
sf::Sprite sprite1(image1);
|
||||
sf::Sprite sprite2(image2);
|
||||
sprite1.SetOrigin(sprite1.GetSize() / 2.f);
|
||||
|
||||
// Create a clock for measuring elapsed time
|
||||
sf::Clock Clock;
|
||||
sf::Clock clock;
|
||||
|
||||
// Loop until a WM_QUIT message is received
|
||||
MSG Message;
|
||||
Message.message = static_cast<UINT>(~WM_QUIT);
|
||||
while (Message.message != WM_QUIT)
|
||||
MSG message;
|
||||
message.message = static_cast<UINT>(~WM_QUIT);
|
||||
while (message.message != WM_QUIT)
|
||||
{
|
||||
if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
|
||||
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
// If a message was waiting in the message queue, process it
|
||||
TranslateMessage(&Message);
|
||||
DispatchMessage(&Message);
|
||||
TranslateMessage(&message);
|
||||
DispatchMessage(&message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -104,12 +104,12 @@ INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT)
|
|||
SFMLView2.Clear();
|
||||
|
||||
// Draw sprite 1 on view 1
|
||||
Sprite1.SetRotation(Clock.GetElapsedTime() * 100);
|
||||
SFMLView1.Draw(Sprite1);
|
||||
sprite1.SetRotation(clock.GetElapsedTime() * 100);
|
||||
SFMLView1.Draw(sprite1);
|
||||
|
||||
// Draw sprite 2 on view 2
|
||||
Sprite2.SetX(cos(Clock.GetElapsedTime()) * 100);
|
||||
SFMLView2.Draw(Sprite2);
|
||||
sprite2.SetX(cos(clock.GetElapsedTime()) * 100);
|
||||
SFMLView2.Draw(sprite2);
|
||||
|
||||
// Display each view on screen
|
||||
SFMLView1.Display();
|
||||
|
@ -118,10 +118,10 @@ INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT)
|
|||
}
|
||||
|
||||
// Destroy the main window (all its child controls will be destroyed)
|
||||
DestroyWindow(Window);
|
||||
DestroyWindow(window);
|
||||
|
||||
// Don't forget to unregister the window class
|
||||
UnregisterClass(TEXT("SFML App"), Instance);
|
||||
UnregisterClass(TEXT("SFML App"), instance);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
int main()
|
||||
{
|
||||
// Create the main window
|
||||
sf::Window App(sf::VideoMode(640, 480, 32), "SFML Window");
|
||||
sf::Window window(sf::VideoMode(640, 480, 32), "SFML Window");
|
||||
|
||||
// Create a clock for measuring the time elapsed
|
||||
sf::Clock Clock;
|
||||
sf::Clock clock;
|
||||
|
||||
// Set the color and depth clear values
|
||||
glClearDepth(1.f);
|
||||
|
@ -34,29 +34,29 @@ int main()
|
|||
gluPerspective(90.f, 1.f, 1.f, 500.f);
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
while (window.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
sf::Event Event;
|
||||
while (App.GetEvent(Event))
|
||||
sf::Event event;
|
||||
while (window.GetEvent(event))
|
||||
{
|
||||
// Close window : exit
|
||||
if (Event.Type == sf::Event::Closed)
|
||||
App.Close();
|
||||
if (event.Type == sf::Event::Closed)
|
||||
window.Close();
|
||||
|
||||
// Escape key : exit
|
||||
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
|
||||
App.Close();
|
||||
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
|
||||
window.Close();
|
||||
|
||||
// Resize event : adjust viewport
|
||||
if (Event.Type == sf::Event::Resized)
|
||||
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
|
||||
if (event.Type == sf::Event::Resized)
|
||||
glViewport(0, 0, event.Size.Width, event.Size.Height);
|
||||
}
|
||||
|
||||
// Set the active window before using OpenGL commands
|
||||
// It's useless here because the active window is always the same,
|
||||
// but don't forget it if you use multiple windows
|
||||
App.SetActive();
|
||||
window.SetActive();
|
||||
|
||||
// Clear color and depth buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -65,9 +65,9 @@ int main()
|
|||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.f, 0.f, -200.f);
|
||||
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
|
||||
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
|
||||
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
|
||||
glRotatef(clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
|
||||
glRotatef(clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
|
||||
glRotatef(clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw a cube
|
||||
glBegin(GL_QUADS);
|
||||
|
@ -111,7 +111,7 @@ int main()
|
|||
glEnd();
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
window.Display();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -17,8 +17,8 @@ public :
|
|||
/// Construct the canvas
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
MyCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style = 0) :
|
||||
wxSFMLCanvas(Parent, Id, Position, Size, Style)
|
||||
MyCanvas(wxWindow* parent, wxWindowID id, const wxPoint& position, const wxSize& size, long style = 0) :
|
||||
wxSFMLCanvas(parent, id, position, size, style)
|
||||
{
|
||||
// Load an image and assign it to our sprite
|
||||
myImage.LoadFromFile("datas/wxwidgets/sfml.png");
|
||||
|
@ -52,10 +52,10 @@ private :
|
|||
/// Function called when the mouse cursor moves
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void OnMouseMove(wxMouseEvent& Event)
|
||||
void OnMouseMove(wxMouseEvent& event)
|
||||
{
|
||||
// Make the sprite follow the mouse cursor
|
||||
mySprite.SetPosition(ConvertCoords(Event.GetX(), Event.GetY()));
|
||||
mySprite.SetPosition(ConvertCoords(event.GetX(), event.GetY()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -100,8 +100,8 @@ private :
|
|||
virtual bool OnInit()
|
||||
{
|
||||
// Create the main window
|
||||
MyFrame* MainFrame = new MyFrame;
|
||||
MainFrame->Show();
|
||||
MyFrame* mainFrame = new MyFrame;
|
||||
mainFrame->Show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,17 +26,17 @@ END_EVENT_TABLE()
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Construct the wxSFMLCanvas
|
||||
////////////////////////////////////////////////////////////
|
||||
wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
|
||||
wxControl(Parent, Id, Position, Size, Style)
|
||||
wxSFMLCanvas::wxSFMLCanvas(wxWindow* parent, wxWindowID id, const wxPoint& position, const wxSize& size, long style) :
|
||||
wxControl(parent, id, position, size, style)
|
||||
{
|
||||
#ifdef __WXGTK__
|
||||
|
||||
// GTK implementation requires to go deeper to find the low-level X11 identifier of the widget
|
||||
gtk_widget_realize(m_wxwindow);
|
||||
gtk_widget_set_double_buffered(m_wxwindow, false);
|
||||
GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
|
||||
XFlush(GDK_WINDOW_XDISPLAY(Win));
|
||||
sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
|
||||
GdkWindow* window = GTK_PIZZA(m_wxwindow)->bin_window;
|
||||
XFlush(GDK_WINDOW_XDISPLAY(window));
|
||||
sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(window));
|
||||
|
||||
#else
|
||||
|
||||
|
@ -84,7 +84,7 @@ void wxSFMLCanvas::OnIdle(wxIdleEvent&)
|
|||
void wxSFMLCanvas::OnPaint(wxPaintEvent&)
|
||||
{
|
||||
// Make sure the control is able to be repainted
|
||||
wxPaintDC Dc(this);
|
||||
wxPaintDC dc(this);
|
||||
|
||||
// Let the derived class do its specific stuff
|
||||
OnUpdate();
|
||||
|
|
|
@ -19,14 +19,14 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Construct the wxSFMLCanvas
|
||||
///
|
||||
/// \param Parent : Parent of the control (NULL by default)
|
||||
/// \param Id : Identifier of the control (-1 by default)
|
||||
/// \param Position : Position of the control (wxDefaultPosition by default)
|
||||
/// \param Size : Size of the control (wxDefaultSize by default)
|
||||
/// \param Style : Style of the control (0 by default)
|
||||
/// \param parent : Parent of the control (NULL by default)
|
||||
/// \param id : Identifier of the control (-1 by default)
|
||||
/// \param position : Position of the control (wxDefaultPosition by default)
|
||||
/// \param size : Size of the control (wxDefaultSize by default)
|
||||
/// \param style : Style of the control (0 by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
wxSFMLCanvas(wxWindow* Parent = NULL, wxWindowID Id = -1, const wxPoint& Position = wxDefaultPosition, const wxSize& Size = wxDefaultSize, long Style = 0);
|
||||
wxSFMLCanvas(wxWindow* parent = NULL, wxWindowID id = -1, const wxPoint& position = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue