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

Pages: [1] 2
1
System / Re: [Newbie] How to use sf::Clock correctly?
« on: September 11, 2015, 11:20:57 pm »
@Brax Thanks for being the only one that bothered to answer my newbie question ;) I'm pretty sure I have clasped the concept now, cheers.

All you had to do is to read documentation.

Bit late to tell me that isn't it. Good job.

2
System / Re: [Newbie] How to use sf::Clock correctly?
« on: September 10, 2015, 07:53:37 pm »
@Brax Thanks for being the only one that bothered to answer my newbie question ;) I'm pretty sure I have clasped the concept now, cheers.

3
System / [Newbie] How to use sf::Clock correctly?
« on: September 09, 2015, 06:29:20 pm »
Hi.
Before I request for help, please bear in mind I'm pretty new to SFML so don't have a lot of knowledge on it.
I have a function in a game I am making where a clock is needed, and I want to use sf::Clock but I don't really know how. I tried but the values I get appear to be only numbers 59-64 and I don't know why. Here's my code:
sf::Clock startClock;
...
float clocktime = startClock.getElapsedTime().asSeconds();
        if (clocktime >= 5)
        {
                windowName.close();
        }

        std::cout << clocktime;
 

4
Graphics / Re: Problem with moving stuff inside a function
« on: July 12, 2015, 05:41:28 pm »
Ah, moving the rectangle before drawing it solved my newbie problem. Thanks.

5
Graphics / Re: Problem with moving stuff inside a function
« on: July 12, 2015, 05:30:12 pm »
Hi kitteh-warrior
Thanks for the help. I perhaps should of checked my code a bit first, yes I do realise it doesn't return a Boolean, what I meant (or what I should of said) was itwill return one. I have taken in what you said, but what about the problem with moving a rectangle shape? I have since improved my code, but it still wont move (In honesty I have no idea why).

6
Graphics / Problem with moving stuff inside a function
« on: July 12, 2015, 01:39:14 pm »
Hi
I decided to try and create a function that draws a button (relative to a window), and when it is pressed, it returns either true or false to a Boolean (and also moves the 'slider'). However, I could of just made a stupid mistake, but I can't seem to move anything when it is in a function. I know it cant be the code itself, as  tried moving the rectangle shape in different places of the function. Please bear in mind I don't have a lot of experience with functions, so sorry if it doesn't make much sense. To clarify, the slider (rectangleShape) or any shape does not move as intended.


void buttonSlider(int xcord, int ycord, sf::RenderWindow& windowName)
{
        bool active = false;
        sf::Vector2i mousepos = sf::Mouse::getPosition(windowName);
        sf::RectangleShape bbox(sf::Vector2f(50, 20));
        sf::RectangleShape bslider(sf::Vector2f(25, 20));
        bbox.setPosition(xcord, ycord);
        bslider.setPosition(xcord, ycord);
       
        bslider.setFillColor(sf::Color::Red);

        int xplus50 = xcord + 50;
        int yplus20 = ycord + 20;
        int sliderCordX = bbox.getPosition().x;
        int sliderCordY = bbox.getPosition().y;
        windowName.draw(bbox);
        windowName.draw(bslider);
       
if (mousepos.x >= xcord && mousepos.x < xplus50 && mousepos.y >= ycord && mousepos.y < yplus20 && sf::Mouse::isButtonPressed(sf::Mouse::Left))
       
{
                if (active == false && sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                        bslider.move(25, 0);
                        active = true;
                       
                }
                if (active == true && sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                        bslider.move(-25, 0);
                        active = false;
                }
        }
}

 

7
If this isn't good enough, I really don't know what is - this was the shortest I could make it:

void welcomescreen()
{
    sf::ContextSettings contextSettings;
    contextSettings.depthBits = 48;

    sf::RenderWindow windowo(sf::VideoMode(640, 480), "gameTest", sf::Style::Default, contextSettings);
    windowo.resetGLStates();    
        windowo.setVerticalSyncEnabled(true);
   
    sf::Font txt;
        txt.loadFromFile("resources/armyfont.ttf");
    sf::Text wlcmtxt;  
    wlcmtxt.setFont(txt);                                                               //text
    wlcmtxt.setScale(1.4, 1.4);
    wlcmtxt.setString("gameTest");
    wlcmtxt.setOrigin(-130, -0);

    windowo.setActive();
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 1.f);
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glViewport(0, 0, windowo.getSize().x, windowo.getSize().y);

     // make 3d cube
    GLfloat cube[] =
    {
      -50, -50, -50, 0, 0, 1, 1,
        -50, 50, -50, 0, 0, 1, 1,
        -50, -50, 50, 0, 0, 1, 1,        
        -50, -50, 50, 0, 0, 1, 1,
        -50, 50, -50, 0, 0, 1, 1,
        -50, 50, 50, 0, 0, 1, 1,

        50, -50, -50, 0, 1, 0, 1,      
        50, 50, -50, 0, 1, 0, 1,
        50, -50, 50, 0, 1, 0, 1,
        50, -50, 50, 0, 1, 0, 1,
        50, 50, -50, 0, 1, 0, 1,
        50, 50, 50, 0, 1, 0, 1,

        -50, -50, -50, 1, 0, 0, 1,        
        50, -50, -50, 1, 0, 0, 1,
        -50, -50, 50, 1, 0, 0, 1,
        -50, -50, 50, 1, 0, 0, 1,
        50, -50, -50, 1, 0, 0, 1,
        50, -50, 50, 1, 0, 0, 1,

        -50, 50, -50, 0, 1, 1, 1,
        50, 50, -50, 0, 1, 1, 1,
        -50, 50, 50, 0, 1, 1, 1,        
        -50, 50, 50, 0, 1, 1, 1,
        50, 50, -50, 0, 1, 1, 1,
        50, 50, 50, 0, 1, 1, 1,

        -50, -50, -50, 1, 0, 1, 1,
        50, -50, -50, 1, 0, 1, 1,
        -50, 50, -50, 1, 0, 1, 1,      
        -50, 50, -50, 1, 0, 1, 1,
        50, -50, -50, 1, 0, 1, 1,
        50, 50, -50, 1, 0, 1, 1,

        -50, -50, 50, 1, 1, 0, 1,
        50, -50, 50, 1, 1, 0, 1,
        -50, 50, 50, 1, 1, 0, 1,
        -50, 50, 50, 1, 1, 0, 1,      
        50, -50, 50, 1, 1, 0, 1,
        50, 50, 50, 1, 1, 0, 1,

    };

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glVertexPointer(3, GL_FLOAT, 7 * sizeof(GLfloat), cube);
    glColorPointer(4, GL_FLOAT, 7 * sizeof(GLfloat), cube + 3);

    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    while (windowo.isOpen())
    {

        sf::Event event;
        while (windowo.pollEvent(event))
        {
         
            if (event.type == sf::Event::Resized)
                glViewport(0, 0, event.size.width, event.size.height);
        }
     
               
                glClearColor(1.0, 1.0, 1.0, 1.0);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glColor3f(1.0f, 0.0f, 0.0f);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.f, 0.f, -200.f);
     
        // Draw the cube
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 36);
       
        windowo.pushGLStates();
                windowo.draw(wlcmtxt);                             //Problem
        windowo.popGLStates();
   
        windowo.display();
    }
}
 

8
I don't know what you're asking from me nexus, my drivers are fully updated, I included a "minimal code example" in my last post, I've read the post, my linkers are fine, I even tested my included code on another PC - drawing the text works fine.

9
General / Error with window.pushGLStates(); and window.popGLStates();
« on: June 21, 2015, 10:14:53 pm »
After my last post I made earlier today, I fixed the issue I had by removing the pushGLStates and popGLStates, but I need this to draw some text with an openGL shape. I don't understand why it won't work  with my SFML, I read the tutorials about using OpenGL. From what I can see, it should work fine. I'm not sure though.

It gives me this error:
First-chance exception at 0x02A1D6AE (nvoglv32.dll) in sfmlGame.exe: 0xC0000005: Access violation reading location 0x00000000.



                ...

                glDrawArrays(GL_TRIANGLE_STRIP, 0, 36);
                               
                window.pushGLStates();
                window.draw(wlcmtxt);
                window.popGLStates();
               
                window.display();

 

10
Graphics / Re: OpenGL issues with nvidia nvoglv32.dll
« on: June 21, 2015, 06:54:01 pm »
I figured out why it wasn't working, I had to remove the 4 lines after glDrawArrays. The only reason they were there is because of a copy and paste issue :P

11
Graphics / Re: OpenGL issues with nvidia nvoglv32.dll
« on: June 21, 2015, 06:12:28 pm »
I had to borrow some of the the opengl example from sfml and use it in the code, as it would of taken way too long to get the original code together, but the result/error is still the same.

#ifndef windowo
#define windowo

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


