SFML community forums

Help => Window => Topic started by: Meerjel01 on February 15, 2023, 12:58:12 pm

Title: Non-OpenGL 3D Rendering
Post by: Meerjel01 on February 15, 2023, 12:58:12 pm
Hi. I would want to make a 3D library from scratch and use SFML to create the window. How do I do that? Is it possible?

I used this tutorial to learn 3D rendering and want to continue with it.
https://www.youtube.com/watch?v=ih20l3pJoeU&t

Thanks. Meerjel01
Title: Re: Non-OpenGL 3D Rendering
Post by: Hapax on February 16, 2023, 08:41:01 pm
If you want to use SFML graphics on that SFML window, you can use a vertex array (https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php) (or vertex buffer), set its primitive type to sf::PrimitiveType::Triangles (https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#primitive-types) and then send all of the co-ordinates for each triangle to the vertex array. These must be in the order that you want them to be rendered.

If you want to use OpenGL on the SFML window, see this tutorial (https://www.sfml-dev.org/tutorials/2.5/window-opengl.php) to get you started and then have a look at some OpenGL tutorials. I'm guessing you probably don't want to do this though as you could easily get OpenGL to do the 3D bit for you ;)
Title: Re: Non-OpenGL 3D Rendering
Post by: Meerjel01 on February 28, 2023, 01:41:24 pm
If you want to use SFML graphics on that SFML window, you can use a vertex array (https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php) (or vertex buffer), set its primitive type to sf::PrimitiveType::Triangles (https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#primitive-types) and then send all of the co-ordinates for each triangle to the vertex array. These must be in the order that you want them to be rendered.

If you want to use OpenGL on the SFML window, see this tutorial (https://www.sfml-dev.org/tutorials/2.5/window-opengl.php) to get you started and then have a look at some OpenGL tutorials. I'm guessing you probably don't want to do this though as you could easily get OpenGL to do the 3D bit for you ;)
I actually wanted to make a custom renderer but if SFML works for this then very well! Doesn't it cost a lot of memory using the technique from the video to SFML? Especially when using textures?
Title: Re: Non-OpenGL 3D Rendering
Post by: Hapax on February 28, 2023, 02:23:52 pm
You can still make a custom renderer if you want to but OpenGL - and therefore SFML - do this easily if you just wanted to focus on drawing the correct shape triangles and in the correct order. Basically, give your triangles to SFML and they'll be layered in the order given.

Computing 3D shapes can be quite process-intensive and then rendering them pixel by pixel can be much more process-intensive. It's often best to leave stuff the graphics card can do to do it for you so it frees up the CPU for other stuff.

Of course, this shouldn't stop you doing it all for learning purposes! :)
Title: Re: Non-OpenGL 3D Rendering
Post by: Meerjel01 on February 28, 2023, 02:33:26 pm
Yes SFML isn't a 3D library and 3D takes a lot to make it work in an optimized way. Yes I can use this for practice since I did this on the original Xbox with a bit of success except for the engine crashing when loading. So using SFML for it can work for sure  ;)

But is there a way to get the SFML method to work with textures? Like accessing the 3D accelerator on the hardware? I'm using a Mac by the way.
Title: Re: Non-OpenGL 3D Rendering
Post by: Hapax on February 28, 2023, 04:48:30 pm
SFML can draw triangles with texture, yes. You simply specify the texture co-ordinates in each vertex and pass the texture to the draw call.

Do note, though, that trying to do textures with perspective distortion is very tricky and is probably best to just leave it to OpenGL to do the 3D if you need that.

It should be noted that SFML does (can) use the hardware for graphics acceleration as it uses OpenGL. However, SFML completely ignores any depth values and is strictly 2D. Getting 3D effects out of a 2D graphics library is tricky but can be fun!
Title: Re: Non-OpenGL 3D Rendering
Post by: Meerjel01 on February 28, 2023, 05:05:57 pm
SFML can draw triangles with texture, yes. You simply specify the texture co-ordinates in each vertex and pass the texture to the draw call.

Do note, though, that trying to do textures with perspective distortion is very tricky and is probably best to just leave it to OpenGL to do the 3D if you need that.

It should be noted that SFML does (can) use the hardware for graphics acceleration as it uses OpenGL. However, SFML completely ignores any depth values and is strictly 2D. Getting 3D effects out of a 2D graphics library is tricky but can be fun!
Though Mac doesn't have OpenGL anymore so I don't know if it works. But I haven't started yet so who knows? It might work!