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

Show Posts

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


Messages - Grimlen

Pages: [1] 2
1
Java / getPlayingOffset() always 0?
« on: November 26, 2013, 08:56:59 am »
For some reason when I play my sound, the getPlayingOffset() always returns 0.
Even though it's clearly played for more than a few seconds, it's still 0:

    @Override
    public void mousePressed(java.awt.event.MouseEvent e) {
            if(sound != null){
                Time t = jt.sound.getPlayingOffset();
                long sndPos = (t.asMilliseconds());
                System.out.println("POS: " + sndPos);
            }
    }
 

And yes, I can hear the sound perfectly fine.
Why does it display 0?

Was this function not implemented yet?

2
Java / Trying to draw a line using VectorArray
« on: November 21, 2013, 07:55:48 am »
Just trying to draw a simple line. Nothing seems to be drawing.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jsoundeditor;

import java.awt.Point;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.swing.JFileChooser;
import org.jsfml.audio.Sound;
import org.jsfml.audio.SoundBuffer;
import org.jsfml.graphics.Color;
import org.jsfml.graphics.RectangleShape;
import org.jsfml.graphics.RenderWindow;
import org.jsfml.graphics.Vertex;
import org.jsfml.graphics.VertexArray;
import org.jsfml.system.Vector2f;
import org.jsfml.window.VideoMode;
import org.jsfml.window.event.Event;

/**
 *
 * @author Taylor
 */

public class JSoundEditor {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws IOException {
        RenderWindow window = new RenderWindow();
        window.create(new VideoMode(600, 225), "Hello!");
        window.setFramerateLimit(30);

        while(window.isOpen()){
            window.clear(Color.BLUE);
            window.display();
            VertexArray v = new VertexArray();
            Vector2f pos;
            pos = new Vector2f(1.0f, 1.0f);
            Vertex v1 = new Vertex(pos);
            pos = new Vector2f(5.0f, 1.0f);
            Vertex v2 = new Vertex(pos);
            v.add(v1);
            v.add(v2);
            window.draw(v);
            for(Event event : window.pollEvents()){
                if(event.type == Event.Type.CLOSED){
                    window.close();
                }
                else if(event.type == Event.Type.MOUSE_BUTTON_PRESSED){
                    System.out.println("test");
                }
            }
        }
    }
}
 

I figured it might have been because I was clearing the window as WHITE so I changed it to blue
so I could see the color of the line. Didn't work.
I can't even change the color of the Vertices.
IE:
v1.color = Color.RED;

I get an error:
"cannot assign a value to a final variable color"

So why isn't it drawing anything?

3
General discussions / Re: SFML 2.1 Visual Studio 2013 Binaries + Template
« on: November 18, 2013, 08:10:53 pm »
Does anyone have a WIN32 project template?

4
Can someone help?
I did everything he said, I downloaded the template as well.
Opened it up, it ran completely fine in both Debug and Release.

However I have a problem.
I'm trying to make a WIN32 project and getting VS 2013 to work with SFML 2.1.

I can't get it to work with a WIN32 project.
I'm not sure what else he has in the templates property pages.
The only difference I found was the includes:

C:\SFML\SFML-2.1\include;%(AdditionalIncludeDirectories)
C:\SFML\SFML-2.1\Libs\Release;%(AdditionalLibraryDirectories)

I'm simply trying to get the Audio portion of SFML working with Visual Studio 2013 Ultimate edition.

Now seeing that the template project works smoothly, this shows that I've successfully copied the SFML dlls to the VC/bin folder correctly.

The WIN32 project just doesn't work.
Here are the libs I've included in my win32 project property pages:
sfml-system-d.lib;sfml-window-d.lib;sfml-audio-d.lib;

When I try to build and run it, I get an error:

"The program can't start because MSVCP110D.dll is missing from your computer. Try reinstalling the program to fix this problem."

I'm unsure of why I'm getting this error.

5
Audio / Altering the samples, possible?
« on: November 12, 2013, 08:38:18 am »
Is it at all possible to alter the samples found in a buffer/sound file?

For example.
Let's say I make an audio editor.
In this editor I can display a sound via its samples on a grid/graph.

In this graph, I can drag my mouse over samples, cut them out, and paste them at
a different location.

So if I were to record myself saying:
"Hello World!"

And I cut the samples where I started saying: "World!", and pasted it before "Hello", I would get back:
"World! Hello"

But how would I do this via the buffer?
This is simple enough how to do it with just an array and display it back to the graph, but
what if I wanted to save the newly organized samples to a file, I would need to somehow
modify the buffer.

How would I do this?

6
General / Re: SFML Win32 - Messages (ie: Scrollbars)
« on: October 05, 2013, 03:16:09 am »
Well I even got rid of the clear() this time and it's still black.
But the main problem I'm having is the scrollbar, when I move it, the drawing + black background goes away.
When I stop moving the scrollbar, it goes back to normal (draws the sprite and the black background).

