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.


Topics - LakySimi1

Pages: [1]
1
General / Pass int/char array to sf::Uint8 array?
« on: April 19, 2024, 11:52:48 pm »
Hi everyone,
there is a way to pass an int or maybe better, a char array to sf::Uint8* pixels = new sf::Uint8[WIDTH * HEIGHT * 4] ?

Honestly, i'm ignorant, i want to build the array of pixels in a classic int array, which is faster to manipulate, and then show it on screen.

Right now instead i am manipulating pixels.

2
Hi everyone,
as for the title, anything, even empty brackets, kills framerate, from 1450ish to 250ish.. why this happen?

Moreover, maybe a dedicated topic could be better but, do you think that, for a pixel-per-pixel rendering, the code below is the right approach for a video game? Like a raycaster, or 2D rpg, or 2D platform..
I've already done a quite pretty raycaster time ago, with sprites and sliding doors, with the very approach in the code below, but i've stopped coding it because i was not sure if the approach was right.

Thank you very much!

PS There is a better way to put code in post, with the proper colorig of keywords etc.?

Code:
(click to show/hide)

3
Hi everyone,
the code provided goes at 540fps on 960x540 with an i5-10400; is not slow in an absolute way but considering what i am doing.. it is, and, most triggering to me is that therefore it is too unoptimized.
Drawing a genering monochrome rectangle with same dimensions goes up to 2500ish fps.

I compromise on go slower because i'm using CPU rather than GPU but it seems a bit too bad to me.

I want to draw the game screen pixel per pixel, i find it funny to come up with al graphic tweaks and have the power to intervent arbitrarily on any pixel i want: there is a way to do what i do in my code but more correctly/optimixed? There are other ways to do what i want to do?

Thak you very much in advance!
Quote

#include <SFML/Graphics.hpp>

using namespace std;

const int H = 1080/2; //Window height
const int W = 1920/2; //Window width

sf::Uint8* pixels = new sf::Uint8[W * 800 * 4]; //Array for the pixels (R,G,B,Alpha)


//Fill pixel array with values (all 100 for simplicity's sake)
void CreateImage(int nCol, int row_0, int row_1)
{
    for (int ir = row_0; ir < row_1; ir++)
    {
        for (int ic = 0; ic < W; ic++)
        {
            pixels[(ir * W + ic) * 4] = 100;        //red
            pixels[(ir * W + ic) * 4 + 1] = 100;    //green
            pixels[(ir * W + ic) * 4 + 2] = 100;    //blue
        }
    }
}



int main()
{
    sf::RenderWindow window(sf::VideoMode(W, H), "SFML works!"); //Create window
    window.setFramerateLimit(0); //No limit to framerate

    //Stuff used to generate final screen image (found online)
    sf::Texture texture;    texture.create(W, H);   sf::Sprite sprite(texture);
   

    for (int ir = 0; ir < W * H * 4; ir++) //Set Alpha=255
        pixels[ir] = 255;

    for (int ix = 0; ix < W; ix++) //Generate any image
        CreateImage(ix, 0, 720);




    while (window.isOpen())
    {
        //Again, stuff used to draw image on screen (found online)
        //Why this part is so slow??
        //Is possible to speed up things mantaining the "pixel array"?
        //(i like have the single pixle draw control)
        texture.update(pixels);
        window.draw(sprite);
        window.display();
    }
    return 0;
}


4
Graphics / Any way to optimize 'pixelsArray to GPU' process?
« on: September 21, 2022, 10:22:56 pm »
Hi everyone,
for my small projects i'm using a  "sf::Uint8* pixelsArray = new sf::Uint8[640 * 480 * 4];" that gives me the possibility to manipulate every pixel as i want but feels kinda slow..

Here's a pseudocode of what i'm currently doing. is there any way to speed things up?
I've the feel that the last 3 rows are slowing everthing because i have to pass my 'pixelsArray' to GPU (right?) every "new updated frame".

Is there a way to modify my 'pixelsArray' somehow directly in the GPU (to avoid the continuous texture update)?

Code: [Select]
sf::RenderWindow window(sf::VideoMode(640, 480));
sf::Texture texture;
texture.create(640, 480);
sf::Sprite sprite(texture);

sf::Uint8* pixelsArray = new sf::Uint8[640 * 480 * 4];

