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

Pages: [1] 2 3 4
1
General / Re: Is this gonna be easy to make?
« on: March 08, 2015, 01:29:41 am »
Are you thinking of something along the lines of TripleA?

http://triplea.sourceforge.net/mywiki

If you are, from the perspective of handling your graphics, audio, and input, then yes, SFML will be far and away the best choice for a project like this. But the game mechanics might prove a bit trickier, not the least of being writing a competitive AI for a game like this.

2
What did you change with it to get it working? I havent had any luck with it so far.

3
Thanks for posting those links, they look very helpful. In the case of the first shader, what drawable entity would I apply it to in SFML, the planets rectangular texture map?

4
Fixed the code above, it should at least compile, I am using g++ with SFML 2.1. My apologies, I was editing the code before I posted, and I should have checked before putting it in the post.

Yes, I have read some of the documentation on OpenGL, and I have read all of the tutorials for SFML, if not the entire API documentation top-to-bottom. The problem I am finding is that most OpenGL tutorials are written for glut or other windowing systems, perhaps I would be better off working through a tutorial written for a different windowing system?

5
Graphics / What else do I need to call besides sf::Texture::Bind() ?
« on: March 05, 2015, 12:32:34 am »
Okay, so I am trying to create a program with a textured openGL cube,

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

#define cameraMove 6


void Draw_cube(float size, sf::Image &sideFace);
void Draw_cube_texed(float size, sf::Texture &sideFace);
void Draw_point(float x, float y, float z);
void Draw_pyramid();

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);

    // load resources, initialize the OpenGL states, ...

        glClearDepth(1.0f);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        // ummm just transparent apparently
       
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);  
        glDepthMask(GL_TRUE);
       
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(90.0f, 1.0f, 1.0f, 500.0f);

        float cubeSize = 20;

        float cameraDistance = -200;

        sf::RectangleShape rect(sf::Vector2f(1500, 50));
        rect.setFillColor(sf::Color(0, 255, 0, 128));
       
        sf::Texture cubeFace;
        if(!cubeFace.loadFromFile("./crate.png"))
        {       std::cout << "Unable to load image from file" << std::endl;
                return -1;
        }
       

        sf::Clock clock;
    // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
                // this would be better done with forcing the window size back
                // to some constant values
           
                                // or at least forced to a specific scale, as if you change the
                                // width/height ratio, the image ends up being distorted
            }
            if(event.type == sf::Event::KeyPressed)
                        {       if(event.key.code = sf::Keyboard::Up)
                                {       cubeSize += 1;
                                }
                                if(event.key.code = sf::Keyboard::Down)
                                {       cubeSize -= 1;
                                }
                        }
                        if(event.type == sf::Event::MouseWheelMoved)
                        {       cameraDistance += event.mouseWheel.delta*cameraMove;
                        }
                       
                       
        }

        // clear the buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // erases any previously drawn stuff...
       
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        // beats me...
        glTranslatef(0.0f, 0.0f, cameraDistance);
        // what the, why does it translate every frame
               
                // ohhh, so we can be 200 units back from wherever the
               
                glRotatef(20*cos((clock.getElapsedTime().asSeconds()*0.5)), 1.f, 0.f, 0.f);
                glRotatef((clock.getElapsedTime().asSeconds()*30), 0.f, 1.f, 0.f);
                //glRotatef((clock.getElapsedTime().asSeconds()*90), 0.f, 0.f, 1.f);
                // rotate the camera view a wee bit

                // lets just try with the z axis rotate
                // okay, no
               
                // that does not work

        // draw...
                Draw_cube_texed(cubeSize, cubeFace);
                //Draw_pyramid();
               

               
               
                Draw_point(25, 25, 25);
                window.pushGLStates();

                window.draw(rect);

                window.popGLStates();
               
                int points = std::rand()%10 + 1;
                for(int cy = 0; cy != points; ++cy)
                {       Draw_point((20 + std::rand()%10),(20 + std::rand()%10),(20 + std::rand()%10));
                }
                // kewl

        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

    // release resources...

    return 0;
}

void Draw_cube(float size, sf::Texture &sideFace)
{       glBegin(GL_QUADS);

        glColor3f(0,0,255);
        // lancelots favourite cube
       
        // I dont care if the joke is old by now dammit!

        glVertex3f(-size, -size, -size);
        glVertex3f(-size,  size, -size);
        glVertex3f( size,  size, -size);
        glVertex3f( size, -size, -size);
        // I guess we define them one at a time in sets of four, hence the quads
        // part...
               
        // and each set of four defines a face...


        sf::Texture::bind(&sideFace);  
        //glTexture
        //glColor3f(255,255,255);
        glNormal3f(0.0, 0.0, 1.0f);
        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);
        //sf::Texture::bind(NULL);     
       
       
        glColor3f(128,128,0);
       
        glVertex3f(-size, -size, -size);
        glVertex3f(-size,  size, -size);
        glVertex3f(-size,  size,  size);
        glVertex3f(-size, -size,  size);

        glColor3f(255,0,0);

        glVertex3f(size, -size, -size);
        glVertex3f(size,  size, -size);
        glVertex3f(size,  size,  size);
        glVertex3f(size, -size,  size);

        glColor3f(128,0,128);

        glVertex3f(-size, -size,  size);
        glVertex3f(-size, -size, -size);
        glVertex3f( size, -size, -size);
        glVertex3f( size, -size,  size);

        glColor3f(0,0,255);

        glVertex3f(-size, size,  size);
        glVertex3f(-size, size, -size);
        glVertex3f( size, size, -size);
        glVertex3f( size, size,  size);



        glEnd();
}

