I'm struggling finding a path towards understanding the first principles in 3D rendering.<p>I can find a lot of complicated books and tutorials that assume a bunch of things like OpenGL or Glad or C++ or Dynamically Linking library X Y Z and magically creating a scene but where is the "build it yourself" path?<p>I essentially want to build my own "hello world" 3D engine to understand how to manipulate pixels/shaders in 3D space.<p>I'm searching for tutorials and books around building a game engine from scratch as that seems to be the best fit -- I'm still searching. Nothing I have found yet seems thorough and to the point and self-bootstrapped. For example I find this walkthrough of building a text-editor from scratch absolutely perfect: https://viewsourcecode.org/snaptoken/kilo/<p>I have no preference for language - I'm familiar with most. Anything more "raw" without including a bunch of libraries will suit me best. So "single file/header libs" are the largest I'd like to play with. Having said that, C might be the best fit if it's the easiest to compile and get up and running without any dependencies.<p>Some embarrassing questions:<p><pre><code> 1. What is the most basic way I can create a window and render pixels in it?
2. Same as one but essentially with the most direct way of creating "fragment shaders?" (Is there something more direct than GLSL?)
3. My second question implies OpenGL as the API - is there a more direct or easier way to manipulate a window and pixels within it than OpenGL that is specific per OS?
3a. What would be the most direct API/layer to access per OS?
</code></pre>
For context: I'm currently coding on Windows/WSL - I recently switched from MacOS. I'm most familiar with MacOS and unix flavors for dev environments. I mention this in case there is a more direct way to accomplish my goal being on Windows than trying to go a cross-platform approach way (OpenGL).<p>I'm specifically avoiding any engine like processing, unity, webGL, etc - these abstract too much of the fundamentals I'm trying to learn.<p>I'd be really happy if I can just:<p><pre><code> 1. Create a window
2. Render pixels in that window that allow 2D/3D space drawing/coloring.
3. Create some basic shapes from a square to a cube and further real-time transformations.
</code></pre>
It can't be that complicated can it? Hah.
> I'd be really happy if I can just:<p>> 1. Create a window 2. Render pixels in that window that allow 2D/3D space drawing/coloring. 3. Create some basic shapes from a square to a cube and further real-time transformations. It can't be that complicated can it? Hah.<p>All this really depends on what language you want to do this on. (A viable example on Java)[<a href="https://youtu.be/KA6rJZOfTTQ" rel="nofollow">https://youtu.be/KA6rJZOfTTQ</a>]. I think what you want is basic software rendering, so be advised: software rendering gets really slow really fast.<p>I tried something akin to this a couple years back l, it didn't end too well, but I learned a ton in the process, feel free to (take a look )[<a href="https://github.com/jonnelafin/PB3D" rel="nofollow">https://github.com/jonnelafin/PB3D</a>], but the code is crap, so I think you are better off on writing your own.<p>Also these are some wikipedia articles on perspective transformations etc:<p>(Perspective projection)[<a href="https://en.m.wikipedia.org/wiki/3D_projection" rel="nofollow">https://en.m.wikipedia.org/wiki/3D_projection</a>] (Perspective projection -> Mathematical formulas) (Rotation matricies)[<a href="https://en.m.wikipedia.org/wiki/Rotation_matrix" rel="nofollow">https://en.m.wikipedia.org/wiki/Rotation_matrix</a>]
I like <a href="https://www.babylonjs.com/" rel="nofollow">https://www.babylonjs.com/</a> very much, if you can live with JS. It has a nice community and very good tutorials.<p><a href="https://playground.babylonjs.com/" rel="nofollow">https://playground.babylonjs.com/</a> is nice to dabble and you can start right now.<p>You already know about shaders and pixels, but I really recommend doing a blender tutorial to understand the pipeline from modeling to computer graphics. There is a lot of shared terminology.<p>Aside from that, modelling can be immense fun.
If I were you, I'd focus on OpenGL 4.x. Going straight to the 3D API, since 2D these days is just a texture on the side of a 3D plane lol.<p>First thing you'll need is to somehow open a window in your preferred OS and language and get a simple "hello triangle" (many tutorials for that) running in any OpenGL version.<p>There are OpenGL bindings for most languages, so pick the one that gets you started fastest. I usually use Windows with C (through the raw win32 API - which isn't everybody's cup of tea and can be somewhat confusing), but maybe there are XCode projects that show a simple window with an OpenGL demo in Objective C or Swift.<p>Also if you're familiar with the Java world (maven, etc.) you can use LWJGL, which provides really simple Java wrappers around the OpenGL C API.<p>Once you have the window up and running, you should understand how GPUs actually work. GPUs are basically separate CPUs at this point, but they also do something that's tough to reproduce on a CPU: they do rasterization. That means they take a bunch of triangles, expressed as floating point numbers, and splat them all together onto a regular integer-based grid (your framebuffer for your monitor or game window).<p>The bare minimum for OpenGL 4.x is two shaders: a vertex shader and a fragment shader (fragment just means "pixel" unless you do more advanced stuff like multisampling antialiasing etc.)
The bare minimum vertex shader just takes a vertex and passes it through unchanged. The bare minimum fragment shader sets a color and takes no input.
Fragment shaders run after rasterization. That's why they operate on pixels. Vertex shaders run before rasterization.<p>Of course the GPU also does nice stuff like interpolating per-vertex values across each pixel of the triangle. That's why so many "hello triangle" delos show a gradient across the triangle. It's an easy easy to show off that feature (which is important for textures later).<p>I'd get away from thinking in terms of pixels/shapes/solids. There are higj-level wrappers around OpenGL that do such things (like Java3D), but are you really learning graphics if you don't study the bottom levels?<p>If you really want to start with 2D, I suggest going through all the steps of setting up OpenGL, and then just render two textured triangles forming a quad covering your window. Then to draw to the window in 2D, you just write to the texture buffer and re-send it to OpenGL. It's more work, but you'll be more confident going into real modern 3D stuff.<p>Hopefully I've given you some ideas. I think you're somewhat torn between low-level and high level, and I regret to inform you that you really can't easily have both out of the box, and you should probably start at the low-level.<p>Although, there are maybe some simplistic 3D engines like OpenScenGraph that might be close, in some ways, to what you want.