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

Pages: [1]
1
Thanks!!!

2
Where are the recommended guide lines?

3
after playing around with it some more, the sf::RenderTexture does behave a bit differently.

You must enable depth sorting once at the start, and disable it once at the end, and calling push/popGLStates respectively.

Unlike window, which you can enable/disable it as much as you want.

4
Graphics / Do OpenGL calls work the same way on a sf::RenderTexture ?
« on: February 16, 2023, 12:44:13 am »
I'm drawing everything to a sf::RenderTexture specifically so a shader has access to what's drawn on screen for further blending. Then I loop again to draw everything to the window (post shader stuff).

My game uses depth sorting. I've tried with and without the pushGLStates()/popGLStates(). Without them, nothing is drawn (to the render texture) that requires depth sorting. With them, everything appears but is not sorted properly.

For sf::RenderWindow, call push/popGlStates() are not necessary. The pure gl() functions work as is.

Does the sf::RenderTexture texture size need to match the world size (as opposed to the window size)? Are there any key differences between sf::RenderWindow and sf::RenderTexture?

for( VertexLevel vertex : *drawPtr ) { 
   if( cameraState_ == CameraState::ISOMETRIC_60D ) {
       
            glEnable(GL_DEPTH_TEST);   
            glEnable( GL_ALPHA_TEST );
            app->pixelBuffer_.pushGLStates();                   // sf::RenderTexture                                                                                           
            app->pixelBuffer_.draw( app->vtexMap_.at( vertex ), app->renderMap_.at( vertex ) );
            app->pixelBuffer_.popGLStates();

            glDisable( GL_DEPTH_TEST );
            glDisable( GL_ALPHA_TEST );
        }
}

        app->pixelBuffer_.display();
        app->testShader_.setUniform( "bufferTexture", app->pixelBuffer_.getTexture() );
 

5
Graphics / Re: How to add a depth buffer to isometric textures?
« on: January 14, 2023, 03:39:50 am »
It works, though the link is incomplete.

In addition to what's in the tutorial, you'll need to define the depth bits in the window's context settings, clear the depth buffer every frame, and draw an empty sf::VertexArray before drawing all the Vertex3Arrays (so some backend OpenGL stuff is set properly), and draw an empty sf::Shape before drawing any sf::Sprites (again, so some backend OpenGL parameters are set properly).

Its a bit hacky, and Im sure if I took the time to read to SFML's source code, you could avoid the empty draw calls and set the OpenGL parameters in the extended class.

Lastly, to draw alpha textures, just draw them last (the order matters if you want alpha stacking to work with multiple alpha vertex arrays)

6
Graphics / Re: How to add a depth buffer to isometric textures?
« on: November 06, 2022, 02:01:05 am »
First, a friend sent me this wonderful article which adds depth sorting by extending some SFML classes: https://www.jordansavant.com/book/graphics/sfml/sfml2_depth_buffering.md

Though Im still figuring out if this is what I need. Will report back later.

Assigning the depth to the color channel for each thing (at the vertex level) would recreate the solution I have now, but in the GPU, and it wouldn't solve any edge cases. Computing this on the CPU is not a bottleneck because I only draw (thus sort) what is visible on screen, and I was able to implement logic for all but one edge case.



7
Graphics / Re: How to add a depth buffer to isometric textures?
« on: November 03, 2022, 07:50:08 pm »
Thanks! Palettes make perfect sense, as I am using the alpha channel.

I implemented a basic fragment shader for the VertexArray storing the sorted textures. Now I can change the color... wooh!

So:
1.) Use the color channels to store depth, and the alpha channel to store 256 unique colors/opacities (I wont need more). Translate the alpha to a color in the shader.

2.) Question: can I calculate and store depth in the vertex shader? I probably cannot do this with the CPU for every pixel since each zoom level in my game uses a different sized tiles/tile atlas, and because there could be many units moving around screen (since it could be possible to store the position once, and pass the tile size to update them in the shader if the tile atlas changes...).

3.) Do you think I will be able to calculate the depth by finding the first/bottom most pixel in the texture that has an alpha value, adding the pixel texture.y position to the texture.y position, and then copying that value to the rest of the pixels in that column in that texture?

Edit: and by texture, I mean the 32 x 32 texture bounds defined in the vertex array for the render texture used.

Double Edit: Actually, the bottom most pixel per column wont work for everything, but I can get around that so long as I can label textures. E.g. a human against the wall with their arm extended would fail. The other option is to calculate z-depth per pixel, but there seems to be a multitude ways of doing that so I would have to experiment.

8
Graphics / Re: How to add a depth buffer to isometric textures?
« on: October 29, 2022, 04:59:48 pm »
Thanks, this is very interesting but I currently use the vertex color for my game.

I'm hoping what I can do is essentially loop through every column of pixels, loop through every pixel in the column, and draw assets based on which texture's pixel is closer to the camera (based on the bottom pixel i.e. screen.y position). Essentially do what I'm doing now, but on a pixel scale instead of texture/rectangle scale. Pretty sure this would solve the problem I have with walls having no depth.

