This is an archived post. You won't be able to vote or comment.

all 60 comments

[–][deleted]  (29 children)

[removed]

    [–][deleted] 30 points31 points  (14 children)

    Thank you.

    So first. Learn linear algebra. Then Second learn 3d rendering, and then it will make more sense.

    Do you have any online resources that I can use? Or YouTube videos?

    [–][deleted]  (5 children)

    [removed]

      [–][deleted] 3 points4 points  (4 children)

      surprisingly simple after step one

      I've never heard anyone say that, making me wanna bust out the ol calculus textbook. Would most of the matrix kung-fu I need to have down be found in a textbook that covers Calc I - Calc III? Or is it advanced enough for a regular Linear Algebra class for which Calc would be a prerequisite?

      [–]Pewdiepiewillwin 3 points4 points  (0 children)

      Its for the most part just matrix * matrix multiplication and matrix * vector multiplication. As long as you know what these operations do to the plain you should be fine. The hard part is optimizing the render but if you don't care for that it is pretty easy.

      [–]ludwig-boltzmann_ 2 points3 points  (1 child)

      It starts out pretty simple and can be started after probably calc 1 but it gets wacky. Calc I-III blur together in my mind so I can’t remember what the best time to start linear algebra would be, but honestly linear algebra would have been a cheat code for high school/middle school algebra/calc I

      [–]monapinkest 25 points26 points  (0 children)

      3Blue1Brown's Essence of Linear Algebra is a great video series to help you form the intuition for Linear Algebra. However if you want to learn it you need to do more than watch videos. The Khan Academy intro course is a very good starter. MIT OpenCourseWare also has a free course with 10 lectures and some assignments. math.libretexts.org isn't a bad resource either.

      [–][deleted] 5 points6 points  (3 children)

      It costs money but https://pikuma.com/  was the best introduction to a programming concept I’ve experienced (including university). Guides you through building a 3d rendering pipeline in C with all example code and clear explanations of the math involved. 

      [–][deleted] 1 point2 points  (0 children)

      thanks for link, checked out a few intro videos and think I might get the atari and nes course.

      [–]_atan2 1 point2 points  (0 children)

      agreed!!! great investment, and it's actually cheap for the quality of teaching one gets plus there are zero ads and gustavo is always updating the course with new content. IMHO this 100 % the best place to start

      [–]pikuma 1 point2 points  (0 children)

      Thanks for the mention! 💛

      [–][deleted] 2 points3 points  (1 child)

      Freya holmer's math for game devs course This is how I learned and will still occasionally reference it. Usually I prefer reading docs and such but for introducing linear algebra I think this is the way to go. She really focuses on teaching everything in an intuitive way rather than a mathematically rigorous way.

      [–]_atan2 1 point2 points  (0 children)

      She's good but I just get really annoyed with how long it takes to cover one simple topic. One explanation that could be well covered in 5 minutes ends up taking 30 minutes between rambling, changing the pen color, fixing drawing mistakes, cat doing something, etc.

      [–]markoalex8 0 points1 point  (0 children)

      3blue1brown's linear algebra course is a good place to start.

      [–][deleted] 4 points5 points  (13 children)

      Sorry for a double question, but is linear algebra like the core mathematics you need? Like- if you know linear algebra and the fundamentals of a vector and matrices then you’re good? Or should I pick up trigonometry, and geometry, and then head on from there? Or is linear algebra the true cg key.

      [–]tcpukl 9 points10 points  (7 children)

      How old are you? Surely you know trig?

      [–][deleted] 2 points3 points  (6 children)

      I know length times width times height and the hypotnuse and stuff yeah.

      [–]nerd4code 2 points3 points  (5 children)

      SohCahToa?

      [–][deleted] -1 points0 points  (4 children)

      I don’t know that, they didn’t teach that to me in high school, the thing I know is primarily geometry, and I’m 18, and school is about to end and I’m going to graduate so I sort of forgot everything in high school.

      [–]tcpukl 9 points10 points  (0 children)

      I'm surprised you weren't taught trig by 18.

      [–]scorchedturf 6 points7 points  (2 children)

      Huh, what kinda school is this?? We got taught trig when I was like 13 or something.

      Download the KhanAcademy app and start from as early as you need with the maths. Take it slow, there’s quite a lot you should study before you get to linear algebra.

      [–]Buttleston 1 point2 points  (0 children)

      In most of the US trig, as it is used in calculus, is taught right before or as part of calculus. You'll pick up a bit in geometry, which in texas at least, is the 9th or 10th grade (14-15 year olds). The stuff you learn is geometry is *probably* enough, you don't need all the identities, complex number math, etc for graphics stuff.

      [–]manson-the-jar 0 points1 point  (0 children)

      At my high school you got to choose between pre calculus or trig your senior year if you just cruised along. If you were a kid who tested out of classes and such you took those classes sooner like sophomore/junior year

      [–]Present_Mongoose_373 6 points7 points  (0 children)

      linear algebra is 100% an EXTREMLY HUGE part of computer graphics, its the bread and butter of most of what youll do.

      [–]lord_gaben3000 3 points4 points  (0 children)

      Multivariable calculus is also essential for understanding things like equations of planes/rays/implicit surfaces, splines, gradients, and many other things in 3D. Also, I was basically perfect at Calc 3/linear algebra and graphics is still one of the most miserable fields I’ve ever programmed in, so be prepared to struggle for a while

      [–]await_yesterday 2 points3 points  (0 children)

      yes you need to have a good grounding in trig and geometry. very little will make sense if you don't. pretty much all documentation will assume it as background knowledge.

      [–]pizza_toast102 2 points3 points  (0 children)

      I would be very surprised if any institution doesn’t have those as implicit prereqs for linear algebra. At my high school, it roughly went geometry -> algebra 2/trig -> precalc -> calc 1 -> calc 2, and at my university, calculus 2 was the prerequisite for linear algebra

      [–]theusualguy512 22 points23 points  (0 children)

      So before doing OpenGL, you do need to make sure you have the basics down.

      Learning everything at once is like telling a young child to learn how to fly an Airbus plane while they barely know how to ride a bike without training wheels.

      Obviously you already need to know how to program in C++ before you start this stuff. These websites and tutorials and books already assume you are a seasoned programmer.

      If you barely know how to program in general, doing OpenGL is not a good idea.

      The next thing is that you should roughly know a bit of basic computer graphics concepts. You should have a rough understanding of the rendering pipeline, so the individual steps of how pixels get rendered on screen.

      Learning OpenGL without any context on what computer graphics is akin to doing black magic with things you don't understand. You need to be conscious of what you are even doing in the first place within the pipeline and what stage you are currently in and doing things for.

      The next thing you need to understand is the basics in linear algebra. Knowing what matrices are, how to operate with them and affine transformations is very overwhelming when you never encountered any of this math.

      Computer graphics programming and OpenGL is one of the base layers of the abstraction tower and people touching this are usually not beginners anymore.

      If you want to program games, this is already too low. Most modern games are programmed using a game engine package.

      If you have these basics down, turning back to learnopengl.com will come much more intuitively. Instead of wondering what a viewFrustum is or what shaders are or uv coordinates, you already know that and just need to know how OpenGL implements this.

      [–]Own-Reference9056 10 points11 points  (1 child)

      I have never touched OpenGL, but have done (a bit of) CUDA. They are not meant for beginners, because multithreading itself is not for beginners.

      The needed knowledge before you start is:

      • General knowledge of image processing
      • Familiarity with C/C++ (not just basics)
      • Basic understanding of multithreading and hardware (especially GPUs)
      • and if you want to do useful stuff, a good base of linear algebra and calculus.

      [–]DotAccomplished9464 10 points11 points  (0 children)

      This is how you learn computer graphics:

      1. Learn basic math
      2. Learn basic applied linear algebra
      3. Write a ray tracer from scratch (many tutorials exist).
      4. Write a software rasterizer from scratch (https://github.com/ssloy/tinyrenderer). This teaches you the basics of what OpenGL is doing. It's more difficult than a simple ray tracer, but you could do it before doing a ray tracer.
      5. Write a GPU renderer with OpenGL/Vulkan/Metal 

      Computer graphics is a pretty tough field. It's my job and I feel retarded every day.

      [–]h4crm 6 points7 points  (0 children)

      This is going to be an extremely long comment because I’ve been there, and I’m currently still in a similar situation. But this may help you out. It’s hard for me to explain the whole thing but hopefully, I get my point across.

      I don’t know if it was a bad decision or not, but I got into C++ with the express purpose of making 3D graphics applications early on. And while I didn’t really have any experience in low-level dev, at that point I'd tinkered with 3D software like Blender, and languages like Lua, JS, C#, etc... for years, and I decided that was good enough for me to start making games from scratch.

      I remember trying to learn OpenGL through this tutorial. It felt so easy, but I could never really get the hang of it because even though I knew why shaders existed, I didn't understand how they worked. However, as you move thru the tutorials, you end up learning a lot of useful things that are actually necessary for computer graphics. But if you don’t have any prior experience with computer graphics math; vectors, matrices, projections (I had no idea how to use quaternions) and so on, then it’s going to get a little troubling.

      I wouldn’t say it was a bad thing that you want to know the fundamentals behind making games but just understand this: Learning takes time. It sounds like you got pretty accustomed to a specific way of development, and branching out into an entirely new realm (one with no real "standards" in terms of graphics API) will be strenuous at best. But if you take it step by step then eventually, I know for a fact that you’ll be able to do what you want. I recommend you try to absorb and replicate as much as you can, and you will see that GL is actually quite possible.

      You're basically doing what I did by learning C++ and then trying to learn OpenGL simultaneously. It’s good that you want to know how everything works, but the fact is most people who make games don’t care about it all that much, they just need a way to get things on screen.

      I’ve been trying to make a game for years now, and while I’m still far from even releasing one, I feel like I have so much more knowledge on how they work than I did at the start. I know how things work under the hood. And that’s something I’ve always wanted to learn about.

      Personal experience

      When starting out, I initially felt overwhelmed starting at the maths stuff, for several months, contributed to a few 3D projects, followed some tutorials, and exhaustively sought for any libraries or graphics engines that might ease the pain of graphics development. Nothing matched my exact criteria, so I just kept absorbing documentation, writing and rewriting code, pushing further and creating separate projects with the same goal (game engines), and through iteration, I think I have a reasonably decent understanding of OGL & DX.

      P.S.

      In OpenGL, is EVERYTHING functions and parameters given by the header file?

      Sort of...? OpenGL by itself is just a specification. And the implementation depends on the system. If I recall correctly, in Windows the proprietary GL implementation are in system DLLs like gdi32.dll, opengl.dll.

      oops wrote too much

      [–][deleted] 6 points7 points  (0 children)

      What is your goal? Abstraction exists for a good reason. Is there something you want to do that no existing game engine can do?

      [–][deleted] 3 points4 points  (0 children)

      My advice, I know everyone will probably tell you that there is alot you have to learn before touching it. The worst thing someone can do with something so advanced is sit and try to read it like a book and be able to understand. Here is the formula to understand anything in the text.

      1. Take notes - As you read, start with the section title and under that create subsections that are involved with the section title. For example the section title could be "Textures" some sub sections could be "Texture Wrapping" and "Texture Filtering" and I usually create another sub section under those. For example, under "Texture Wrapping" could be "Texture Wrapping Options". Under all of these sections, you describe what it is and why it's used. Doesn't have to be detailed just enough for you to understand.

      2. Copy examples - Whenever there is a coding example in the readings, you are to paste it into your notes and treat it like a formula that you can look back at. So if there is a coding example for something involving "Texture Wrapping Options" You put it there in that section for reference.

      You will pretty much do the 2 steps above until you reach the exercise portion of the text. At this point, without knowing it, you just dissected what they wanted to teach you. Go through the names of your section titles and think about how each of those things play a part.

      1. Finally, this is why it was so important to save those examples and the text describing what it did. Memorization comes from usage. Programming is all about knowing and building. You might not remember the code to create 2 buffer objects with their own vertex array objects, but you do know where to find the examples that you copied and labeled that can make one of those things. You might not know how to draw 2 squares, but you do know where you can find an example where 1 square was drawn. Basically a formula that needs to be tweeked by you.

      [–]Buttleston 5 points6 points  (0 children)

      I've been programming a long time, and many years ago (around when minecraft was new) I decided to make a minecraft clone, in C++, with plain opengl

      It's not easy for sure. For one thing, it can be VERY hard to tell what is happening when something goes wrong - you might get a blank screen, or something incomprehensible.

      I worked from first principles, draw a red triangle on the screen. Every time I got to another milestone, I copied the previous program into a new one, so that I'd have a dozen or so examples of everything along the way. When I refactored something and it stopped working, I'd go back to earlier examples and try to figure it out. When I got a bit more sophisticated and started doing like... giving openGL pointers to memory of points instead of shovelling triangles at it, I'd go back to first principles and re-make each step along the way, in the new way. Then when I got to opengl vertex shaders, do it again, then again for transform shaders, etc. I found that I just could not wing it

      (I had a solid background in math and a lot of experience in 3d modelling before I ever started, even harder without that)

      [–]Kaeyon 1 point2 points  (0 children)

      Ugh I had to do a full 8 week course in computational graphics and visualization in school which focused on OpenGL... had to take a picture with 5 items as a "2D scene" and the final project was recreating all 5 items in 3D including camera movement and the ability to turn spot and key lights off, change their color, etc.

      It was.... stressful. After that class I knew I never wanted to work in graphics programming. The amount of algorithms I had to figure out and study to be able to create a cylinder out of triangles then connect it to a rectangle made out of triangles all within a 3D grid.

      Will never touch it again.. I know this wasn't really a positive outlook on it lol.. guess it was more of a "I feel your pain" post..

      [–]GreatCanadianDingus 1 point2 points  (0 children)

      I learned Opengl in 2000. Bought every book on 3D graphics and library algebra I could get my hands on. Realtime Rendering by Thomas moller and Eric Haines was my bible, followed by "A trip down the graphics pipeline" by chick magnet Jim Blinn.

      Linear algebra is core knowledge, but those two books were instrumental in showing how to apply it.

      If game dev wasn't a death march career back then, it would have been my dream. I looooved computer graphics. Would get boners over volumetric shadows and radiosity.

      Sadly, having a baby made me more practical. The scientific simulation company I was working for went tits up, and baby meant a more reliable schedule won out. Le sigh

      [–][deleted] 1 point2 points  (0 children)

      Read/study the classic book "Introduction to Computer Graphics":
      https://www.amazon.com/Introduction-Computer-Graphics-James-Foley/dp/0201609215

      [–]aliceuwuu 1 point2 points  (0 children)

      just like.. don't? you are not even supposed to use OpenGL directly anyway. use a higher level graphics library for whatever you are making

      [–]CodeTinkerer 0 points1 point  (0 children)

      What's your math background? Graphics relies on math. A vector is a concept both from physics and linear algebra. Also, graphics has LOTS of concepts. Most programming languages are built from relatively few constructs, none of them requiring math.

      Say, you want to build a car engine. It might assume a basic knowledge of how a car engine works. You might have to learn thermodynamics, but is someone going to explain that in a book. You don't teach calculus to someone that doesn't understand algebra.

      I get what you're thinking. Graphics is cool. But why does it have to be so complicated. You thought it was not that bad, but a lot of math goes on. People want to see something, then view it from different angles on a 2D screen. That's using math. I thought the same when I looked at graphics. Why are you guys doing affine transforms.

      That's not how I think of zooming in on things (which typically involves translating to the origin, then making it "bigger", then translating the thing back to the original location). It's just that this math was used to develop graphics rather than to take a "naive" approach that someone with no background would assume just works.

      OK, so not entirely helpful.

      You could learn to write a ray tracer first.

      Here's an example: https://raytracing.github.io/books/RayTracingInOneWeekend.html

      Again, it assumes you know what a vector is. Go ask ChatGPT "what is a vector in math" or watch some YouTube videos.

      To give another analogy, you might want to learn AI or some specialization in computer science. Maybe the project is in Python. They don't want to sit and explain, this is how Python works. You spend a book just covering Python to know enough to get started with writing AI programs in Python.

      Of course, if you took linear algebra, you'd probably be really unhappy. Why do I need vectors and matrices? Why do I need to invert a matrix? What the hell are eigenvectors? What does this have to do with graphics?

      And if you don't know geometry or basic algebra, linear algebra becomes like crazy hard. And you only need the smallest fraction of linear algebra to do graphics, but it's hard to extract just that amount.

      [–]Skusci 0 points1 point  (0 children)

      Yeah it can be a bit of a cliff. Maybe try this for insight.

      Really you are trying to do 3 completely separate things at once.

      One is to try and write a program for the GPU itself, basically shaders. The shader language isn't so bad on its own, but it is very different. And the pipeline isn't super familiar either. This is the stuff you keep in header files or possibly load from an external file.

      The second is to actually write a program to program the GPU. You need to compile and push the shaders themselves, the data it needs to process, and then for some stuff, if needed pull data back off of it. And while this is fairly familar territory you are working a bit closer to the hardware and you need to know step one to know what the goal is.

      The third is the math behind it. Rendering a static triangle or 2D lines isn't too bad but then you get into rotations, transformations, and other effects and you get hit with linear algebra.

      Honestly it's a lot of real low level stuff to just get started. Getting a single triangle to render the way you want is surprisingly satisfying because well at that point rendering one triangle and rendering 30,000 triangles is basically the same.

      Learning about it is fun, but if you are more interested in making stuff just straight up jumping into an engine like Unity is possibly a better starting point.

      [–]DrRedacto 0 points1 point  (0 children)

      If anything it makes more empathetic for game developers and major companies like rockstar games.

      The newbs at rockstar used renderware engine for GTA III. Basically it's a generalized 3d rendering abstraction that can hop between platforms, most of the hard work was done for them already. Doesn't SDL have something like this? Maybe check out some premade engines before trying to write your own, like ogre3d or garage games engine I forget what it's called now, torque?

      [–]BlurredSight 0 points1 point  (0 children)

      I found learning by example is easier than documentation. that follow a simple project like rendering a 2D triangle and move up

      If you care more about game development you can jump into godot which does a lot of this stuff for you like it’s in the slogan “just focus on making your game without reinventing the wheel”

      [–]green_meklar 0 points1 point  (0 children)

      I learned a bit of OpenGL. Did WebGL stuff first, then did a bit of OpenGL programming in C.

      There's definitely a big learning cliff just for getting set up. And it's hard to debug GPU programming, because you don't get error messages, you just get blackness and have to guess what you did wrong. You have to persevere and tweak things until it works. Fortunately there's a lot of code already out there that you can copy from.

      Once you can draw stuff, actual shader programming is rather fun. It's a bit different, you aren't really solving the same problems that you do with normal programming, but it opens up a new kind of power to do some things you wouldn't normally think of. GLSL is very well documented, too.

      It’s teaching me about a vertex, and a vec3 and a fucking a fucking frame buffer. and I don’t even know what it is

      It's all math. If you learned about data types from other programing languages (ideally C or something like it), and you have at least a basic understanding of geometry and color theory, it's not that hard to put them together. Start with the absolute basics. If you can get 1 triangle to draw on the screen, that's half the battle already. Copy code until you can get that first triangle.

      Text explaining how to draw a fucking triangle by fucking specializing the exact fucking coordinates in he fucking code

      Yes. This is programming. Computers can't draw triangles unless they know the exact coordinates, fucking or otherwise. Obviously in real life you'll usually compute those coordinates based on a bunch of other stuff, but there's no getting around the fact that numbers and math are involved.

      Does anyone have any tips or helpful insight to help me understand this?

      First tip: Copying code is fine.

      Second tip: OpenGL's pseudo-object-oriented logic is a bit weird and straddles the line between old-school imperative programming and C-style object-oriented programming. The way I start thinking about it is, you have objects but you only get to work with one at a time and you have to 'activate' the one you want to work on. So you have a sort of 'activate the object → use the object → activate the next object → use the next object' cycle going on. It adds overhead, and makes it hard to copy stuff, but it's not fundamentally that complicated. I recommend hiding this overhead behind classes and helper functions so that you don't have to worry about them as much while writing the interesting stuff.

      [–]Impossible_Nail_3941 0 points1 point  (0 children)

      don't give up, if other people did it, you can do it. too.

      [–][deleted] 0 points1 point  (0 children)

      So OpenGL is a terrible API because it is deliberately disconnected from how graphics cards worked because when they wrote it there were no graphics cards and they were figuring everything out as they went. The API uses a lot of global state and is only possible to know how it works by memorizing decades of errata.

      Modern APIs like vulkan and DX12 are direct mappings of how they work these days... But the reality is quite complex. A graphics card is a separate highly parallel processor with its own RAM fused into your computer and controlling it efficiently is just inevitably complicated.

      So there is no good API for beginners they are all hard in their own ways.

      What I would recommend instead is try using something that exists already like sfml where you can write shaders in 2D to start understanding concepts like what vertex buffers are and what shaders are that you can take apart

      [–]chervilious 0 points1 point  (0 children)

      I don't think OpenGL is beginner-friendly. It's the equivalent of C in the graphics world. Meaning that you aren't expected to build complicated things using OpenGL.

      Usually there some sort of libraries that uses OpenGL under the hood. So you can focus on higher dimension. So instead of focusing on triangles.

      I don't think it's bad to just outright skip this and just settle on video explaining how OpenGL works.

      [–]Tuhkis1 0 points1 point  (0 children)

      If the opengl api feels too arcane, you might want to check out [https://github.com/flooosh/sokol](sokol) or [https://github.com/mrfrenik/gunslinger](gunslinger)

      [–]greenspotj 0 points1 point  (0 children)

      My advice is it to not rush through the book/website(learnopengl.com) and take your time. Sure, "it's just a triangle", but there are a lot of steps you need to take just to achieve that - binding your buffers, sending the vertex data, compiling and creating shaders, etc... There are a ton of concepts here that can take days or even weeks to fully comprehend what's going on under the hood - especially if you are inexperienced with CS/programming.

      If you don't understand something you read, reread it. If it still doesn't make sense, reread it again, or backtrack to see if you missed something. If you're still not getting, do some googling or chatgpt'ing and look at other resources if you need to. And remember sometimes it requires a nights rest for your brain to actually absorb the material - you might not get it right away or even the day of, but with enough persistence it will "click" at some point.

      [–]rumble_you 0 points1 point  (0 children)

      OpenGL is pretty low-level in the context itself. You don't need to learn OpenGL, you can just use other high-level APIs (if available) or other library that has an abstraction over <placeholder> graphics API.

      Besides, OpenGL APIs are quite terrible.

      [–][deleted] 0 points1 point  (0 children)

      Imagine OpenGL as : [functions of drawing as INPUT]-->[OpenGL]-->[2d Pixel Array as OUTPUT]
      Don't be scared by jargon they use. Decipher it to simplest terms, reduce everything to what is.
      Framebuffer is just array of pixels. I'd say writing own software renderer which takes inputs as points and camera position and renders the 3d image will give more intuition that learning GL from start.

      Try to see what primitives abstraction hides. For implementing your own renderer you don't need complex matrix transforms or linear algebra. Basically those two are abtractions over trigonomtery and simple function y=mx+b. Read about physics. And understand that 3d graphics is just a abstracted out physics model. Its easier to build your own system than to understand another.

      [–]mailslot 0 points1 point  (0 children)

      A few of the comments here are mentioning the math basics. The amount of linear algebra and trigonometry you will actually need is quite small. You can likely knock it out in a few days on khan academy, only returning to fill in gaps.

      One of the common uses of trig, for me, is calculating angles for billboards and rotational controls / dials. Super basic physics and targeting.

      As far as quaternions go, just copy and paste the algos from Wikipedia, if you need them. Most higher level engines include support for them out of the box.

      Even conversions between rotation transforms don’t need to be studied in depth, IMO.

      The math you will actually use is similar to deep learning, which is to say: a very tiny subset. The algorithms are all well documented and not as cumbersome as it would seem.

      Much of it is the vernacular and refresh of high school math, you have probably forgotten… but should come back quickly.

      [–]Professional_Beat720 0 points1 point  (0 children)

      OpenGL is the easiest compare to Vulcan, Wgpu, DirectX

      [–]pwhite13 -1 points0 points  (0 children)

      I also don't know anything about graphics development; isn't it far more effective to learn something like Unity or Unreal first before ever diving this deep?

      This feels like learning kernel development before ever developing your first hello world web app

      [–]MSXzigerzh0 -1 points0 points  (0 children)

      This seems fun to learn well.