i’ve recently made a hobby of trying out new things in C++/SDL2 every day and one things i would like to try is to tranform an SDL window into a first person viewpoint, but first i must know the basic tenants of an fps viewpoint. what makes a simple FPS viewpoint? i know i would have to come up with a z axis, as well as some sort of rotation method, but how in basic steps would i go about doing that with the most simple of C++/SDL2 format possible?
This is a pretty involved question. There are a number of ways to draw graphics in perspective, and SDL is better suited to some than others.
Option 1: Draw 2D images in perspective, the way you do on paper. Then you just draw them by conventional SDL means. There’s a pretty good youtube channel I’ve used called moderndayjames, if you’re interested.
Option 2: Scaling things on the fly. This is still a 2D technology, which means SDL can do this pretty easily, but you’ll need to read up on a bit of geometry to get it looking right. Farther objects look smaller (scale), look slower (delta) and appear closer to the center of the view than nearer ones, proportional to x/z.
Option 3: 3D rendering. SDL can do this through use of OpenGL. I have no experience with this, but as I understand it, you need to read up on both OpenGL and how to set up SDL to render OpenGL.
that second option sounds more like what i would be looking at, to make things a bit more clear, i got the idea of doing a barebones 3D engine like program from a channel i like called bisqwit, in a video where he made a doom-style 3d engine in C, he also provided a very basic 3D FPS perspective demo written in basic and i took that and took a few hours to convert it into C++, if you want ill link the video, but after i converted his qBasic program, i wanted to take it a step further and have more than a wall that the window can pan around, its also noted that this demo(both his original qBasic and my converted C++ demos) have an issue where even if the player is at a point where the wall shouldnt be rendered it is, it also has some perspective issues, but ill get the file and remove any of my custom dependencies from it and make it available here for you to try out
FpsDemoCode.txt (5.1 KB)
here is the file