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:#include <SFML/Graphics.hpp>
int main()
{
//INITIALIZE WINDOW
int W = 1280; //Screen width
int H = 720; //Screen height
sf::RenderWindow window(sf::VideoMode(W, H), "SFML Project");
//INITIALIZE PIXELS ARRAY
sf::Texture texture;
texture.create(W, H);
sf::Sprite sprite(texture);
sf::Uint8* pixels = new sf::Uint8[W * H * 4]; //Array for the pixels (A,R,G,B)
for (int ir = 0; ir < W * H * 4; ir++) pixels[ir] = 255; //In particular to set Alpha channel to 1.
int color_Red = 0;
int color_Green = 0;
int color_Blue = 0;
///MAIN LOOP
sf::Event Event;
while (window.isOpen())
{
//HARDWARE INPUTS
while (window.pollEvent(Event))
[glow=red,2,300]{[/glow]
//if (Event.type == sf::Event::Closed)
// window.close();
[glow=red,2,300]}[/glow]
//GAME LOGIC
//The game logic also provide the color for the pixels, for this example all the screen will be..
color_Red = 150;
color_Green = 120;
color_Blue = 175;
//FILL PIXELS ARRAY
for (int ic = 0; ic < W; ic++)
for (int ir = 0; ir < H; ir++)
{
pixels[4*(ic + ir * W)] = color_Red; //RED
pixels[4*(ic + ir * W) + 1] = color_Green; //GREEN
pixels[4*(ic + ir * W) + 2] = color_Blue; //BLUE
}
//DISPLAY
texture.update(pixels);
window.draw(sprite);
window.display();
}
}
[/size]