Welcome, Guest. Please login or register. Did you miss your activation email?

Recent Posts

Pages: [1] 2 3 ... 10
1
Graphics / Re: How to correctly draw a triangle fan?
« Last post by Nortski on Today at 11:38:23 am »
Ok, I will try your suggestions.
It's weird though as it only happens on the right side of that shape and nowhere else.
2
General / Re: I have a problem
« Last post by kojack on Today at 09:08:51 am »
The biggest hit here is that you are loading the background jpg from disk every frame. It really should be loaded just once at the beginning then reused, like the hero sprite's texture.
3
General / Re: I have a problem
« Last post by swthxbld3 on Today at 06:17:40 am »
It turns out that this is because of the image itself. But now I have fps drawdowns. It is also unclear why. Could you look at the code and tell me what is better to redo.
4
General / I have a problem
« Last post by swthxbld3 on Today at 06:00:01 am »
When I run the program, the character moves in a small fps. I looked at how it could be solved and came across Clock and time. But the problem has not been solved. Please help me, I have to submit the project soon. The problem is that when I add the background, the character starts lagging
main.cpp
 (#include <SFML/Graphics.hpp>
#include "hero.h"
#include "game.h"
#include <iostream>


int main() {
    sf::RenderWindow window(sf::VideoMode(1920, 1080), "WayofDarkness");



    game(window);

   

    return 0;
})

hero.h
 (#ifndef HERO_H
#define HERO_H

#include <SFML/Graphics.hpp>

class Hero {
private:
    sf::Sprite sprite;
    sf::Texture texture;
    float x, y;

public:
    Hero(std::string spritePath, float posX, float posY) {
        if (!texture.loadFromFile(spritePath)) {
        }

        sprite.setTexture(texture);
        x = posX;
        y = posY;
        sprite.setPosition(x, y);
    }

    void draw(sf::RenderWindow& window);

    void move(sf::RenderWindow& window, float&, float&, float);








};

#endif HERO_H)

hero.cpp
 (#include <iostream>
#include "hero.h"
#include "update.h"



void Hero::draw(sf::RenderWindow& window)
{
        window.draw(sprite);
}

void Hero::move(sf::RenderWindow& window, float&  playerX, float& playerY, float time)
{

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) || sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                playerX -= 0.6 * time;
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                playerX += 0.6 * time;


    sprite.setPosition(playerX, playerY);

}






)

game.h
 (#pragma once

#include <SFML/Graphics.hpp>
#include "hero.h"
#include "scence.h"
#include <iostream>


float playerX = 250;
float playerY = 151;



void game(sf::RenderWindow& window) {

    //window.setFramerateLimit(60);


    Hero hero("HeroSprite/doodle.png", 100, 100);
    sf::Clock clock;

    while (window.isOpen()) {
        float time = clock.restart().asSeconds();
        clock.restart();

        std::cout << time<< std::endl;
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }


        window.clear();
        hero.move(window, playerX, playerY, time);
        scence(window);
        hero.draw(window);
        window.display();
    }
}
)

scene.h
 (#pragma once

#include <SFML/Graphics.hpp>





void scence(sf::RenderWindow& window) {
        sf::Texture backgroundTexture;
        backgroundTexture.loadFromFile("ALL/images/animationBG.jpg");
        sf::Sprite background(backgroundTexture);
        window.draw(background);


       

})

5
General / Re: Can you integrate allegro into an sfml window?
« Last post by Me-Myself-And-I on Today at 12:23:08 am »
Thankyou.
There's a problem though. 
216   3   ...\pl_mpeg.h   [Error] conflicting declaration 'typedef struct plm_plane_t plm_plane_t'
6
Graphics / Re: How to correctly draw a triangle fan?
« Last post by Hapax on May 18, 2024, 11:18:29 pm »
If the triangle solution works, you must check your formation of the triangle strip to see if it's correct, including infinitely thin or 'backwards' triangles (breaking the triangle strip shape).
It might be worth making the calculations using doubles - for more accuracy - and then only converting to floats when creating the graphics (triangle strip).
7
General / Re: Can you integrate allegro into an sfml window?
« Last post by fallahn on May 18, 2024, 12:05:47 pm »
This should get you off on the right foot:

https://github.com/fallahn/VideoTexture

Just add the files in the 'src' directory to your project, and check the example for usage :)
8
Graphics / Re: How to correctly draw a triangle fan?
« Last post by Nortski on May 18, 2024, 11:55:50 am »
The safest bet, I would say, is to use separate triangles. The formation of the triangles does not matter so if they overlap or 'go backwards', it's fine since each triangle doesn't affect any other triangle.

I may have to try this just to see if it works. However; I will need to find a solution using a triangle fan as this was specifically instructed in the course I'm following.
9
Graphics / Re: How to correctly draw a triangle fan?
« Last post by Hapax on May 17, 2024, 10:46:51 pm »
It seems that there is an issue when those triangles are thin - possibly infinitely thin or even inverted due to rounding errors.
Triangle fans are not supposed to have overlapping triangles so it could have an issue with this when those triangles are 'thin'.

You could try replacing it with a triangle strip; this should be able to do similar but would require specifying the centre point multiple times. Plus, the strip might also suffer from the same issues, depending on Open GL feels about that.

The safest bet, I would say, is to use separate triangles. The formation of the triangles does not matter so if they overlap or 'go backwards', it's fine since each triangle doesn't affect any other triangle.

Of course, you would need almost 3 times as many vertices (it would be 3 times the vertices you have now minus 2) since you would just simply specify each triangle's vertices separately, repeating quite a few.
10
In addition - and something I was going to mention in my previous post but forgot - you should consider DPI awareness.

This can throw all sorts of things out if one version is DPI aware (even if automatic) and the other is not.

It's a very complicated issue, by the way, but I think Mac and Windows treat it differently by default. Possibly the way SFML treats it is different in those operating systems too but I'm not sure.
Pages: [1] 2 3 ... 10
anything