//UPDATING PIXELS ARRAY
pixelsArray [x + y*640 * i] = 0-256;
so on..

//UPDATING  WINDOW
texture.update(pixels);
window.draw(sprite);
window.display();


BONUS QUESTION:
Suppose i have a large pixelsArray [4096x4096] but want to draw (fast) just a rectangular portion of it?
(like as map scrolling as seen in Age of Empires or Commandos [supposed paused for semplicity])

PS I'm sure i got something wrong but i'm not really into technicals of SFML/OGL.. just need something to draw.

5
Hi everyone!
I'm making a game and i'm questioning if my drawing method is right enough or can be improved.
I really like to draw a pixel at a time.

I pick the color of the pixel i want to draw from and image and than i transfer the RGB data on a 'pixels' array. Then i transfer this 'pixels' array into a Texture, then it into a Sprite and then i display the final Window, this last part (last 3 rows) are a mistery to me, i've seen it online ^^

CODE
(click to show/hide)


EDIT
What's 'better': use a pixel array and transfer to a Texture OR using an Image and then transfer it to a Texture?

I provide two full code which show that the PixelArray solution is faster but maybe is also stressful for the PC?
(click to show/hide)

6
Hi guys!
I'm making my own raycasting engine, the game resolution is the classic 320x200 windowed.
Obviously i want to make it run let's say zoomed in so for now i'm using two ways, the first one is simply to click "fullscreen" button on the window, it lost the aspect ratio but works; the second one is to use a simple scale function to make a window 3 times larger, and it works as well.

The problem is that if in original 320x200 uses 20% of cpu while the 2 scale methods raise it to 32/35%! 70% of more CPU usage just for fullscreen?!

So i'm wondering if there's a proper way to do it, do you know some?
I'm thinking about those games that first change the PC resolution and then go fullscreen, i think is the best way..?


Here the scaleup function that i made:
Code: [Select]
void RESOLUTION_SCALE()
{
    for (i = 0; i < width; i++)
        for (j=0; j < height; j++)
            for (iterX = 0 ; iterX < scaleRESOL ; iterX++)
                for (iterY = 0 ; iterY < scaleRESOL ; iterY++)
                {
                    pixelsFinal[( (j*scaleRESOL +iterY)*windowWidth + i*scaleRESOL + iterX)*4]    = pixels[(j*width + i)*4];
                    pixelsFinal[( (j*scaleRESOL +iterY)*windowWidth + i*scaleRESOL + iterX)*4 +1] = pixels[(j*width + i)*4 +1];
                    pixelsFinal[( (j*scaleRESOL +iterY)*windowWidth + i*scaleRESOL + iterX)*4 +2] = pixels[(j*width + i)*4 +2];
                }
}

WITH:
width = 320;
height = 200;
scaleRESOL = 3;
pixels = 320x200;
pixelsFinal = 960x600;

7
General / [SOLVED] Debug works perfectly, Release works halfway?!
« on: February 29, 2020, 07:48:49 pm »
Hi everyone!
I'm developing a raycasting game engine in CodeBlocks with SFML, surely it's not perfect but it works well, at least the Debug executable AND in "Debug mode" in CodeBlocks as you can see here:
(click to show/hide)

But in Release executable and "release mode" of CodeBlocks it works half way, in fact the wall rendering works perfectly and the framerate doubles but floor and ceil isn't rendered, to be precise
its rendered only maybe ten pixel height stripe in the middle of the window:
(click to show/hide)

Searching around i read that can depend on which libraries are are used, here's mine:
(click to show/hide)
Previously the first five was followed by "-d" (for "debug" i think) but it works the same without too.
There's no other libraries in the linker of "build options.." of the project.


I will be very glad if someone can help me to make a working Release!

PS
Please don't mind the swastika, i'm using, for testing, the textures of the old PC game "Wolfenstein 3D" by "id software"!

8
Window / Updating the sprite and show it works for few seconds
« on: May 28, 2019, 07:42:31 pm »
Hi everyone!
i'm a very newbie with SFML, in trying to learn how to display my pixels array and refreshing window when needed. I've make this very basic program, it works, make me change the intesity of blue (whitch fill the window) based on my input but it works just for 2 or 3 seconds! Then the window doesn't not respond and freeze.

I'm using CodeBlocks

(click to show/hide)

Pages: [1]
anything