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

Pages: [1]
1
Graphics / Re: beginning of snake
« on: August 16, 2013, 11:41:37 am »
Quote
if(dir == Down)
        {
            Snake[0].snakeblock.move(0,2);
        }
        if(dir == Left)
        {
            Snake[0].snakeblock.move(-2,0);
        }
        if(dir == Right)
        {
            Snake[0].snakeblock.move(2,0);
        }

Get rid of this.

Think about it logically.
You should do this every time you want the snake to move.

1. Create a new temporary SnakeBlock to be the new head.
  - Calculate the new global position of this new head. Use the snake's old head (snake[0]) and the direction that the snake is currently traveling in to calculate the new head position.

2. Push this SnakeBlock onto the front of the snake.

3. Pop the tail of the SnakeBlock off.

You shouldn't have to touch any other parts of the snake. Try playing it online or on a Nokia, see how the middle part of the snake stays absolutely still, only the head and tail move.

Don't worry about the snake not being able to eat himself. That's pretty trivial and not part of what you're trying to do at the moment. ;)

2
Graphics / Re: GLEW Problems (access violation error)
« on: August 15, 2013, 05:21:34 pm »
Hi Laurent, and thanks very much for the reply :)

I did what you said, and although it didn't work at first I juggled around glewInit() until it did!
It isn't working quite as it's supposed to, but as the compiler seems to be OK I think that the problems are now of OpenGL, so I should be able to hammer them out soon.

So thankyou very much Laurent or eXpl0it3r for your time, knowledge, and patience :)

3
Graphics / Re: beginning of snake
« on: August 15, 2013, 04:18:10 pm »
Good. Don't worry programming in a game-loop based way is different but you'll get used to it.

I recently read a tutorial on snake:
http://www.gamedev.net/page/resources/_/technical/game-programming/game-programming-snake-r3133


I think that the best approach is an std::vector, deque, queue of snake bits, (so you are on the right track ;) ), and then every frame:
Code: [Select]
- Calculate where the new snake's head will now be (using the 'dir' variable), and 'push' (look up vector.push_front) a new part of the snake onto the front of the vector to be it's new head.

- 'pop' from the back the tail of the snake.

You get me?

When the snake eats some food, don't do the 'pop', and obviously the snake will grow by one bit!

I think that you should work on your programming style a bit more. It's good at the moment, (and I'm glad to see no sign of 'using namespace std'), but I think it's a good idea in this case to use the fully-qualified name for enums, e.g. Direction::Up instead of Up, just for clarity. That said it's personal preference.

Also, most of your snake blocks will have the same texture so perhaps you should make the SnakeBlock's texture member a pointer. This means you're not saving so many copies of the same texture, and if you change the texture for one of the blocks they will all change, but this is up to you.

4
Graphics / Re: beginning of snake
« on: August 15, 2013, 03:16:32 pm »
I think that you're new to loop-based game programming.

You need to think about this:
  while(dir == Up) { ... }

Remember that if you don't change 'dir' in that while loop, then you will be stuck in that while loop forever, not giving SFML a chance to redraw your window- so nothing will happen.
I think that changing the 'while's to 'if's might help  ;)

Remember that for anything to happen on the screen you need to get to the bottom of your game loop.

5
Graphics / Re: GLEW Problems (access violation error)
« on: August 15, 2013, 03:11:27 pm »
Using Vertex Buffer Objects, i.e. though the glGenBuffers() etc. functions.
These functions are part of (afaik) OpenGL extensions, which require GLEW (or GLEE) to run.
I can't get GLEW to run properly in an SFML based context.

6
Graphics / Re: GLEW Problems (access violation error)
« on: August 15, 2013, 03:00:00 pm »
Thanks.

Yeah I know, but if you look at my edit above, to be honest I have tried mostly everything...
And I'd prefer to use the static SFML libraries.

I frustratingly see other projects using VBOs successfully with SFML but with little explanation.


I personally, but I think that  the community as a whole would really appreciate it the SFML team could demonstrate the correct method of using GLEW and SFML perhaps in a tutorial, or if the GLEW mess was fixed so the correct way would become self-evident.