void welcomescreen()
{

        // Request a 32-bits depth buffer when creating the window
        sf::ContextSettings contextSettings;
        contextSettings.depthBits = 48;

        // Create the main window
        sf::RenderWindow windowo(sf::VideoMode(640, 480), "gameTest", sf::Style::Default, contextSettings);
        windowo.resetGLStates();        
        windowo.setVerticalSyncEnabled(true);
       
        sf::Font txt;
        if (!txt.loadFromFile("resources/armyfont.ttf"))
        {
                cout << "An error has occured loading the font.";
        }
       
        sf::Text wlcmtxt;      
        wlcmtxt.setFont(txt);
        wlcmtxt.setScale(1.4, 1.4);
        wlcmtxt.setString("gameTest");
        wlcmtxt.setOrigin(-130, -0);

        // Make it the active window for OpenGL calls
        windowo.setActive();

        // Set the color and depth clear values
        glClearDepth(1.f);
        glClearColor(0.f, 0.f, 0.f, 1.f);

        // Enable Z-buffer read and write
        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);

        // Disable lighting and texturing
        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);
       
        glViewport(0, 0, windowo.getSize().x, windowo.getSize().y);

        // Setup a perspective projection
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        GLfloat ratio = static_cast<float>(windowo.getSize().x) / windowo.getSize().y;
        glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 800.f);

        // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
        GLfloat cube[] =
        {
                // positions    // colors (r, g, b, a)
                -50, -50, -50, 0, 0, 1, 1,
                -50, 50, -50, 0, 0, 1, 1,
                -50, -50, 50, 0, 0, 1, 1,        // blue
                -50, -50, 50, 0, 0, 1, 1,
                -50, 50, -50, 0, 0, 1, 1,
                -50, 50, 50, 0, 0, 1, 1,

                50, -50, -50, 0, 1, 0, 1,       //green
                50, 50, -50, 0, 1, 0, 1,
                50, -50, 50, 0, 1, 0, 1,
                50, -50, 50, 0, 1, 0, 1,
                50, 50, -50, 0, 1, 0, 1,
                50, 50, 50, 0, 1, 0, 1,

                -50, -50, -50, 1, 0, 0, 1,         //red
                50, -50, -50, 1, 0, 0, 1,
                -50, -50, 50, 1, 0, 0, 1,
                -50, -50, 50, 1, 0, 0, 1,
                50, -50, -50, 1, 0, 0, 1,
                50, -50, 50, 1, 0, 0, 1,

                -50, 50, -50, 0, 1, 1, 1,
                50, 50, -50, 0, 1, 1, 1,
                -50, 50, 50, 0, 1, 1, 1,                //cyan
                -50, 50, 50, 0, 1, 1, 1,
                50, 50, -50, 0, 1, 1, 1,
                50, 50, 50, 0, 1, 1, 1,

                -50, -50, -50, 1, 0, 1, 1,
                50, -50, -50, 1, 0, 1, 1,
                -50, 50, -50, 1, 0, 1, 1,               //purple
                -50, 50, -50, 1, 0, 1, 1,
                50, -50, -50, 1, 0, 1, 1,
                50, 50, -50, 1, 0, 1, 1,

                -50, -50, 50, 1, 1, 0, 1,
                50, -50, 50, 1, 1, 0, 1,
                -50, 50, 50, 1, 1, 0, 1,
                -50, 50, 50, 1, 1, 0, 1,                //yellow
                50, -50, 50, 1, 1, 0, 1,
                50, 50, 50, 1, 1, 0, 1,

        };


        // Enable position and color vertex components
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glVertexPointer(3, GL_FLOAT, 7 * sizeof(GLfloat), cube);
        glColorPointer(4, GL_FLOAT, 7 * sizeof(GLfloat), cube + 3);

        // Disable normal and texture coordinates vertex components
        glDisableClientState(GL_NORMAL_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

        // Create a clock for measuring the time elapsed
        sf::Clock clock;

        // Start the game loop
        while (windowo.isOpen())
        {
                // Process events
                sf::Event event;
                while (windowo.pollEvent(event))
                {
                        // Close window: exit
                        if (event.type == sf::Event::Closed)
                                windowo.close();

                        // Escape key: exit
                        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                                windowo.close();

                        // Resize event: adjust the viewport
                        if (event.type == sf::Event::Resized)
                                glViewport(0, 0, event.size.width, event.size.height);
                }

       
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                {
                        windowo.close();
                }
               
               
                // Clear the color and depth buffers
                glClearColor(1.0, 1.0, 1.0, 1.0); // add this

                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                glColor3f(1.0f, 0.0f, 0.0f);

                // Apply some transformations to rotate the cube
                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();
                glTranslatef(0.f, 0.f, -200.f);
                glRotatef(clock.getElapsedTime().asSeconds() * 50, 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);

                // Draw the cube
                glDrawArrays(GL_TRIANGLE_STRIP, 0, 36);
               
                windowo.pushGLStates();
        //      windowo.draw(wlcmtxt); 
                windowo.popGLStates();
                windowo.pushGLStates();
                windowo.popGLStates();

                // Finally, display the rendered frame on screen
                windowo.display();
        }
}

#endif


 

I have the latest Nvidia drivers, I don't think that's the problem. I'm also using SFML 2.2 if that helps.

12
Graphics / OpenGL issues with nvidia nvoglv32.dll
« on: June 21, 2015, 04:32:18 pm »
In my code I used some opengl, but I get an error when debugging (Other code works fine). I get this error:

Unhandled exception at 0x02BCD6AE (nvoglv32.dll) in sfmlTest.exe: 0xC0000005: Access violation reading location 0x00000000.

It goes on to say nvoglv32.pdb is not loaded, but to be honest I have little idea about what this is about. Let me know if you need my opengl code, although it will take me a while as it is quite sparse in my game. Is there an easy fix for this?

Edit: It seems sprites or shapes don't draw at all either.

13
Graphics / Re: Create shape and set it's position in one line?
« on: June 17, 2015, 11:18:40 pm »
Ah, thanks  ;)

14
Graphics / Create shape and set it's position in one line?
« on: June 17, 2015, 11:14:49 pm »
I would like to know if it's possible, as it would be a lot more efficient in my game I am making.

15
Graphics / Re: Get position of entity local to a window/view
« on: June 12, 2015, 08:33:09 pm »
Ah, now I think I could of just setPosition(positive cords) done instead... This was the solution to this, thanks for the info.

Pages: [1] 2