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

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Can you integrate allegro into an sfml window?
« Last post by eXpl0it3r on Today at 08:25:35 am »
Those are OpenGL functions, you'll also have to link OpenGL.
2
General / Re: Can you integrate allegro into an sfml window?
« Last post by Me-Myself-And-I on Today at 02:45:11 am »
Thankyou very much. That definitely solved the conflicting declaration issue.
I'm still having two errors.
undefined reference to `_imp__glBindTexture@8'
undefined reference to `_imp__glTexImage2D@36'
 

I guess since it works for you it must be because my SFML version must be incompatible with this. I use sfml 2.4.0.
3
General / Re: I need help with this
« Last post by eXpl0it3r on May 23, 2024, 11:36:42 pm »
I'm not quite sure what you mean with "determine the position of the outline of the cue ball". Do you mean the shortest ray to the border of the cue ball? Wouldn't we also need to know where this is casted from to answer the question?

Maybe there's also an entirely different question hidden underneath. Can you describe what you're trying to solve currently?

Also might be useful if you could provide some code.
4
General / Re: Texture is not loading
« Last post by eXpl0it3r on May 23, 2024, 02:36:21 pm »
You can't just put an object outside of any scope and expect it to just work. ;)
You need to learn a bit more about scopes and lifetime, plus compilation units.
It's recommended to not use global variables, but use the class scope, if you want to share something across multiple functions.

Maybe you actually wanted to load the texture on the tile class instead of bgtex that lives outside of everything?

Personally, I recommend to use something like a ResourceHolder and pass a reference to where you want to use a texture.
5
General / Texture is not loading
« Last post by floppa_dev2 on May 23, 2024, 02:16:58 pm »
Hello! I am trying to make a small platformer game but I have a huge problem, the texture isn't loading.
https://github.com/epicfloppadev/floppa/ this is the github name
So I have this code in src/tile.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
class tile
{
public:
    bool activated = 0;
    Vector2f position={0.f,0.f};
    Sprite sprite;
    Texture texture;
};
Texture bgtex;
void loadTiles(tile tiles[][14])
{
    bgtex.loadFromFile("Images/tile.jpg");
    for (int i = 0; i <= 12; i++)
    {
        tiles[6][i].activated = 1;
    }
    for (int i = 0; i <= 7; i++)
    {
        for (int j = 0; j <= 13; j++)
        {
            tiles[i][j].position={float(100*i), float(100*j)};
            tiles[i][j].sprite.setPosition(tiles[i][j].position);
            if (tiles[i][j].activated == 1)
            {
                tiles[i][j].sprite.setTexture(bgtex);
               
            }
        }
    }
}
void display_tile(tile &object, sf::RenderWindow &window)
{
   
    window.draw(object.sprite);
}

this code in main.cpp:

#include "smth.hpp"
#include "grass.cpp"
#include "tile.cpp"
using namespace sf;
bool jumping = 0;
float jump_velocity = 0;
float accelerationV = 0.5;
float speedV = 0;
bool o_g = 0;
int main()
{

    tile tiles[8][14];
    loadTiles(tiles);
    //
    // Music battle;
    // battle.openFromFile("Audio/battle-of-the-dragons-8037.wav");
    // battle.play();
    Object player = {{500, 500}, 0},
           bg{{1000, 1000}, 0};
    if (!player.texture.loadFromFile("Images/big-floppa-player.png") || !bg.texture.loadFromFile("Images/bg.jpg"))
    {
        return -1;
    }
    player.sprite.setScale(0.7, 0.7);
    init_grass();
    bg.sprite.setTexture(bg.texture);
    player.sprite.setTexture(player.texture);
    RenderWindow window(sf::VideoMode(1280, 720), "Super Floppa", Style::Titlebar | Style::Close);
    Clock clock;
    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {

            if (event.type == Event::Closed || Mouse::isButtonPressed(Mouse::Right))
                window.close();
        }
        Time elapsed = clock.restart();
        float dt = elapsed.asSeconds();

        if (Keyboard::isKeyPressed(Keyboard::A))
        {

            speedV += accelerationV;
            if (speedV > maxSpeedV)
                speedV = maxSpeedV;
            player.position += {-speedV, 0.f};
        }
        if (Keyboard::isKeyPressed(Keyboard::D))
        {
            speedV += accelerationV;
            if (speedV > maxSpeedV)
                speedV = maxSpeedV;
            player.position += {speedV, 0.f};
        }
        else
        {
            speedV -= (-1 * bool(speedV < 0)) * accelerationV;
        }
        if (Keyboard::isKeyPressed(Keyboard::Space) && !jumping)
        {
            jumping = 1;
            o_g = 0;
            jump_velocity = sqrt(2 * GRAVITY * JUMP_HEIGHT);
        }
        if (o_g == 0)
        {
            player.position.y -= jump_velocity * dt;
            jump_velocity -= GRAVITY * dt;
        }
        if (touch_grass_lol(player, grass))
        {
            jumping = 0;
            o_g = 1;
            player.position.y = grass.getPosition().y - player.texture.getSize().y * player.sprite.getScale().y;
        }
        if (dt < 1.f / 60.f)
        {
            sleep(sf::seconds(1.f / 60.f - dt));
        }
        std::cout<<tiles[1][1].sprite.getTexture().getSize();

        window.clear();
        //   window.draw(bg.sprite);
        // window.draw(grass);
        for (int i = 0; i <= 6; i++)
        {
            for (int j = 0; j <= 12; j++)
            {
                if (tiles[i][j].activated == 0)
                {

                    display_tile(tiles[i][j], window);
                    // std::cout<<tiles[i][j].position.x<<&#39; &#39;<<tiles[i][j].position.y<<std::endl;
                }
            }
        }
        display_smth(player, window);
        window.display();
    }
    return 0;
}
when I am running the program the texture is not showing but if i modify the player texture to be bgtex(the tiles texture), the texture is showing as normal, what should i change in the loadTiles() function
6
General / Re: Can you integrate allegro into an sfml window?
« Last post by fallahn on May 23, 2024, 10:56:07 am »
Just tried it with gcc and there were a few typos which needed fixing 😅