Using GLEW seems like a pretty basic part of SFML, especially for 3D applications like mine where using immediate OpenGL commands is useless and also deprecated, and VBOs, VAOs, etc. are becoming the standard.

7
Graphics / Re: GLEW Problems (access violation error)
« on: August 15, 2013, 01:57:27 pm »
Okay, thanks for the reply  :).

I reverted back to the static glew32s.lib library, and I moved glewInit() to the very top of main().

However, VC++2010 complains that:

1>sfml-graphics-s-d.lib(glew.obj) : error LNK2005: ___glewCopyTexSubImage3D already defined in glew32s.lib(glew.obj)
1>sfml-graphics-s-d.lib(glew.obj) : error LNK2005: ___glewDrawRangeElements already defined in glew32s.lib(glew.obj)
... (about a few hundred similar lines)

This is the problem I had with the static library before: SFML hides GLEW enough that we aren't allowed to use it, but not enough that we can run our own copy as well...?

What do you think?

Edit

I tried *not* linking and including the glew32s.lib library- I thought since SFML has included the GLEW library already it is pointless. This seems to work, and the duplicate object errors are not there- however glGenBuffers is still 0x00...

Also, now glewInit() is an unresolved external symbol. I think that maybe that SFML will do this to stop it being called twice, as it is called as part of the SFML load-up? However as I said glGenBuffers is still null...

8
Graphics / GLEW Problems (access violation error)
« on: August 15, 2013, 12:48:32 pm »
Hi all,

I recently ran into some trouble trying to get GLEW working in SFML.
Currently the SFML libraries are static, and the GLEW library is dynamically linked- with a DLL in beside the .exe, is this correct?

The problem is that when I try and use any of the GL extensions I get an access violation error:

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "Test", sf::Style::Default, sf::ContextSettings(32));

        glewExperimental = GL_TRUE;
       
         GLenum glewErr = glewInit();

         if (glewErr != GLEW_OK)
                 std::cout << "GLEW not OK...";
         else
                 std::cout << "GLEW is OK...";

         if (!GLEW_ARB_vertex_buffer_object)
         {
                std::cout << "Not supported...";
         }

         unsigned int temp = 0;
         glGenBuffers(1,&temp); // Access violation reading '0x000...'
 

Visual C++ throws an access violation error at the glGenBuffers line.
Most similar problems I see online are because of omitting 'glewInit()', or 'glewExperimental = GL_TRUE'.

Is it possibly a problem with the way I have set up GLEW?

