Amazingly Flexible C code without OOP or FP Ideological Bullsh*t

Поделиться
HTML-код
  • Опубликовано: 14 июн 2024
  • Amazingly Flexible C code is at 12:46
    Chapters:
    - 00:00:00 - Intro
    - 00:00:56 - Recap
    - 00:03:48 - Near/Far Clipping Planes
    - 00:07:27 - Reproducing the Problem
    - 00:12:46 - Cup3d and Teapot3d share the same code
    - 00:16:38 - How the 3D demos work
    - 00:19:59 - Naive Attempt at Clipping Planes
    - 00:27:00 - Handling keys
    - 00:32:37 - Printing stats
    - 00:36:40 - Checking for NaNs
    - 00:42:18 - Infinite z-values
    - 00:44:50 - Clipping by 1/z
    - 00:46:42 - Pixel authorization
    - 00:47:59 - Testing the 1/z clipping
    - 00:48:55 - Q: Do you have a CS degree?
    - 00:50:10 - Q: Are you authorizing a pixel or vertex of a triangle?
    - 00:50:47 - Clipping planes almost work
    - 00:52:39 - Trying to gaslight myself into believing that there are no bugs
    - 00:53:03 - Reproducing bug with Cup3d
    - 00:54:06 - Negative z bug
    - 01:02:14 - Naive fix for the negative z bug
    - 01:05:11 - Q: How will you handle the rainbow texture with 2 triangles?
    - 01:06:42 - Looking for easier fix of negative z bug
    - 01:09:31 - Mirroring negative z values
    - 01:17:15 - Looking inside of the Utah Teapot
    - 01:20:05 - z == 0
    - 01:21:59 - Finalizing the solution
    - 01:32:18 - Outro
    - 01:33:07 - Smooch
    References:
    - Source Code: github.com/tsoding/olive.c
  • НаукаНаука

