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

Pages: 1 [2] 3
16
Very very nice!

Quote
I'll write an article about it later


Please do so.

17
Graphics / Crazy bug using OpenGL lighting and RenderWindow
« on: May 12, 2011, 10:10:19 pm »
After I tried a lot to solve it I decided to show this to you guys.

I am pretty sure the code should be correct this way.
Sorry, but it can't be smaller:
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
    sf::Clock clock;
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML + OpenGL", sf::Style::Default, sf::ContextSettings(32));

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(70.f, App.GetWidth() / App.GetHeight(), 1.f, 600.f);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
    GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat light_position[] = {0.0, 0.0, 1.0, 0.0};

    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    float red[] = {102.f/255.f, 51.f/255.f, 51.f/255.f};
    float blue[] = {51.f/255.f, 51.f/255.f, 102.f/255.f};
    float green[] = {51.f/255.f, 102.f/255.f, 51.f/255.f};


    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();

            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }

        App.SaveGLStates();
        App.Clear(sf::Color(0, 0, 0, 1));
        App.RestoreGLStates();

        //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClear(GL_DEPTH_BUFFER_BIT);

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

        // Draw a cube
        glBegin(GL_QUADS);

            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
            glColor3f(1.f, 0.f, 0.f);
            glNormal3f(0.f, 0.f, -1.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f( 50.f,  50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);

            glColor3f(1.f, 0.f, 0.f);
            glNormal3f(0.f, 0.f, 1.f);
            glVertex3f(-50.f, -50.f, 50.f);
            glVertex3f( 50.f,  -50.f, 50.f);
            glVertex3f( 50.f,  50.f, 50.f);
            glVertex3f(-50.f,  50.f, 50.f);

            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
            glColor3f(0.f, 1.f, 0.f);
            glNormal3f(-1.f, 0.f, 0.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f(-50.f,  50.f,  50.f);
            glVertex3f(-50.f, -50.f,  50.f);

            glColor3f(0.f, 1.f, 0.f);
            glNormal3f(1.f, 0.f, 0.f);
            glVertex3f(50.f, -50.f, -50.f);
            glVertex3f(50.f, -50.f,  50.f);
            glVertex3f(50.f,  50.f,  50.f);
            glVertex3f(50.f,  50.f, -50.f);

            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
            glColor3f(0.f, 0.f, 1.f);
            glNormal3f(0.f, -1.f, 0.f);
            glVertex3f(-50.f, -50.f,  50.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f,  50.f);

            glColor3f(0.f, 1.f, 0.f);
            glNormal3f(0.f, 1.f, 0.f);
            glVertex3f(-50.f, 50.f,  50.f);
            glVertex3f(-50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f,  50.f);

        glEnd();

        App.Display();
    }
    return EXIT_SUCCESS;
}


The bug is:
The two red quads don't show up.

This only happens when:
- you use lighting
- you use sf::RenderWindow instead of sf::Window (I wanted to display text, so I had to change to RenderWindow)

Crazy thing about it:
- When you change it to this the blue quads won't show up:
Code: [Select]
float blue[] = {51.f/255.f, 51.f/255.f, 102.f/255.f};
float red[] = {102.f/255.f, 51.f/255.f, 51.f/255.f};
float green[] = {51.f/255.f, 102.f/255.f, 51.f/255.f};


I am using SFML2 and CodeBlocks + MinGW.

Any ideas?

18
Network / Client fails to bind in separate thread
« on: May 12, 2011, 04:33:55 pm »
Code: [Select]
for(int i = 0; i < sizeof(buf); i++){
    buf[i - 1] = buf[i];
}

Code: [Select]
for(int i = 0; i < sizeof(buf); i++){
    buf[i - 1] = buf[i];
}


In both examples you access buf[-1] which is illegal.

19
System / Clock::GetElapsedTime () in milliseconds
« on: May 10, 2011, 10:35:16 pm »
The definition is:
Quote
float sf::Clock::GetElapsedTime()


I am sure you are doing this:
Code: [Select]
int a = clock.GetElapsedTime();
This int just holds seconds since the return value is rounded.

Try this:
Code: [Select]
float a = clock.GetElapsedTime();

Edit: too late..

20
General / Problems with linking SFML2 static
« on: May 10, 2011, 02:44:50 pm »
Thank you!
Wasn't it the other way around in SFML 1.x? That you had to define a DYNAMIC macro? (I'm not sure about it since I never really worked with it)

21
General / Problems with linking SFML2 static
« on: May 08, 2011, 09:18:17 pm »
Hey. I have some problems linking a test .cpp against the static sfml2 libraray with codeblocks.

Code: [Select]
// No comments on the code please xD
#include <SFML/System.hpp>

int main ()
{
    sf::Clock clock;
    return clock.GetElapsedTime();
}


I build the SFML2 Lib static and dynamic without any errors with cmake and the mingw32 makefile.

When I link against "libsfml-system-s.a" there is this error:
Quote
obj\Release\main.o:main.cpp|| undefined reference to `_imp___ZN2sf5ClockC1Ev'|
obj\Release\main.o:main.cpp|| undefined reference to `_imp___ZNK2sf5Clock14GetElapsedTimeEv'|
||=== Build finished: 2 errors, 0 warnings ===|


