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

Pages: [1] 2 3 ... 18
Graphics / Re: Simple Isometric tileMAP but ugly result
« on: February 23, 2020, 05:32:39 pm »
i had similar problem with this, it turns out that it is happened due to float point precision problem.

i have solved it here in this link: https://en.sfml-dev.org/forums/index.php?topic=21048.msg150470#msg150470

Graphics / Re: GL_INVALID_OPERATION messages pop up when loading textures.
« on: February 23, 2020, 05:16:47 pm »
what SFML version do you use? i remember that the "glFlush()" were removed!!.

also, there is a potential bug in "loadTextures()", the sf::Texture object has tobe inside the nested for-loops. try to change it and see what gonna happen.

SFML projects / Titanion Clone
« on: February 22, 2020, 09:41:29 pm »
Remake of an old game called Titanion, it's an Open-Source originally made by apagame, it's a strike down super high-velocity swooping insects game-like similar to infamous Space Invaders. it was written in D-Language, but unfortunately, D-Language no longer be supported, they re-created it and called it D2-Language. i have been working on this game for sometime, it is part of my 3D OpenGL FrameWork Demos, i added colours, text and sounds, no textures involved in this game ;D, this is one of many reasons, why i chose to spend sometime to re-create it.

here game-play demo:

General / Re: basic text box
« on: February 15, 2020, 10:01:30 pm »
excellent point Laurent.
yes, indeed, it's quite useful, gotta update my code example.

General / Re: basic text box
« on: February 15, 2020, 07:51:53 am »
The for-loop will tell you all information you need, the printable ASCII characters and its index position For example:If i run the for-loop in my PC it will print something like this:

30 �
31 �
33 !
34 "
35 #
36 $
37 %
122 z
123 {
124 |
125 }
126 ~
128 �
129 �

From the output, we can easily now detect all of printable chars and its indices which is clearly the printable chars start from index 32 upto 127. now, we need to add this boundary check to SFML event-loop:

//if (event.text.unicode >= 32 && event.text.unicode <= 127)
if (std::isprint(event.text.unicode)) // thanks to Laurent
    input_text += event.text.unicode;

Don't worry about if user press BackSpace or Return/Enter keys, sf::Text will take care for these inputs internally, just supply the string to sf::Text::setString with escape char in event-loop:

if (event.key.code == sf::Keyboard::BackSpace) {
    if (!input_text.empty())
        input_text.pop_back();// as Laurent pointed out
if (event.key.code == sf::Keyboard::Return){
        input_text += '\n';

That's it, we have accomplished a minimal text editor.

I added a simple blinking effect to “cursor”. It was a part of my early demos when I was working out with the SFML library. ;D

Here the complete source source:
#include <SFML/Graphics.hpp>
#include <locale>

int main()
    sf::RenderWindow window({ 640 ,480 }, "test");

    std::string input_text;
    sf::Font font;
    sf::Text text("", font);

    sf::Clock clock;

    while (window.isOpen())
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed)
            else if (event.type == sf::Event::TextEntered) {
                if (std::isprint(event.text.unicode))
                    input_text += event.text.unicode;
            else if (event.type == sf::Event::KeyPressed) {
                if (event.key.code == sf::Keyboard::BackSpace) {
                    if (!input_text.empty())
                if (event.key.code == sf::Keyboard::Return) {
                        input_text += '\n';

        static sf::Time text_effect_time;
        static bool show_cursor;

        text_effect_time += clock.restart();

        if (text_effect_time >= sf::seconds(0.5f))
            show_cursor = !show_cursor;
            text_effect_time = sf::Time::Zero;

        text.setString(input_text + (show_cursor ? '_' : ' '));


General / Re: basic text box
« on: February 14, 2020, 08:00:12 am »
it quite easy to retrieve all ASCII characters programmatically, just run a for-loop to print out all characters that range from 0 to 255. unless i misunderstood what you are trying to achieve.

for (int i = 0; i < 255; i++)
    std::cout << i << ' ' << (char)i << '\n';

Graphics / Re: Inherit from sf::Shape (sf::CircleShape)
« on: February 05, 2020, 05:28:57 am »
your code looks fine, there is no problem with it, but, making the asteroid's radius 10 pixels is quite small. give it higher value like 200 or 300 pixels, it's okay, also set the asteroid's position at center of screen for debugging, to make sure,the asteroid is visible and it's lay within viewport of window. also, make sure of the texture rect is mapped to a valid spot in that texture, means it does't picked transparent or color similar to window's background color or perhaps, the texture itself is corrupted or fully transparent. if that the case then change it with a valid texture or better, use "sf::Image" to create an image with opaque or solid color like "sf::Color::Red". and feed it to the texture update method "sf::Texture::update()". check the official documentation for texture update method.

General / Re: Noise when using threads
« on: February 02, 2020, 04:30:26 pm »
hmm, interesting i haven't thought about drawing the pixels as points with sf::VertexArray, i think this worth testing. gotta make my own mandelbrot demo  ;D

General / Re: Noise when using threads
« on: February 01, 2020, 01:01:40 pm »
since all threads using same resource you need to lock the current thread by using "std::mutex" or even better "std::lock_guard<std::mutex>".

to fix the processor usage consumed, you have to make the current active thread to sleep for sometime. there is a function already made for this purpose: "std::this_thread::sleep_for(std::chrono::microseconds(1))"

in general sf::Image was not made to do a heavy image processing, alternatively you you may look for computing shader and indirect draw commands, it is available in both opengl and D3D.
it will help you if you need to boost your application further.

this is what i know as common advises maybe there is better way to handle the image processing efficiently that i'm not aware of.

Graphics / Re: loadfromfile failing to load an image
« on: January 24, 2020, 07:24:05 pm »
"loadFromFile()" usually print an error message on console screen if it can't open the file. check it if there is a message. if not then make complete and minimal example that produce same error.

General / Re: Text
« on: January 15, 2020, 08:58:13 am »
you can achieve these condition states by introducing a boolean values in your game classes like "bool is_button_pressed;", "bool is_he_chose" ... etc;

and then let the classes that needs those boolean properties to access them. whether by a pointers to the classes or some kind of game patterns that lets the entities in a game reference each other.
it's an inefficient to delete/create text objects every time when the player pressed the button. better to not to draw the text and probably it needs a timer for how long text will be drawn.
however, i think your game won't has a performance issues. since, your game has a few game objects, no collision or physics involved.

in general, it's depend on your game design which class responsible about display the hint text and its life span.

General / Re: How to implement sprite group?
« on: January 10, 2020, 03:28:49 pm »
well, i have almost same error as you have it, i'm using visual studio 2015 [v140]-for widow 8.1.
i made test code to draw colorful circle shapes with "sf::CircleShape". to show the the error

i suspect it might be a bug with my compiler version. i'm using visual studio 2015 [v140] for window 8.1.

here my test code:
#include <SFML/Graphics.hpp>

int main()
        sf::RenderWindow window(sf::VideoMode(640, 480), "test!");

        std::vector<std::reference_wrapper<const sf::Drawable>> shapes_wrapper;

        sf::CircleShape shape(32);

        std::vector<sf::CircleShape> shapes;
        for (int i = 0; i < 2; i++) {
                if (i == 0) {
                        shapes.back().setPosition(window.getView().getCenter() / 4.0f);
                else {
                        shapes.back().setPosition(window.getView().getCenter() / 2.0f);
#if 0 // ugly error, it should accept it. <-- probably it's a bug

        sf::CircleShape test_shape(32);
        test_shape.setPosition(window.getView().getCenter() - window.getView().getCenter() / 4.0f);

        sf::CircleShape center_shape(32);

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

                for (const auto& shape : shapes)
                for (const auto& shape : shapes_wrapper)

        return 0;

EDIT: it looks the std::vector of sf::CircleShape objects cause the problem, i replaced it with std::list and it works. also, i have test it with sf::CircleShape pointers ad it works as expected.
std::list<sf::CircleShape> shapes;

or with smart pointer
std::vector<std::unique_ptr<sf::CircleShape>> shapes;

both worked fine in my code.

alright, according to https://en.cppreference.com/w/cpp/container/vector/push_back

If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.

that means we have at least to use reserve() the vector to guarantee that no reallocation will happen by the subsequent of push_back()

fix: in my code it needs to add this:
std::vector<sf::CircleShape> shapes;
while in yours it needs to add this:
std::vector<Box> boxes;

General / Re: Sprite Pointer?
« on: January 09, 2020, 11:19:06 pm »
i agree with Rosme about reading a c++ book. pointers and references are most important features in c++ language. if you had difficulties to grasp these concepts then you may consider to switch to other programming language that don't use low level features like java or c#.

to solve the compiler warning in you code, just assign the memory address of your main sprite to the pointer sprite by using the address-of "operator(&)" like this:

Selected_Piece = &Piece_1;

and you can use the pointer by dereference it. if you were needed it, with "operator(*)", like this:

window.draw(*Selected_Piece );

SFML projects / Re: Intel 8080 Emulator-Space Invaders
« on: January 06, 2020, 09:51:34 am »
hello fallahn  :)

i'm so glad that you like it, i really appreciated.

i can't thank you enough for the tutorial, it really helpful. i get it where the problem is, according to the tutorial, it appears i have mapped the mirrored RAM location at wrong address location. i have fixed that and the bug seems has gone away  :D

SFML projects / Intel 8080 Emulator-Space Invaders
« on: January 03, 2020, 06:42:50 pm »
i have managed to make simple a `Intel 8080` 8-bit microprocessor emulator for Space Invaders. however, there is good news and bad news.

the good news is, the sound is working fine with emulator unlike my previous Space Invaders clone https://en.sfml-dev.org/forums/index.php?topic=26821.0
which is still can't get it to working correctly.

the bad news emulator has a bug for some reasons the Space Invaders game crushed when the startup game demo run longer. honestly i don't know what actually cause it, is it a multi-threading issues or memory-corruption, i have no idea.

the cpu runs fine i have tested it with COM test-files.

EDIT: bug is fixed, now the emulator's working fine.

here a Demo of Space Invaders game:


before i forget, I will post the source code for Space-Invaders clone project as soon as i finished fixing its bugs and publish the code.
the emulator-code is simple and easy to read, mostly copy-paste from 8080/8085 assembler.
here the emulator's source code: https://github.com/MORTAL2000/Intel-8080-Emulator-Space-Invaders/

Pages: [1] 2 3 ... 18