void Draw_point(float x, float y, float z)
{       glBegin(GL_POINTS);
        glColor3f(255,0,0);
        // aha, that works nicely
        glVertex3f(x, y, z);
        glEnd();
}

void Draw_pyramid()
{
       
                glBegin(GL_TRIANGLES);                                                          // Start Drawing A Triangle
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Front)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f(-10.0f,-10.0f, 10.0f);                                       // Left Of Triangle (Front)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f( 10.0f,-10.0f, 10.0f);                                       // Right Of Triangle (Front)
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Right)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f( 10.0f,-10.0f, 10.0f);                                       // Left Of Triangle (Right)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f( 10.0f,-10.0f, -10.0f);                                      // Right Of Triangle (Right)
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Back)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f( 10.0f,-10.0f, -10.0f);                                      // Left Of Triangle (Back)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f(-10.0f,-10.0f, -10.0f);                                      // Right Of Triangle (Back)
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Left)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f(-10.0f,-10.0f,-10.0f);                                       // Left Of Triangle (Left)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f(-10.0f,-10.0f, 10.0f);                                       // Right Of Triangle (Left)
        glEnd();                                                                                        // Done Drawing The Pyramid

}


void Draw_cube_texed(float size, sf::Texture &sideFace)
{       glBegin(GL_QUADS);                          // Start Drawing Quads
    // Front Face
   
        sf::Texture::bind(&sideFace);  
   
    glNormal3f( 0.0f, 0.0f, 1.0f);                  // Normal Pointing Towards Viewer
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 1 (Front)
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 2 (Front)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Front)
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 4 (Front)
    // Back Face
    glNormal3f( 0.0f, 0.0f,-1.0f);                  // Normal Pointing Away From Viewer
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Back)
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 2 (Back)
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 3 (Back)
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 4 (Back)
    // Top Face
    glNormal3f( 0.0f, 1.0f, 0.0f);                  // Normal Pointing Up
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 1 (Top)
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 2 (Top)
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Top)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 4 (Top)
    // Bottom Face
    glNormal3f( 0.0f,-1.0f, 0.0f);                  // Normal Pointing Down
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Bottom)
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 2 (Bottom)
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 3 (Bottom)
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 4 (Bottom)
    // Right face
    glNormal3f( 1.0f, 0.0f, 0.0f);                  // Normal Pointing Right
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 1 (Right)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 2 (Right)
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Right)
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 4 (Right)
    // Left Face
    glNormal3f(-1.0f, 0.0f, 0.0f);                  // Normal Pointing Left
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Left)
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 2 (Left)
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 3 (Left)
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 4 (Left)
        glEnd();                                // Done Drawing Quads
}

But when I run the function void Draw_cube_texed(float size, sf::Texture &sideFace) in my event loop with a properly loaded texture the cube appears without being textured. What else do I need to include in the function call for the texture to be mapped to the sides of the cube?

6
In the API docs? Theres nothing about it in here:

http://www.sfml-dev.org/tutorials/2.2/window-opengl.php

Edit: nevermind, found it. How exactly would I break up a rectangular texture into triangles though?

7
Weirdly enough, it works even without that. My link settings are

g++ hellogl.o -o hellogl -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

and it works.

So I guess the only way of rendering a textured sphere would be to do it as a set of triangles, like described here:

http://stackoverflow.com/questions/7687148/drawing-sphere-in-opengl-without-using-glusphere

But in order to texture it I will need to somehow break up the image of the planet into triangular segments and map them to each triangle in the sphere. Is there a way to load a sf::Texture and map it to a openGL entity?

8
Wait, really? So I can just call OpenGL calls from inside of SFML without ever needing to bother with linking to the OpenGL libraries?

I have been doing the solution with rendering a textured circle, but its really not a good fit for the task. Its hard to properly crop and center an image of a planet at ~ 1600 pixels square, so it causes a lot of problems, like the ground not corresponding to where the ground in the image is. Its a really hacky solution to be honest.

9
Okay, so I am working on a space simulator type project in 2D. The Vessels are rendered as flat sprites, which is simple enough, but for the planets and moons I would like to be able to render them as 3d spheres with a rectangular texture mapped to their surfaces. Obviously, the most direct way of doing this would be to use OpenGL, but I would rather not devote all of that time & add another dependency to my project just to do one very simple thing involving 3d graphics.

