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

Pages: [1]
1
Graphics / Re: SFML 2.0 and OpenGL texture mapping problem
« on: November 28, 2012, 06:43:22 am »
Thank you. I replaced all the OpenGL texture binding calls to only one sf::Texture::bind() call and everything worked fine. Not only easier, but saves much of typing. But I still don't understand why it didn't work previously.

2
Graphics / SFML 2.0 and OpenGL texture mapping problem
« on: November 27, 2012, 05:07:55 pm »
Hello, I have a problem which I seem can't fix. I tried using everything in the past few hours, nothing worked. Essentially what I'm trying to do just bind some 128x128 .png format texture on to a square in OpenGL with SFML 2.0. I got no errors, but all I can see is white square and thats all. Here's the simplified code I'm trying to get to work:

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

using namespace std;

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

        glViewport(0,0,800,600);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glEnable(GL_TEXTURE_2D);
        glOrtho(0,800,0,600,1,-1);

        sf::Image texture;
        texture.loadFromFile("Resources/texture.png");

        GLuint id;
        glGenTextures(1,&id);
        glBindTexture(GL_TEXTURE_2D,id);
        glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,128,128,0,GL_RGBA,GL_UNSIGNED_BYTE,texture.getPixelsPtr());

        unsigned short indices[6] = {0,1,2,2,3,0};
        float vertices[8] = {100,100,
                                                200,100,
                                                200,200,
                                                100,200};

        float textureCoords[8] = {0.0f, 1.0f,
                             1.0f, 1.0f,
                             1.0f, 0.0f,
                             0.0f, 0.0f};
       
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        glVertexPointer(2,GL_FLOAT,0,vertices);
        glTexCoordPointer(2,GL_FLOAT,0,textureCoords);

       

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

        }
                glClear(GL_COLOR_BUFFER_BIT);
                glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_SHORT, indices);
                window.display();
        }

        return 0;
}

I also tried using gluBuild2DMipmaps() instead of glTexImage2D() but I got some very strange artifacts in my texture, it doesn't even look like my texture anymore, it just KIND OF has same colors but it is very distorted and looks random.
Maybe i'm doing something wrong? How do you bind textures to your OpenGL games/applications?
I ported this code from Android OpenGL example from a book which i'm reading, and there it works fine.

Thanks for your help in advance.

3
Network / Re: Could someone explain me this?
« on: June 24, 2012, 05:10:53 pm »
Wait() returns the number of sockets that are ready for reading, not the total number of sockets that the selector contains. It would be very hard to get two sockets ready at the exact same moment (you'd need at least two clients, and a lot of luck).

You should really learn more about the basics of networking before trying to do something with SFML. The API doc and tutorials won't teach you how to write a network program.
Do you have any recommendations? Sites, forums maybe?

4
Network / Re: Could someone explain me this?
« on: June 23, 2012, 08:33:24 am »
Ok, but after int Sockets = Selector.Wait(); I have put cout << "Sockets: " << Sockets << endl;
and it always show that it has only 1 socket, even after I connect one more.
So Selector.Add(Listener); would be first socket, and Selector.Add(Client); should be second, but it always shows only 1 socket...

5
Network / Could someone explain me this?
« on: June 22, 2012, 09:24:56 pm »
#include <SFML/Network.hpp>
#include <iostream>

using namespace std;

int main()
{
        sf::SocketTCP Listener;

        Listener.Listen(2435);

        sf::SelectorTCP Selector;

        cout << "Waiting for port 2435 connection" << endl;

        Selector.Add(Listener);

        while(true)
        {
               
                int Sockets = Selector.Wait();
                cout << "Sockets: " << Sockets << endl;

                for(int i = 0; i < Sockets; i++)
                {
                        sf::SocketTCP Socket = Selector.GetSocketReady(i);
                        cout << "For loop after Selector.GetSocketReady(i);" << endl;

                        if(Socket == Listener)
                        {
                                sf::IPAddress adress;
                                sf::SocketTCP Client;
                                Listener.Accept(Client,&adress);

                                cout << "Address " << adress << " connected" << endl;
                               
                                Selector.Add(Client);
                        }
                        else
                        {
                                sf::Packet packet;
                                if(Socket.Receive(packet) == sf::Socket::Done)
                                {
                                        string String;
                                        packet >> String;
                                        cout << String << endl;
                                }
                                else
                                {
                                        cout << "Disconnected" << endl;
                                        Selector.Remove(Socket);
                                }
                        }
                }

        }

    return EXIT_SUCCESS;
}
 



I can't understand some things here... Because SFML documentation sucks.

So my first question is what is:
what Selector.GetSocketReady(i) does really return?
And what is if(Socket == Listener)?
And why doesn't Socket always equal to Listener?
This is soo strange. I don't get it. It is equal to Listener just when someone connects, but after that its not...

Could someone help me understand this?

Pages: [1]
anything