I've updated the repo with a version that I've tested on my linux box and added a CMake project for the demo if you'd like to try it.
7
SFML development / Re: Font/Text Direction
« Last post by FRex on May 23, 2024, 06:26:52 am »
Adding vertical advance in sf::Font would unlock one thing: let users write own text code that does the vertical layout. I think this was the point Hapax made.

Same as now sf::Text has no per letter color, style, etc. but you can write a class that does, all using sf::Font, never dealing with FreeType yourself, or how in general you can make own drawables using vertex arrays or buffers.

Now if you want vertical text, you'd have to use FreeType 100% by yourself, just to get that y from advance that sf::Font doesn't expose (I'm not sure if anything else is missing or if just this one field will allow it).
8
After a bit of experimenting, that solution partially worked. I figured it out so I'm going to mark the thread as solved, but for anyone who runs into this issue:

Resetting the window view is NOT enough to solve this on its own. The flow of code should be something like this:
if (event.type == sf::Event::Resized) {
        window.setView(sf::View(sf::Vector2f(window.getSize().x/2.f,window.getSize().y/2.f), sf::Vector2f(window.getSize().x, window.getSize().y)));
        for (auto& i : sprites) {
            i.setPosition(/*new position */);
        }
       
    }
You must adjust every drawn object/sprite's position after you change the sf::View, otherwise each drawn object is stuck with an arbitrary sf::View based on the time it was drawn before/after the resizing of the window.
9
General discussions / Re: Scroll Wheel
« Last post by eXpl0it3r on May 22, 2024, 10:38:53 pm »
Have you tried the sf::Event::MouseWheelScrolled event? See the tutorial.

Or are you saying that your mouse has more than one scroll wheel?

As for buttons, SFML also supports two extra mouse buttons.
10
General / Re: Can you integrate allegro into an sfml window?
« Last post by Me-Myself-And-I on May 22, 2024, 09:23:06 pm »
I don't think that's the problem.
The header files are not listed in the cmake file.
# Project: Project1
# Makefile created by Dev-C++ 5.11

CPP      = g++.exe
CC       = gcc.exe
WINDRES  = windres.exe
OBJ      = main.o VideoTexture.o
LINKOBJ  = main.o VideoTexture.o
LIBS     = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -L"C:/SFML-2.4.0/lib" -static-libgcc -lsfml-graphics -lsfml-network -lsfml-audio  -lsfml-system -lsfml-window -m32
INCS     = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS  = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -I"C:/SFML-2.4.0/include"
BIN      = Project1.exe
CXXFLAGS = $(CXXINCS) -m32 -std=c++11
CFLAGS   = $(INCS) -m32 -std=c++11
RM       = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
        ${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
        $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

main.o: main.cpp
        $(CPP) -c main.cpp -o main.o $(CXXFLAGS)

VideoTexture.o: VideoTexture.cpp
        $(CPP) -c VideoTexture.cpp -o VideoTexture.o $(CXXFLAGS)
Pages: [1] 2 3 ... 10