How do I get it to stop getting rid of the sprite when I move the scrollbars?

7
General / Re: SFML Win32 - Messages (ie: Scrollbars)
« on: October 04, 2013, 06:35:46 pm »
Got it working.
Clearly I didn't realize I had a "WndProc" all ready in the code.

However I have another question.

Now I'm trying to display a sprite (knight.png) in my main win32 window.
I achieved this. However, for some reason:
1) The background is black and not default gray
2) When I scroll with my scrollbars, the background changes to gray and erases my sprite while scrolling, and puts the background color back to black and draws my sprite again after I stop scrolling.

Here's my updated code with drawing a sprite in a Win32 window:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <windows.h>
#include <cmath>


HWND button;


////////////////////////////////////////////////////////////
/// Function called whenever one of our windows receives a message
///
////////////////////////////////////////////////////////////
LRESULT CALLBACK onEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
        SCROLLINFO si;

        RECT clientRect;
        GetClientRect(handle, &clientRect);
        int iVertPos, iHorzPos;

    switch (message)
    {
                case WM_CREATE:
                MessageBox(handle, TEXT("MESSAGE"), TEXT("Hello"), 0);
                break;

                case WM_HSCROLL:
                        si.cbSize = sizeof(si);
                        si.fMask = SIF_ALL;

                        GetScrollInfo(handle, SB_HORZ, &si);
                        iHorzPos = si.nPos;

                        switch (LOWORD(wParam))
                        {
                        case SB_LINELEFT:
                                si.nPos -=1;
                                break;

                        case SB_LINERIGHT:
                                si.nPos += 1;
                                break;

                        case SB_PAGELEFT:
                                si.nPos -= si.nPage;
                                break;

                        case SB_PAGERIGHT:
                                si.nPos += si.nPage;
                                break;
                       
                        case SB_THUMBTRACK:
                                si.nPos = si.nTrackPos;
                                break;
                       

                        default:
                                break;
                        }

                        si.fMask = SIF_POS;
                        SetScrollInfo(handle, SB_HORZ, &si, TRUE);
                        GetScrollInfo(handle, SB_HORZ, &si);

                        if (si.nPos != iHorzPos)
                        {
                                InvalidateRect(handle, &clientRect, TRUE);
                                UpdateWindow(handle);
                        }
                        return 0;
         case WM_VSCROLL:
                        si.cbSize = sizeof(si);
                        si.fMask = SIF_ALL;
                        GetScrollInfo(handle, SB_VERT, &si);
                        iVertPos = si.nPos;
                        switch(LOWORD(wParam)){
                                case SB_TOP:
                                        si.nPos = si.nMin;
                                        break;

                                case SB_BOTTOM:
                                        si.nPos = si.nMax;
                                        break;

                                case SB_LINEUP:
                                        si.nPos--;
                                        break;

                                case SB_LINEDOWN:
                                        si.nPos++;
                                        break;

                                case SB_PAGEUP:
                                        si.nPos -= si.nPage;
                                        break;

                                case SB_PAGEDOWN:
                                        si.nPos += si.nPage;
                                        break;

                                case SB_THUMBTRACK:
                                        si.nPos = si.nTrackPos;
                                        break;

                                default:
                                        break;
                                }

                si.fMask = SIF_POS;
                SetScrollInfo(handle, SB_VERT, &si, TRUE);
                GetScrollInfo(handle, SB_VERT, &si);
                if(iVertPos != si.nPos){
                        InvalidateRect(handle, &clientRect, TRUE);
                        UpdateWindow(handle);
                }
                return 0;
        // Quit when we close the main window
        case WM_CLOSE :
        {
            PostQuitMessage(0);
            return 0;
        }

        // Quit when we click the "quit" button
        case WM_COMMAND :
        {
            if (reinterpret_cast<HWND>(lParam) == button)
            {
                PostQuitMessage(0);
                return 0;
            }
        }
    }

    return DefWindowProc(handle, message, wParam, lParam);
}