When I link against "libsfml-system.a" there is no error. Also the examples work when they are created with the static library. Whats up with that?

22
General / Question about "make all"
« on: April 30, 2011, 05:48:22 pm »
I did. Thats not the problem.
My question is why do I have to do that:
Code: [Select]
make all
make doc

instead of
Code: [Select]
make all
To build everything.

When I don't set BUILD_DOC it's clear why it should not build the docs.

23
Network / How to dev an online server for a simple game
« on: April 30, 2011, 04:57:54 pm »
Quote
I just done 1/2game with client and server on my local net but
now I want to understand if is possible to put the server side of game on an online shared server.


If you have done a client/server game it should be simple to do that. There really is nothing changing but that it is running over the internet and you can't use your local IPs to acces the server.

Quote
I want to know if I can use SFML libs on a game server. And Graph-Lib?


Yes, of course you can! For your server you normally don't need any graphics.

Quote
This is a strategic game with a very small use of TCP pakets but I think that here we have a bad ADSL line to do that in home.


Just check how much bandwidth your game needs in your local network and then check how fast your line is. For a game with many players you will need a computer with a fast acces to the internet though.

Quote
Where can I found info about small online server for my small game?


There are many tutorials about that I think. The SFML example/tutorials for networking will help you to understand how SFML handles it.
http://gamedev.net/ is always a good resource.

I hope that helps you :)

24
General / Question about "make all"
« on: April 30, 2011, 04:35:02 pm »
Is there a reason why "make all" only creates targets that produce a binary?
Wouldn't it be useful to produce the doc target, too?

25
SFML wiki / /!\ List of GUI based on SFML /!\
« on: April 28, 2010, 09:56:28 pm »
I don't like that all that projects are in French :(
They look awesome but I can't work with them because I can't read French that well. Why isn't there just one English forum and just English projects? I think everybody should know English if he wants to work with the computer.

26
Window / A way to get sf::Style of an existing window
« on: April 21, 2010, 09:28:54 pm »
Quote
I don't like the idea of putting a pair of getter/setter for every member of every class. Classes provide services, not data. And one service that a window provides is changing its title. Retrieving it is another service that is much less relevant (in my opinion).


I see what you mean. My opinion is that a class should have a method to get each member that it can set. It makes everything a lot easier.

Maybe a simple solution would be if the sf::Style would be added to the sf::WindowSettings member of the sf::Window. What do you think?

27
Window / A way to get sf::Style of an existing window
« on: April 21, 2010, 07:45:10 pm »
Is there going to be one one in 2.0 or is there a reason why there is none?

28
Window / A way to get sf::Style of an existing window
« on: April 21, 2010, 07:29:11 pm »
Is there a way to get the style of a window that exists?
I want to check if my window is fullscreen and didn't find a function for that purpose in the documentation.

29
Network / Client managing
« on: February 20, 2010, 10:50:30 pm »
Thank you very much, Laurent!
It is working correctly now.

I like your way of helping people.

warm regards,
PhiLLe

30
Network / Client managing
« on: February 20, 2010, 06:55:11 pm »
player.h
Code: [Select]
#ifndef __PLAYER__
#define __PLAYER__

#include <SFML/Network.hpp>

class Player : sf::NonCopyable {
    public:
       
        ~Player()
        {
            Socket.Close();
        }

        Player(sf::SocketTCP Client)
        {
            Socket = Client;
        }

        sf::SocketTCP Socket;
};

#endif


main.cpp
Code: [Select]
#include <iostream>
#include <vector>
#include <SFML/Network.hpp>
#include "player.h"
using namespace std;

std::vector<Player *> Clients;
sf::Mutex GlobalMutex;

void Accept(void * UserData)
{
    sf::SocketTCP Listener;

    if (!Listener.Listen(1234))
        cerr << "Clouldn't Bind to port: " << 1234 << endl;

    while (true)
    {
        sf::SocketTCP Client;
        if (Listener.Accept(Client) == sf::Socket::Done)
        {
            GlobalMutex.Lock();
            Clients.push_back(&Player(Client));
            GlobalMutex.Unlock();

            cout << "New connection" << endl;
        }
    }
   
    Listener.Close();
}

int main()
{
    sf::Thread Taccept(Accept);

    Taccept.Launch();

    while (true)
    {
        sf::Packet packet;
        sf::Int8 GameChar = 'P';
        packet << GameChar;
 
        GlobalMutex.Lock();
        for (unsigned int i = 0; i < Clients.size(); i++)
        {
            sf::Socket::Status status = Clients.at(i)->Socket.Send(packet);
            cout << "Socket " << i << ": ";
            if (status == sf::Socket::Error)
                cout << "Error" << endl;
            else if (status == sf::Socket::Disconnected)
                cout << "Disconnected" << endl;
            else if (status == sf::Socket::NotReady)
                cout << "NotReady" << endl;
        }
        GlobalMutex.Unlock();
        sf::Sleep(0.5);
    }

    Taccept.Terminate();

    return 0;
}

Pages: 1 [2] 3