Implement 3D Software Engine as learning excercise

I want to follow this tutorial to implement a 3D Soft engine on top of OpenGL so that I can have a thorough understanding of 3D graphics.

I’ve searched the internet and it seems like I could use glDrawPixels but that’s been removed in “modern” OpenGL, the substitue seems to be glTexImage2d. But in both cases I’ve not found code that is simple and complete enough for me to put something together “quickly”.

Basically I want the CPU to be able write pixels to a buffer and then have those show up on the screen, really simple.

Anyway, I’d love some advice on the how I might accomplish this, txs in advance!

– Wink

In that case, OpenGL isn’t of much use to you. Either use the platform’s native windowing API, or if you want cross-platform something like SDL.

In that case, OpenGL isn’t of much use to you. Either use the platform’s native windowing API, or if you want cross-platform something like SDL.

I could use something else, but I’d like to learn OpenGL and I’m going to do the “soft 3d engine” in Zig which can use OpenGL running via GLFW and epoxy tetris.

I’ve taken what I’ve learned so far and can put up a window, handle input, create Texture, Framebuffer but can’t get pixels to display, see zig-3d-soft-engine. If I’m close maybe some simple suggestions will get me over the top. Otherwise, if I’m way off base, maybe a link to a C example that uses GLFW and OGL to get pixels (maybe from an image) to the screen.

Thanks!

Google “OpenGL Cookbook filetype: pdf”

This is a quiet easy to understand book with working tutorials. You have to read the whole first chapter in order to understand how OpenGL is set up properly. Maybe you should do the triangle tutorials too, to understand the concept of shaders. Afterwards you can skip everything and go directly to the textures tutorial. Then it should be easy:

  • Create a char/float array which holds RGB values for each pixel you want to draw. The size is simply resolution width x resolution height x 3 - decide for an ordering (column major / row major)
  • Create a Texture and transfer the array data
  • Create an rectangular vertex object (2 triangles) with 2 attributes (coordinates and tex-coordinate). The coordinates are chosen that the rectangle occupies the whole screen.
  • Create a simple pass through vertex shader and a fragment shader which reads the pixel color from the texture depending on the tex-coordinate.
  • Compile both shaders into a program
  • Activate the texture and the program. Then draw the object
  • If necessary, update the texture after each frame

This might not be very efficient, since updating a texture is rather expensive, but it should do the trick.

You can also read this:

https://open.gl/textures

The section “Loading texture images” has a short code snipped which creates a checker bard pattern and loads it into a texture. Adjust that to your needs.

@ProgrammerX, thanks most helpful !