LRESULT CALLBACK freqEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam){
        switch(message){
        case WM_CREATE:

                break;
        }
        return DefWindowProc(handle, message, wParam, lParam);
}


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \param Instance : Instance of the application
///
/// \return Error code
///
////////////////////////////////////////////////////////////
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("Main");
    RegisterClass(&windowClass);

    // Define a class for our frequency window
    WNDCLASS freqClass;
    freqClass.style         = 0;
    freqClass.lpfnWndProc   = &freqEvent;
    freqClass.cbClsExtra    = 0;
    freqClass.cbWndExtra    = 0;
    freqClass.hInstance     = instance;
    freqClass.hIcon         = NULL;
    freqClass.hCursor       = 0;
    freqClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
    freqClass.lpszMenuName  = NULL;
    freqClass.lpszClassName = TEXT("Freq");
    RegisterClass(&freqClass);

        sf::Texture texture;
        if (!texture.loadFromFile("knight.png"))
        {
                // error...
        }
        sf::Sprite sprite;
        sprite.setTexture(texture);

    // Main Window
    HWND window = CreateWindow(TEXT("Main"), TEXT("Sound Editor"), WS_SYSMENU | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, 200, 200, 660, 520, NULL, NULL, instance, NULL);
        //Frequency Window
        HWND freqWnd = CreateWindow(TEXT("Freq"), TEXT("Frequency"), 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);

        sf::RenderWindow SFMLViewMain(window);

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

    // Create a clock for measuring elapsed time
    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)
    {
        if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&message);
            DispatchMessage(&message);
        }
        else
        {
            float time = clock.getElapsedTime().asSeconds();
                        SFMLViewMain.clear();
                        SFMLViewMain.draw(sprite);
                        SFMLViewMain.display();
                       
            // Clear views
            /*
                        SFMLView1.clear();
            SFMLView2.clear();


            // Display each view on screen
            SFMLView1.display();
            SFMLView2.display();
                        */

        }
    }

    // Destroy the main window (all its child controls will be destroyed)
    DestroyWindow(window);
        DestroyWindow(freqWnd);

    // Don't forget to unregister the window class
    UnregisterClass(TEXT("Main"), instance);
        UnregisterClass(TEXT("Freq"), instance);
    return EXIT_SUCCESS;
}
 

8
General / SFML Win32 - Messages (ie: Scrollbars)
« on: October 04, 2013, 08:52:41 am »
I'm trying to setup scrollbars in a simple SFML window.
The main reason why I need scrollbars is I'm trying to make a simple wave editor using
the sound functions in SFML. The scrollbars will be used for scrolling through the wave (hscrolling) and also
zooming in on it (vscrolling).

However I'm having trouble just even getting simple events like: WM_CREATE to popup once I've
created a window. I'm also confused how to integrate win32 into SFML becaue of how it's setup.
There's no wndproc callback now...so how does it know which window is getting a callback?

Anyways here's my code, maybe someone can tell me how to get a simple WM_CREATE event working:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <windows.h>
#include <cmath>

HWND button;


////////////////////////////////////////////////////////////
/// Function called whenever one of our windows receives a message
///
////////////////////////////////////////////////////////////
LRESULT CALLBACK onEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        // Quit when we close the main window
        case WM_CLOSE :
        {
            PostQuitMessage(0);
            return 0;
        }

        // Quit when we click the "quit" button
        case WM_COMMAND :
        {
            if (reinterpret_cast<HWND>(lParam) == button)
            {
                PostQuitMessage(0);
                return 0;
            }
        }
    }

    return DefWindowProc(handle, message, wParam, lParam);
}


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \param Instance : Instance of the application
///
/// \return Error code
///
////////////////////////////////////////////////////////////
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("Test");
    RegisterClass(&windowClass);

    // Main Window
    HWND window = CreateWindow(TEXT("Test"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, 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);

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

    // Create a clock for measuring elapsed time
    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)
    {
        if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&message);
                        switch(message.message){
                        case WM_CREATE:
                                MessageBox(window, TEXT("MESSAGE"), TEXT("Hello"), 0);
                                break;
                        }
            DispatchMessage(&message);
        }
        else
        {
            float time = clock.getElapsedTime().asSeconds();

            // Clear views
            /*
                        SFMLView1.clear();
            SFMLView2.clear();


            // Display each view on screen
            SFMLView1.display();
            SFMLView2.display();
                        */

        }
    }

    // Destroy the main window (all its child controls will be destroyed)
    DestroyWindow(window);

    // Don't forget to unregister the window class
    UnregisterClass(TEXT("Test"), instance);

    return EXIT_SUCCESS;
}
 

9
Network / Re: UDP Network help with ports
« on: October 15, 2012, 04:32:54 pm »
Yes but how do I tell whether a port is all ready binded?
i.e.

Client 1 checks if port 4568 is binded...No.
Client 1 binds to port 4568.
Client 2 checks if port 4568 is binded...Yes.
Client 2 checks if port 4569 is binded...No.
Client 2 binds to port 4569.

Now I read the documentation and it says I can use: "Socket::AnyPort".
However I want to know if this is safe?

10
Network / UDP Network help with ports
« on: October 15, 2012, 05:19:56 am »
I've got a problem when it comes to ports.
I've got my server binded to port: 4567
My client is binded to port: 4568

There's a problem with this.
If I launch one client, it will successfully bind to port 4568.
If I launch another client, it will fail to bind to port 4568.