(glewInit returns GLEW_OK, and by using glGetString(GL_EXTENSIONS) [or something] I am sure that my drivers support VBOs, they are part of the standard anyway aren't they?)

Any help would be much appreciated,
thanks.

9
Why can't you just say to the sprite:
' Move to the next tile, if I am there, then move to the next tile'?

if (sprite_position == next_tile_centre)
{
    next_tile_centre = best_path.at( next_tile_id )
}

sprite_position = sprite_position + (next_tile_centre / player_speed)?
 
?

Or am I not getting your question?

10
Graphics / Re: Using SFML with OpenGL (conflicts with GL states)
« on: July 29, 2013, 02:56:10 pm »
Just in case anyone is reading this- I upgraded to SFML 2.1 and the problem is fixed. Merci Laurent!

11
Graphics / Re: Using SFML with OpenGL (conflicts with GL states)
« on: July 27, 2013, 03:49:36 pm »
Thanks for the reply.
Is this OK? Any ideas?
It still DOES NOT rotate when the three SFML lines exist, but DOES when they are commented out.

EDIT:When I use a texture mapped 3D model, the model stays still but the texture rotates in strange ways. As usual, when I get rid of the SFML code all is OK.

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "Test-Project", sf::Style::Default, sf::ContextSettings(32));
        window.setVerticalSyncEnabled(true);
        window.setKeyRepeatEnabled(true);

        sf::Font font;
        font.loadFromFile("C:\\WINDOWS\\Fonts\\arial.ttf");
        sf::Text text;
        text.setFont(font);
        text.setCharacterSize(30);
        text.setStyle(sf::Text::Bold);
        text.setColor(sf::Color::Red);
       
        vector3D screenSize(640.0f,480.0f);

        float clip_near = 0.1f, clip_far = 100.0f;
        glViewport(0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective( 75.0f, screenSize.x / screenSize.y, clip_near, clip_far);
        glMatrixMode(GL_MODELVIEW);

        float sceneRotation = 0.0f; // degrees

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

                glClearColor(0.5f,0.5f,0.5f,1.0f);
                glClearDepth(1.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glLoadIdentity();

                glEnable(GL_DEPTH_TEST);
                glEnable(GL_LIGHTING);
                glEnable(GL_LIGHT0);

                glColor3f(1.0f,0.0f,0.0f);
                glTranslatef(0.0f,0.0f,-4.0f);

                sceneRotation += 3;
                glRotatef(sceneRotation,0.0f,1.0f,0.0f);

                if (sceneRotation > 360)
                        sceneRotation = 0;

float radius = 1.0f;
                glLineWidth(3.0f);
        glBegin(GL_LINES);
        glVertex3f(-radius,-radius,-radius);
        glVertex3f(radius,-radius,-radius);
        glVertex3f(radius,radius,-radius);
        glVertex3f(-radius,radius,-radius);
        glVertex3f(-radius,-radius,radius);
        glVertex3f(radius,-radius,radius);
        glVertex3f(radius,radius,radius);
        glVertex3f(-radius,radius,radius);
        glVertex3f(-radius,-radius,radius);
        glVertex3f(-radius,-radius,-radius);
        glVertex3f(-radius,radius,-radius);
        glVertex3f(-radius,radius,radius);
        glVertex3f(-radius,-radius,-radius);
        glVertex3f(-radius,-radius,radius);
        glVertex3f(-radius,radius,radius);
        glVertex3f(-radius,radius,-radius);
        glVertex3f(-radius,-radius,-radius);
        glVertex3f(-radius,radius,-radius);
        glVertex3f(radius,-radius,-radius);
        glVertex3f(radius,radius,-radius);
        glVertex3f(radius,-radius,radius);
        glVertex3f(radius,radius,radius);
        glVertex3f(-radius,-radius,radius);
        glVertex3f(-radius,radius,radius);
        glEnd();

                // Start of problem lines
                window.pushGLStates();
                window.draw(text);
                window.popGLStates();
               // End of problem lines.

                window.display();
        }
        return 0;
}

12
Graphics / [SOLVED] Using SFML with OpenGL (conflicts with GL states)
« on: July 26, 2013, 07:18:33 pm »
Hi,
I am using SFML with OpenGL in my tiny application. I have simplified the code down to the following:

int initiateGame(void) {

        vector3D screenSize(640.0f,480.0f);

        float clip_near = 0.1f, clip_far = 100.0f;
        glViewport(0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective( 75.0f, screenSize.x / screenSize.y, clip_near, clip_far);
        glMatrixMode(GL_MODELVIEW);
        return 0;
};


int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "Test-Project", sf::Style::Default, sf::ContextSettings(32));
        window.setVerticalSyncEnabled(true);
        window.setKeyRepeatEnabled(true);

        sf::Font font;
        font.loadFromFile("C:\\WINDOWS\\Fonts\\arial.ttf");
        sf::Text text;
        text.setFont(font);
        // (set the rest of the text attributes)

        initiateGame();

        float sceneRotation = 0.0f; // degrees

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

                glClearColor(0.5f,0.5f,0.5f,1.0f);
                glClearDepth(1.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glLoadIdentity();

                glEnable(GL_DEPTH_TEST);
                glEnable(GL_LIGHTING);
                glEnable(GL_LIGHT0);

                glColor3f(1.0f,0.0f,0.0f);
                glTranslatef(0.0f,0.0f,-4.0f);

                sceneRotation += 3;
                glRotatef(sceneRotation,0.0f,1.0f,0.0f);

                if (sceneRotation > 360)
                        sceneRotation = 0;

                drawSolidSphere(1.0f,4,4);

                // Start of problem lines
                window.pushGLStates();
                window.draw(text);
                window.popGLStates();
               // End of problem lines.

                window.display();
        }
        return 0;
}

