Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Non-OpenGL 3D Rendering  (Read 4372 times)

0 Members and 1 Guest are viewing this topic.

Meerjel01

  • Newbie
  • *
  • Posts: 28
    • View Profile
Non-OpenGL 3D Rendering
« 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.


Thanks. Meerjel01

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Non-OpenGL 3D Rendering
« Reply #1 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 (or vertex buffer), set its primitive type to sf::PrimitiveType::Triangles 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 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 ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Meerjel01

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Non-OpenGL 3D Rendering
« Reply #2 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 (or vertex buffer), set its primitive type to sf::PrimitiveType::Triangles 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 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?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Non-OpenGL 3D Rendering
« Reply #3 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! :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Meerjel01

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Non-OpenGL 3D Rendering
« Reply #4 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Non-OpenGL 3D Rendering
« Reply #5 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!
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Meerjel01

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Non-OpenGL 3D Rendering
« Reply #6 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!