# How do 3d engines create frames? [closed]

I wanted to start on a little project of making a simple 3d engine, but I can't seem to find anywhere how 3d engines actually make frames. (I don't mean the math behind the 3d projection). Do they use bitmaps and edit the pixels, or do they use the GPU in some way? Also is editing the pixels in a bitmap using CPU or GPU?
EDIT:

I only mean after they do the math and find each pixel value for the frame how do they display the frame? Do they change the pixels in a bitmap while rendering a scene, or do they have an array that has all the pixels color values then use the GPU do display the pixels?

• Rather broad question. The rendering pipeline overview on the OpenGL wiki might be a good introduction.
– Anko
Sep 20, 2015 at 0:58
• It can be very similar from one engine to another. It could take a little book to answer completely. As @Anko suggested, you should take a look at some documentations than could explain you how complex it can be. Sep 20, 2015 at 1:30
• After setting all the pixels they just call SDL_GL_SwapBuffers or wglSwapBuffers or glXSwapBuffers (depending on platform). The GPU has already set the pixels in a big array called a back buffer. Sep 21, 2015 at 0:19

This isn't too complex. In fact, it behaves a lot like a 2D game does.

When a 3D engine renders a frame, it typically does so in stages. Sort of like photoshop really. And this can happen either on the CPU or the GPU. For most game engines, it's now the GPU that handles this.

So... the engine first creates what is called a "Swap Buffer". It is basically a contiguous block of memory (holds two frames) that our final image will be rendered into. When the frame is finished, the game engine will swap it with the old frame.

When the game renders, it's usually done in multiple passes. These passes will be basically screenshots that the engine will use. So in a way, yes you are creating RGBA pixels, and then you edit them.

Each of these passes will be seperate pieces of the same scene. So... Albedo, lighting, shadows, depth, ect.

The engine will then composite all of these together into the final image.

• So does it basically create a frame then display it when the next frame is being made? Sep 20, 2015 at 14:18
• Yup. You got it. Sep 20, 2015 at 18:49

All the projection and rendering is done on the GPU. When loading a level, the CPU reads meshes and textures from disk and uploads it to video memory of the GPU. In return, it gets integer numbers to later address those resources.

Every frame, the CPU sends commands to the GPU like "use mesh number 4 with texture number 7 and draw it". It also sends some data like the projection matrix and mesh positions. However we don't want to send more than needed every frame since the PCIe connection the the GPU is relatively slow.

When the GPU performs the rendering, the screen image is just treated like a texture of the size of the window internally. In fact, many engines draw to multiple textures in order to create more advanced graphics effects. Then, it is just another command that tells the GPU which image to send to the monitor.

By the way, the engine provides the code for both CPU and GPU (in form of shaders).