Like this, the sphere is drawn (and translated) but NOT rotated.
If I comment out the three 'problem lines', then the text disappears (obviously) and the sphere spins.

When I add in the rest of my code, if I glEnable(GL_CULL_FACE), then the SFML text dissapears. Surely any OpenGL calls should not affect SFML text, provided the drawing of the SFML text is surrounded by window.pushGLStates() and window.popGLStates()?

Why is this happening?
I read on the wiki that I must do my OpenGL stuff, call 'pushGLStates', do my SFML stuff, then call 'popGLStates'. I thought that this is what I am doing at the moment but it is evidently not working.

Any help would be much appreciated,

Thanks

13
Graphics / Re: Graphics Stretching on Window Resize
« on: March 28, 2013, 07:56:13 pm »
Thanks very much I got it working! :)

mike38

14
Graphics / Graphics Stretching on Window Resize
« on: March 27, 2013, 06:38:19 pm »
Hi all,

I've been using SFML for a while now and it's a fantastic package; I extend my thanks to all involved in the creation and development.

I have been using an OpenGL background and SFML text in my 2D scene. Everything works great apart from when I resize the window.  I want the OpenGL background to resize with the window, but the SFML text to stay at the same size and proportion affixed in the upper left.

However, on resizing the window the text appears stretched (as if I was scaling everything) for a split second, then returns to it's original size. The OpenGL background scales correctly. You can see this in the following image (the text is slightly stretched horizontally):



(after a split second the text returns to normal.)

Here's the relevant code. Sorry if it seems long but I have no idea where the annoying behavior is coming from.

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), _PROGRAM_NAME, sf::Style::Default,    

        resizeOpenGLWindow(window.getSize().x,window.getSize().y);

        DocumentView mainDocumentView(window);

        mainDocumentView.setup(vector2D(0,0),vector2D(0,0),
                10.0f,sf::Color::White,sf::Color::Black,
                mainDocumentFont);

 while (applicationState.isRunning)
 {     
                applicationState.view = sf::View(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
                window.setView(applicationState.view);
                handleEvents(&window,&applicationState); // handleEvents calls 'resizeOpenGLWindow' and resizes the mainDocumentView

                 // set up mainDocumentView
       
                glClearColor(1.0f,1.0f,1.0f,1.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glLoadIdentity();
               
                mainDocumentView.update();
                window.display();      
 }
    return 0;
}

This essentially is updating the text:

int DocumentView :: update()
{

         drawRichString(vector2D(topLeft.x + textMargin,topLeft.y + textMargin),
                document.at(0).text,mainDocumentFont,textColour,
                linkedRenderWindowPointer);
         
        return 0;
}

And the graphics functions:

void resizeOpenGLWindow(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, 1);
    glMatrixMode(GL_MODELVIEW);
       
}
void drawRichString(vector2D position, RichString richString,sf::Font font,sf::Color textColour, sf::RenderWindow & renderWindow)
{
        renderWindow.pushGLStates();
        float characterWidth;
        float lastCharacterWidth;
        currentDrawText.setColor(textColour);

        for (loopCounterType currentDrawCharacter = 0;
                currentDrawCharacter < richString.characters.size();
                currentDrawCharacter++)
        {
                currentDrawText.setFont(font);
                lastCharacterWidth = currentDrawText.getFont().getGlyph(currentDrawText.getString().getData()[0],
                        currentDrawText.getCharacterSize(),false).advance;
                currentDrawText.setString(richString.characters.at(currentDrawCharacter).rawChar);
                                       
                currentDrawText.setPosition(position.x +
                        (float(currentDrawCharacter) * lastCharacterWidth)
                        ,position.y);

                renderWindow.draw(currentDrawText);
                               
        }
        renderWindow.popGLStates();
}

If you feel you need more information I would be more than happy to supply you.

Thanks in advance,

mike38


Pages: [1]
anything