I just dont know how I would implement that in a shader and pull the proper info from the sf::VertexArray

9
Graphics / How to add a depth buffer to isometric textures?
« on: October 28, 2022, 07:34:29 pm »
Hello, I'm creating an isometric city builder pixel art game. You can see examples on reddit.com/r/Archapolis for reference.

I figured out how to implement depth sorting via an algorithm, and it solves 95-99% of the cases (with some hacks). The general solution is to sort everything by the bottom of every textures screen.y position, but I have walls that are just the edge of the isometric cube (so no depth), so I needed to add some workarounds for objects/unit in buildings. I hit a hard limit with hallways (very complicated to explain).

I'd prefer to hit 100% with no hacks, and from the little I know about graphics programming, depth sorting appears to be the answer.

It seems possible to add this to SFML, but Im not sure how I would do that, and I am not sure how I would assign a depth to each pixel for the GPU.

Anyone know how I can experiment with this method?

10
Graphics / Re: Transforming Individual Quad/Sprite in Vertex Array
« on: June 01, 2022, 05:59:37 pm »
I can't figure out how to implement what you're describing. I tried creating a sf::Transform, set the rotation to 90, and then apply that to each point in the quad. Doesn't work.

Here is my code that works, but is a hacky way to accomplish what I need. Note that gameMapPassed is a container with tiles to update in the game, and gameMap_ is a container that contains all game world tiles.


//...
finder = textureMap_.at( TileType::TILE_ATLAS_VARIANT ).getSize().x / TILE_SIZE;
//...

for( const auto& tile : gameMapPassed ) {
        int index = tile.first;

        sf::Vertex* quad = &vtexMap_.at( VertexLevel::USER_TILE )[gameMap_.at( index ).mutableTile.tile_id * 4];
        TileType tileType = tile.second.staticTile->type;
        int tileNumber = static_cast<int>( tileType );

        int x = index % mapWidth_;
        int y = index / mapWidth_;
        int tx = tileNumber % finder;
        int ty = tileNumber / finder;
       
        int rotation = tile.second.mutableTile.rotation;
        int rotaHelp {};

        switch( rotation ) {
                case 0: rotaHelp = 0; break;
                case 90: rotaHelp = 1; break;
                case 180: rotaHelp = 2; break;
                case 270: rotaHelp = 3; break;
        }

        quad[0].position = sf::Vector2f( x * TILE_SIZE, y * TILE_SIZE );                               
        quad[1].position = sf::Vector2f( ( x + 1 ) * TILE_SIZE, y * TILE_SIZE );
        quad[2].position = sf::Vector2f( ( x + 1 ) * TILE_SIZE, ( y + 1 ) * TILE_SIZE );
        quad[3].position = sf::Vector2f( x * TILE_SIZE, ( y + 1 ) * TILE_SIZE );

        if( tile.second.mutableTile.mirror == false ) {
                quad[( 0 + rotaHelp ) % 4].texCoords = sf::Vector2f( tx * TILE_SIZE, ty * TILE_SIZE ); 
                quad[( 1 + rotaHelp ) % 4].texCoords = sf::Vector2f( ( tx + 1 ) * TILE_SIZE, ty * TILE_SIZE );
                quad[( 2 + rotaHelp ) % 4].texCoords = sf::Vector2f( ( tx + 1 ) * TILE_SIZE, ( ty + 1 ) * TILE_SIZE );
                quad[( 3 + rotaHelp ) % 4].texCoords = sf::Vector2f( tx * TILE_SIZE, ( ty + 1 ) * TILE_SIZE );
        }
        else { 
                quad[( 1 + rotaHelp ) % 4].texCoords = sf::Vector2f( tx * TILE_SIZE, ty * TILE_SIZE );
                quad[( 0 + rotaHelp ) % 4].texCoords = sf::Vector2f( ( tx + 1 ) * TILE_SIZE, ty * TILE_SIZE );
                quad[( 3 + rotaHelp ) % 4].texCoords = sf::Vector2f( ( tx + 1 ) * TILE_SIZE, ( ty + 1 ) * TILE_SIZE );
                quad[( 2 + rotaHelp ) % 4].texCoords = sf::Vector2f( tx * TILE_SIZE, ( ty + 1 ) * TILE_SIZE );
        }
}
 

Essentially, by changing the order when filling out the quad[], you can rotate and/or mirror and individual tiles in the game. (e.g. 0 + rotaHelp could start at quad[2]. Then % 4 ensures the value wraps around to 0.).

It's long winded to describe why the rotation logic works. Im less certain why the mirror logic works, but it does. I discovered it by playing around with the ordeing some more.

11
Graphics / Transforming Individual Quad/Sprite in Vertex Array
« on: May 30, 2022, 04:44:24 pm »
Hello, is there an official way to rotate/mirror an individual quad/sprite in a vertex array? All the documentation I've seen so far is for applying a transform to an entire vertex array.


Pages: [1]
anything