Комментарии • 109

  • @TsodingDaily
    @TsodingDaily  Год назад +38

    Amazingly Flexible C code is at 12:46

    • @ilyasabi8920
      @ilyasabi8920 Год назад

      Remember to not use Ru$T logo on your thumbnails apparently it's trademarked and illegal to use. They even force you to use CoC if you want to use rπst in your project. R÷st foundation what a joke 🤣😂

    • @spodarman3823
      @spodarman3823 Год назад +1

      Do u have a discord server?

    • @Halston.
      @Halston. Год назад +2

      customer wants teapot rendered about origin and a taurus at [100,0,0] how do i do?

    • @lizzyfleckenstein9837
      @lizzyfleckenstein9837 Год назад +3

      I fail to see how global variables have an advantage over passing arguments to a function here. As has already been pointed out, what if you want to load and render multiple models? What if you want to dynamically create a model at runtime? The code suddenly seems a lot less reusable/flexible. And solving it in a better way has nothing to do with bullshit like OOP or FP.
      I suppose that it's easier to generate C code with global variables, but imo generating code to include data in your program is a hack. Why not include the bytes directly in the binary? Linkers can easily do this. And modern languages have built in support to facilitate it, Rust has include_bytes! and procedural macros, Go has go:embed and go:generate, Zig allows for functions to be executed at compile time. All of these methods are a lot more ergonomic than putting together a Makefile (or similar) that ensures code gets generated, and they also take away the extra steps that you are putting the compiler through (first generating code from bytes, then having to parse it into bytes again).

    • @drygordspellweaver8761
      @drygordspellweaver8761 Год назад

      @@spodarman3823 he does but I was unable to get verified so can't speak in there

  • @anon_y_mousse
    @anon_y_mousse Год назад +59

    Just for future reference, if you need to look up a C standard library function, all of them have manpages. Even tells you what header to include and in some instances will show you examples.

    • @alurma
      @alurma Год назад +19

      Pretty sure he knows that

    • @ilyasabi8920
      @ilyasabi8920 Год назад

      Yeah he used on stream

    • @Kersich86
      @Kersich86 Год назад +2

      lol

    • @spicynoodle7419
      @spicynoodle7419 Год назад +6

      This is one of the best things. It I'm stranded on an island, a PC with Linux and GCC will serve me very well

    • @anon_y_mousse
      @anon_y_mousse Год назад +2

      @@ilyasabi8920 I've never seen the live stream, only ever watch the edited videos and not always on the same day.

  • @empireempire3545
    @empireempire3545 Год назад +50

    I love your coding style. And then i go to work and i love your style even more.

  • @petromudrievskyj
    @petromudrievskyj Год назад +14

    14:52 A concatenation is just a functor of the monoidal category of files

    • @drdca8263
      @drdca8263 Год назад +4

      Do you mean a functor from files x files to files?
      I think it would be clearer (and more specific) to say it is the monoidal product on it...
      But, really, I’m not sure what kind of morphisms you would have between files?
      Probably better to just say that strings with concatenation is a monoid, instead of mentioning categories?

    • @petromudrievskyj
      @petromudrievskyj Год назад +3

      @@drdca8263 You're right. At first I wrote "A set of files equipped with concatenation operation is just a monoid", but I wanted it to sound more like "A monad is just a monoid...", so I've changed it to this, which is also correct.
      Monoid can be viewed as monoidal category (see "monoid" page on ncatlab).
      The functor of monoidal category is it's tensor product (bifunctor), so there is no ambiguity there.
      As to morphisms in (not monoidal) category of files - command line utilities will do; they can be composed using pipe |

  • @jannemyllyla1223
    @jannemyllyla1223 Год назад +15

    I just started working at a company writing mostly C for their hw. I feel somehow dirty about how good working with the C feels.

    • @mattetis
      @mattetis Год назад

      What does hw mean? Hardware?

    • @jannemyllyla1223
      @jannemyllyla1223 Год назад +1

      @@mattetis well, technically it is an abstraction layer.

    • @mattetis
      @mattetis Год назад

      @@jannemyllyla1223 What? Does "hw" stand for "abstraction layer"? I'm lost 😂

    • @jannemyllyla1223
      @jannemyllyla1223 Год назад +4

      @@mattetis the code is part of an abstraction layer, but for the customers the whole thing is hardware.

  • @kingivan1151
    @kingivan1151 Год назад +23

    That is very neat, I never think to do #include "file.c" that is awesome. Thank you for sharing Mr emacs

    • @kingivan1151
      @kingivan1151 Год назад +14

      @@zweitekonto9654 I'm glad you are me and I am you

  • @dnkreative
    @dnkreative Год назад +7

    Clipping to near/far and any other planes happens in clip space, before projection, so there will be no divisions by zero or negative projection. Clipping triangles is not very difficult problem - only 3 cases to handle: all vertices behind a plane (triangle should not be rendered), some of the vertices lie on a plane - clip resolves to another triangle and general case when triangle needs to be split in two.

    • @AttackOnTyler
      @AttackOnTyler Год назад

      I was about to say, it looks like div by 0 errors, make the load take forever

  • @brainz80
    @brainz80 Год назад

    @tsoding Could forcing a 2d vector of 0, 0 in case z is less than or equal 0 work?

  • @arisweedler4703
    @arisweedler4703 Год назад +1

    "Isn't the flexibility of the demo system amazing" - as long as you understand that the API is loading values into global variables then it's great. I think a more normal API for this would be to have an asset be a pure data file, import a library to import the data into a variable, then import a library to display and call the display with the imported object. More normal is more complicated :D

  • @eduardabramovich1216
    @eduardabramovich1216 Год назад +1

    will u try odin lang?

  • @torphedo6286
    @torphedo6286 Год назад +12

    I kind of like this idea, but I also really don't like including C files...just habit, I guess. I include text files to make large string arrays using a separate asset file fairly often.
    I really love how simple and flexible the code here is, but on the other hand I really like being able to load those assets at runtime (partly because I then don't need to generate asset C files) They included all assets via build-time generated C arrays in the Mario 64 PC port, and it kinda sucks having to recompile the game every time you want to update an asset. Works amazing if your assets don't need to change often though

    • @henrikholst7490
      @henrikholst7490 2 месяца назад

      Back in pascal time this was the only way I knew how to do. Nobody used partial compilation except library makers.
      Btw check out TempleOS. The entire OS post kernel and compiler is compiled JIT and the kernel and compiler itself is compiled exactly like how Tsoding does here by including lots of files. No linking.

  • @varshneydevansh
    @varshneydevansh Год назад

    Where could I learn and improve my c++ and algorithm skill like yours?

  • @pokefreak2112
    @pokefreak2112 Год назад +2

    This is why I've never understood the argument of "global variables are inflexible/untestable". You can literally swap it out at any time? (including compile time as you demoed)

    • @HeihachiMishimaZaibatsu
      @HeihachiMishimaZaibatsu 8 месяцев назад

      Functions using those global variables are untestable by definition, because they can manipulate its state.

    • @pokefreak2112
      @pokefreak2112 8 месяцев назад

      @@HeihachiMishimaZaibatsu if you pass in a reference you can also mutate that state. The only difference is that the global saves a level of indirection. If you're multithreading your code you may need this indirection because threads must refer to different state, but in single threaded code I see no benefit in having it.

    • @HeihachiMishimaZaibatsu
      @HeihachiMishimaZaibatsu 8 месяцев назад

      @@pokefreak2112 that's why you don't pass references as arguments in FP, because data is immutable by definition. There is no such thing as "reference" in FP at all.
      In OOP however, your criticism is correct.

  • @brvtalcake
    @brvtalcake Год назад

    I laughed so hard when you talked about curing people in the field of philosophy, especially when you know how philosophers can be depressive as f

  • @AdityaPuranik1
    @AdityaPuranik1 Год назад +13

    Praise allah for HD strim.

  • @LuvingToryChristman
    @LuvingToryChristman Год назад +4

    Rust doesn’t compute anymore, so this was kinda refreshing! 🎉😊

    • @alurma
      @alurma Год назад +1

      Explain

    • @tcygnus
      @tcygnus Год назад +3

      @@alurma no

    • @alurma
      @alurma Год назад +3

      @@tcygnus what does it mean "Rust does not compute". What does this even mean

    • @tcygnus
      @tcygnus Год назад +5

      @@alurma I don’t know either

    • @antronixful
      @antronixful Год назад +1

      yeah, since rust stopped computing i feel i'm much more happy, i hate rust

  • @freestyle85
    @freestyle85 Год назад

    I thing you didn't fix the bug with mirorring a point with negative z-value. If z-value is a big (by module) and after mirorring you can get sitiation when the point will not clip and you will get some of artifacts on screen. But maybe I mistake.

    • @TsodingDaily
      @TsodingDaily  Год назад +2

      I don't really see how that can happen, but if you manage to reproduce that, please let me know!

    • @mrsesh7364
      @mrsesh7364 Год назад

      @@TsodingDaily If the negative value of the negative value falls between the near and far planes , will it be rendered?

  • @nickst2797
    @nickst2797 Год назад +3

    Could you please state your opinions on OOP andFP? (I do not know FP and i dont see any benefits of OOP - I prefer C style procedural programming).

    • @j3y445
      @j3y445 Год назад

      he always says the same thing. imperative C runs the world still to this day and everything else is a toy. OOP is just a syntax and FP is ideological bullshit. its pretty clear to see his stance if u watch one or two of his streams.

    • @torphedo6286
      @torphedo6286 Год назад +2

      Same here :)

    • @havenselph
      @havenselph Год назад +1

      The point of OOP is for ease of use, you can do anything you can in OOP with C, it just takes more time. Taken to the extreme, you have Python which might not be the quickest to run, but it kills any language in speed of implementation. Imagine loading a complex data structure like a CSV file in C; yuck.
      Either way, I love C, and I love Python, but they both have their own reasons to be used. I commonly implement in Python to learn how, then I implement in C, sometimes even Rust.

    • @Bobbias
      @Bobbias Год назад +4

      ​@@havenselph oop is primarily about hiding internal state of objects, making objects which the programmer can think of as being sufficiently like a primitive object that they can simply use without thinking about the implementation.
      Functional programming instead days everything is a function. Any data structure can be created out of functions. Functions can operate on other functions.
      In c, it's not often that you use callbacks, or function pointers (though not unheard of, of course) but passing functions into other functions to build up functionality is the entire basis of functional programming. If you really want to understand fp the best way to do so imo is to read through the first couple chapters of structure and interpretation of computer programs, SICP, which uses lisp/scheme as it's language. If you reach a point where you understand exactly what is being taught after a couple chapters, you'll understand exactly how fp differs from oop.

    • @havenselph
      @havenselph Год назад +1

      @@Bobbias I appreciate it, I've beem reading compiler design and interpreter crafting recently. Will look into that book as well.

  • @QckSGaming
    @QckSGaming Год назад +5

    Kinda the polar opposite of flexible but really cool system for this purpose.

    • @TsodingDaily
      @TsodingDaily  Год назад +9

      It's the most flexible hardcoded solution I've ever implemented 👌

    • @QckSGaming
      @QckSGaming Год назад +2

      @@TsodingDaily I love it :)

  • @contentprogramming
    @contentprogramming Год назад +1

    i think the video title should include "clipping" somewhere ;)

  • @pissnotime1894
    @pissnotime1894 11 месяцев назад +1

    ok, but in 2023 it's abnormal we still need to handle .h files and circular deps.
    preprocessor sucks.
    no metaprogramming.
    no dynamic dispatch.

  • @blu35cr3w
    @blu35cr3w Год назад +2

    Your teapot renders quite odd. Like it bending towards the viewport / viewer. It looks like it's bulging towards the user. For example: If the handle comes into sight (left background), your "funnel" has to be near the viewer at the same time (right foreground). But in the video it seems like it is bended like 90°. Otherwise great content! I like to watch or even listen to you.

    • @TsodingDaily
      @TsodingDaily  Год назад +9

      Yeah, this is because I used a pretty crappy projection that does not account for aspect ratio. Literally x' = x/z and y' = y/z. I'll clean it up at some point when I get to it.

    • @blu35cr3w
      @blu35cr3w Год назад +1

      @@TsodingDaily Never thought you would answer. That makes absolutely sense. Keep it up.

  • @cold_ultra
    @cold_ultra Год назад

    does it webscale tho?

  • @mushroomcrepes4780
    @mushroomcrepes4780 Год назад +1

    yay

  • @Vulto166
    @Vulto166 Год назад +1

    We can make nintendo 64 graphics with this library.
    This is cool!
    I know that it can make better things but i like the idea. 😅

  • @408sophon
    @408sophon Год назад +4

    I need help with what FP means. Somebody help pls

    • @TheArrowedKnee
      @TheArrowedKnee Год назад +6

      Functional programming?

    • @sorenvandenberg9909
      @sorenvandenberg9909 Год назад +8

      @@TheArrowedKnee Functional programming.

    • @izergaer
      @izergaer Год назад +3

      Functional programming🤔

    • @alurma
      @alurma Год назад

      Function programming has many definitions
      This style can be used in any real programming language. Some languages make it more convenient
      Some notable stuff
      - "first class" functions. Create functions on the fly, store them in variables, etc
      - accent on "immitability". Store immutable stuff in variables. Change variable values by reassigning new (say calculated) value. Counterexample: store mutable thing in a variable and change its contents
      There are more meanings, but this can get you started

    • @408sophon
      @408sophon Год назад +1

      Thanks all

  • @MikeHunt-fr7co
    @MikeHunt-fr7co Год назад +1

    It is a conflict of interest for google to provide good search results

  • @Salantor
    @Salantor Год назад +1

    I mean, you have one file containing the logic and two containing the data and you just import data when necessary. You can go for some FP and OOP bullshit here, but even for those two paradigms the solution would be pretty simple considering, again, that your logic and data are separated.

    • @HeihachiMishimaZaibatsu
      @HeihachiMishimaZaibatsu 8 месяцев назад

      The separation of data and business logic is actually a core concept of what you call "FP bullshit".

    • @Salantor
      @Salantor 8 месяцев назад

      I know.

  • @XELER53
    @XELER53 Год назад +4

    Zdravstvuite Tsoding

  • @Mariuspersem
    @Mariuspersem Год назад

    Who knew that tuskan raiders could program 1:02:07 ?

  • @Purkinje90
    @Purkinje90 Год назад +3

    Curing people in the field of philosophy 🤣

  • @Omar-fn2im
    @Omar-fn2im Год назад +9

    unbelievably based title

  • @KFlorent13
    @KFlorent13 Год назад +1

    15:32 Tu veux dire que tu es français depuis tout ce temps !!!!?

  • @ricardodasilva9241
    @ricardodasilva9241 Год назад

    Came for the part where you tell how one skip the bullshit ideology part. Found nothing :(
    I would be interested on the take though.

  • @yaksher
    @yaksher 11 месяцев назад +1

    Why not... have a function? Instead of just assuming a global variable.

  • @fasogoss
    @fasogoss Год назад +1

    First!

  • @antronixful
    @antronixful Год назад +6

    oop zzz, fp kinda sus

  • @blastygamez
    @blastygamez Год назад +5

    C is 1st in the best programming language made

  • @jordixboy
    @jordixboy Год назад

    meaning of FP

  • @drygordspellweaver8761
    @drygordspellweaver8761 Год назад +2

    You can tell a real programmer when they do ++i instead of i++ (unless its specifically desired)

  • @JuggernautWare
    @JuggernautWare Год назад

    Привет, а на русском языке ты пишешь видео?

  • @hamu_sando
    @hamu_sando Год назад

    I'd rather use Rust, Zig, Nim, Java+GraalVM, etc.

  • @geekdev0
    @geekdev0 Год назад +4

    go write 3d game in c

  • @user-dl9yl3wz3p
    @user-dl9yl3wz3p Год назад +3

    За ужасный французский акцент дизлайк и отписка.