So my question was, has anyone ever developed any sort of sf::Drawable child class that can take a rectangular texture as input and draw it onscreen as a textured sphere? Or are there any other options that I am missing here that I could try instead?

10
General / Re: Trying to adapt the TileMap example to a class
« on: February 17, 2015, 01:18:04 am »
Yeah, I see it now, the return call is one loop too high  ::)

works perfectly now  8)

11
General / Trying to adapt the TileMap example to a class
« on: February 15, 2015, 08:52:30 pm »
Okay, so I am trying to adapt the TileMap example class found here:

http://www.sfml-dev.org/tutorials/2.2/graphics-vertex-array.php

for use in my own project.

I created a quick tileset png file:



And quickly rewrote the class in a header and cpp file:

class Planetary_surface: public sf::Drawable, public sf::Transformable
{       public:
        bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);
        private:
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

    sf::VertexArray m_vertices;
    sf::Texture m_tileset;
};

and cpp

bool Planetary_surface::load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{       // load the tileset texture
        if(!m_tileset.loadFromFile(tileset))
        {       return false;
        }
        // resize the vertex array to fit the level size
        m_vertices.setPrimitiveType(sf::Quads);
        m_vertices.resize(width * height * 4);
        // populate the vertex array, with one quad per tile
        // why is it 4 though...
        for(unsigned int i = 0; i < width; ++i)
        {       for(unsigned int j = 0; j < height; ++j)
                {       // get the current tile number
                        int tileNumber = tiles[i+(j*width)];
                        // find its position in the tileset texture
                        int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                        int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);
                        // get a pointer to the current tile's quad
                        sf::Vertex* quad = &m_vertices[(i + j * width) * 4];
                        // define its 4 corners
                        quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                        quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                        quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                        quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
                        // define its 4 texture coordinates
                        quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                        quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                        quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                        quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
                }
                return true;
        }
}


void Planetary_surface::draw(sf::RenderTarget& target, sf::RenderStates states) const
{       // apply the transform
        states.transform *= getTransform();
        // apply the tileset texture
        states.texture = &m_tileset;
        // draw the vertex array
        target.draw(m_vertices, states);
}

which seems true to the original code

But when I run it, I get this as an output:



Which has the first column drawn properly, but not the rest.

When I copy the example class as it was defined in the original document (just one big class declaration) into the main cpp and use it, it renders everything properly as expected, but when I use the class that I defined in the header/cpp file pair, I keep getting the issue with only the first column being drawn. I cant figure out how the heck that is happening.

12
SFML projects / Re: Screenshot Thread
« on: January 17, 2015, 12:54:00 am »
My current project, creating a 2d space simulator engine in C++ using SFML:



Think Kerbal Space Program and Lunar Lander fused together.

13
General discussions / Re: SFML 2.2 Released!
« on: December 19, 2014, 03:01:10 am »
Congratulations on the release, I especially like the updates to the structure of the website, they make it much easier to find information than before.  ;D

I might be willing to help contribute to the project, but Im not sure if I have the necessary background to do any good. Is there any areas in hardware specific stuff that I should know beforehand?

About the Android and ios support, thats very exciting! How exactly do things like window creation and input handling work on a mobile device work? Is the mouse just assumed to be wherever the user last touched the screen? (I checked the new tutorial docs, but there was no info there)

14
General / Re: Trying an unusual idea with audio feedback
« on: November 09, 2014, 10:18:33 pm »
Well its fairly efficient compared to the original version of the project involving a series of godawful bash scripts using xdotool, ::) but I do see what you mean. I personally would prefer to keep the project solely as a SFML app, for the sake of simplicity and maintainability. It definitely could be rewritten using OS specific calls to make it faster, but that would probably involve writing lots of ugly code couched in #ifdef statements. Windows I can probably do easily through the Windows API, although I would assume Linux could be done through the kernel? Ive never done anything linux specific in C++, so I dont know. OSX would be the biggest issue though, since I dont own a copy, & I dont really want to buy a copy just for developing stuff.

I appreciate the advice though. :)

15
General / Re: Trying an unusual idea with audio feedback
« on: November 08, 2014, 10:37:25 pm »
Thats perfect! thankyou  ;D

Its actually working right now as I type this, absolutely awesome.  8)

Unfortunately the framerate limit seems to have to be rather high in order to keep up with the rate that typing occurs at. Maybe that should be customized as well (user can input their desired frame rate so that people with really good WPM can have it higher if needed. 20 FPS seems to work well for me.

If you could refresh my memory, does calling play on the sf::Sound stop the previous instance of it being played?
(ie if Im calling chime.play(); for every keypress, does a new keypress stop the sound being played for the previous one, if the previous one was not finished?). It seems as if it is doing that, which I would like to stop if possible. Perhaps each key needs its own sf::Sound object to avoid that?

Apologies for the indenting if it is weird, I hate the ANSI-C style with the burning passion of a thousand suns, so I prefer to write code in a different style (its known as Horsttman or something like that IIRC)

Pages: [1] 2 3 4
anything