So how exactly would I launch two clients on the same computer?

11
Network / Whenever I receive a new message, my player stops drawing
« on: October 09, 2012, 11:09:47 pm »
Here's how my client/server works:

Client presses the LEFT key:
Sends byte: 0

Server reads for a byte:
Gets: 0
Decided to execute code:
    Create a new player and insert player into array

Later on in server on another thread:
   Draw players using window.draw(), iterating through vector of players

Client presses the RIGHT key:
Sends byte: 1

Server reads for a byte:
Get: 1
Decided to execute code:
    Show the IP of the player that sent this message
    //Up to this point, the server will stop drawing the player
   //In a very short instant upon each new message being received, the server will draw a white rectangle       //(the size of my player) and then draw the black background. Sometimes I even catch a glimpse of my player sprite, but it goes away.

I'm not sure why, after I receive byte: 1, the server stops drawing my player...

main.cpp:
/************************************************************
SERVER
************************************************************/

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;
using namespace sf;

#include "ServPlayer.h"
#include "Sockets.h"

vector<ServPlayer> players;

bool checkIpAndPort(Data d){
        for (vector<ServPlayer>::iterator itr = players.begin(); itr != players.end(); ++itr) {
                if(itr->ip == d.sender && itr->port == d.port){
                        return true;
                }
        }
        return false;
}

void netThread(void *userData){
        bool running = *(bool*) userData;

        sf::IpAddress sender;

        // Create the UDP socket
        sf::UdpSocket socket;
        // Bind it (listen) to the port 4567
        if (!socket.bind(4567)){
                // Error...
        }

        while(running){
                Data d = readbyte(&socket);
                char b = d.byte;
                switch(b)
                {
                        case 0:
                                {
                                //Find out if the IP address is not in
                                        if(!checkIpAndPort(d)){
                                                ServPlayer p(d.sender, d.port);
                                                players.push_back(p);
                                                cout << "New Player: " << d.sender << " " << d.port << endl;
                                        }
                                        else{
                                                cout << "Hello!" << endl;
                                        }
                                break;
                                }


                        case 1:
                                {
                                        for (vector<ServPlayer>::iterator itr = players.begin(); itr != players.end(); ++itr) {
                                                if(itr->ip == d.sender && itr->port == d.port){
                                                        ServPlayer p = *itr;
                                                        cout << "Test: " << p.ip.toString() << endl;
                                                }
                                        }
                                }
                                break;
                }
        }
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        bool running = true;
        sf::Thread thread(&netThread, &running);
        thread.launch();

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

                window.clear();
                vector<ServPlayer>::iterator itr;
                for ( itr = players.begin(); itr != players.end(); ++itr )
                        window.draw(itr->spr_player);
        window.display();
    }
        running = false;
    return 0;
}
 

ServPlayer.cpp:
#include "ServPlayer.h"
#include <cstdlib>
#include <iostream>

ServPlayer::ServPlayer(){

}

ServPlayer::ServPlayer(IpAddress ip, unsigned short port){
        this->ip = ip;
        this->port = port;
        /* initialize random seed: */
        srand ( time(NULL) );

        /* generate secret number: */
        int num = rand() %10 + 1;
        std::cout << num << std::endl;

        if(!img_player.loadFromFile("Images\\spr_player.png")){
                //Error
        }
        spr_player.setTexture(img_player);
        spr_player.setPosition(50 + (50+num), 50 + (50+num));
        spr_player.setOrigin(img_player.getSize().x/2, img_player.getSize().y/2);
}
 

Is it possibly because:
- I'm using players as a global variable?
- I'm using a different thread?

12
Network / Re: Check when someone has disconnected from my UDP socket?
« on: October 06, 2012, 08:48:23 am »
All right thanks for elaborating that.
Exactly how often do you think I should be pinging? Or I suppose it wouldn't really matter,
just as long as I'm not using up a ton of bandwidth?

13
Network / Check when someone has disconnected from my UDP socket?
« on: October 05, 2012, 11:10:44 pm »
In my UDP server, I'm trying to find out when a client has "disconnected".
Obviously, this makes more sense if I were using a TCP socket but UDP is not "connected".

One way I thought of was having the server constantly send a message to the client,
and if it was not able to contact it, we determine that client to be "disconnected", but this seems
highly inefficient.

Does anyone know the proper way to test if someone is disconnected?

I'm not talking about when the user closes the window, I mean if for any reason the user is actually
NOT in the server (i.e., client crashed, client's internet d/c, etc.)

14
Network / Re: writebyte() implementation
« on: October 03, 2012, 12:31:47 am »
Thanks got it!

15
Graphics / Re: SFML 2.0 Missing text characters in Linux.
« on: October 02, 2012, 11:08:50 pm »
Thanks!

Pages: [1] 2
anything