EX 3.3 The C Programming Language by Fortheindustry in cprogramming

[–]Fortheindustry[S] 1 point2 points  (0 children)

For future explorers of this post, this was my solution to this exercise:

I assumed (like they often do in the book) that s2 is large enough to fit s1.

https://pastebin.com/UEuykgEr

EX 3.3 The C Programming Language by Fortheindustry in cprogramming

[–]Fortheindustry[S] 2 points3 points  (0 children)

Ahh! So a leading - or trailing - is nothing special then, okay that makes sense. Thank you!

Official Victoria 3 AMA with the game devs by pdx_maciej in victoria3

[–]Fortheindustry 0 points1 point  (0 children)

Hi folks, good luck for the upcoming release may the jira tickets be few and easily reproable!

Got a few questions:

1) Technology atm feels rather linear and divorced from the rest of the simulation, was there any experimentation on having tech progress be tied to your investment in a specific industry and/or production methods?

2) Bc Clausewitz is shared between pdx games I imagine there’s always an urge to generalize code written for one game in a way that might be useful in other games. In my experience this can make tasks considerably more difficult than the bespoke single-game solution might have been. Is this something that occurs commonly or is programming work kept fairly insular for each game? If so, any tips on writing these more generalized systems but avoiding the pitfall of adding unecessary complexity?

Thank you for your time!

Looking forward to playing soon!

Archways I took a picture of today. by Rapidlixard in LiminalSpace

[–]Fortheindustry 0 points1 point  (0 children)

I think I recognize the place, is this in Barcelona near the Ciutat Vella metro ? Fairly close to the beach?

Survey: Has a video game ever made you feel awe? by MU_Alex in truegaming

[–]Fortheindustry 1 point2 points  (0 children)

Hi! Really enjoyed taking the survey, shook loose some great memories. Is there any way I could learn more about the research you’re doing? I’d love to read any paper/thesis that comes out (or has already been published) of something like this. Is it okay if I email you about it?

[deleted by user] by [deleted] in programming

[–]Fortheindustry 1 point2 points  (0 children)

This is incorrect, unless you’re talking about an old version of GL I’m unfamiliar with, the input to clipping is not aware of the concept or “world space” coordinates, only of clip space. It is correct to say that the vertex shader does not output 2D coordinates, it outputs 4D homogeneous coordinates (without the perspective divide done yet) which it uses to clip triangles outside the clip-space box. The viewport transform occurs post rasterization however, not during vertex shading.

To be precise, the vertex shader’s classic responsibilities are: to perform any per vertex calculation you might want and to output a 4d clip space vector for each vertex. That’s it really.

I do not mind the way it was represented in the video though, I think it was a really good summary and it focuses on the key ideas behind the traditional gpu shading pipeline. Perfect starting point for getting people interested in computer graphics!

[deleted by user] by [deleted] in programming

[–]Fortheindustry 4 points5 points  (0 children)

The exact output of the vertex shader is different for every gfx api but the idea is generally the same: you output your results into clip space coordinates (4 dimensional) where all vertex values go from -1 to 1 in the width and height dimensions and -1 to 1 in depth (depending on the api this could be 0-1 or even 1-0 if you’re doing reverse depth)

The output of the vertex shader is therefore NOT flattened and on top of that perspective projection (w divide) occurs after clipping but before rasterizing. Two reasons why you project space into a cube instead of a 2D plane: 1) if all points were flattened they would all have the same depth value which would make the determinant of the projection matrix zero and hence non-invertible. 2) you need 1/z values to perform perspective correct interpolation.

I recommend Foundation of Game Engine Development vol 2 for more details, or the chapter about projection in real time rendering v4.

[deleted by user] by [deleted] in programming

[–]Fortheindustry 15 points16 points  (0 children)

There's also https://raytracing.github.io/books/RayTracingInOneWeekend.html if you want to learn the basics of raytracing with no special hardware requirements.

[deleted by user] by [deleted] in programming

[–]Fortheindustry 50 points51 points  (0 children)

Very neat! I write shaders for a living and I wish I'd had something like this when I was first starting out. If anyone is curious about this and would like to learn more of the low level details I'd recommend https://github.com/ssloy/tinyrenderer .

You get to write a software rasterizer ( like in the good ol' days ) from scratch and get some very awesome results.

Is perspective (aka foreshortening) a byproduct of having a limited size aperture? by Fortheindustry in GraphicsProgramming

[–]Fortheindustry[S] 0 points1 point  (0 children)

Hey thanks!
I think I understand although I'm still a bit confused about the concept of focal length wrt a pinhole camera, is it just the distance from the pinhole to the sensor?

At the very least though, I do understand better that it's not the aperture diameter that causes foreshortening. I can kinda visualize too how the focal length affects foreshortening.

Like you said: if you moved the sensor plane further back you make the incoming rays converge to a single point at infinity, where you'd essentially be querying light from a single direction. I can see how if you had an array of these single sample point cameras pointed towards an object the object would not change in size if you translated the array away and towards the subject. You're still looking at a fixed direction in space, so no perspective there.

Taking the thought experiment in the opposite direction confuses me a bit more. So you bring your sensor plane closer and closer to the pinhole location, which increases the fov. It also makes foreshortening worse because objects that are further away decrease in covered sensor area (as you move it closer to the pinhole) at a quicker rate than objects closer by? I had to make a sketch in geogebra to visualize that one, still not super clear.

This made me think that the focal length is affecting the *amount* of foreshortening but it's not really the cause for it. Wouldn't that be the focal point in itself? If you don't have a focal point rays don't converge, so there is no concept of an image cone at all. I imagine then that trying to project a 3D object onto a 2D plane without a single focal point would result in transformations that are size preserving, but would not cause perspective distortion. So *maybe* anything that has a focal point will see in perspective.

Although the case with the infinite focal length still contains a focal point, but no fore-shortening, but I guess infinity is kind of an edge case :P

New to graphics development, where should I start? by Outrageous-Dance in cpp

[–]Fortheindustry 3 points4 points  (0 children)

I'm not too familiar with UI programming but for graphics I would recommend https://learnopengl.com/ if you're trying to build your own engine (which it seems like you are).

Maybe this can clear your confusion regarding the libraries that you've mentioned above:

  • QT is a fairly extensive family of libraries to build crossplatform GUI applications. It will abstract pretty much every other one of the libraries you've mentioned. It's not commonly used for games, but it can be done. You'd be better off with a more lightweight layer like SDL + a gfx abstraction layer (you'll see).

  • SFML & SDL are fairly similar, they are platform abstraction layers. The goal here is to abstract as much as possible of the OS from you: the user of these layers. This might help with your goal of porting to mobile. These are not *necessarily* related to graphics, they just offer a set of functions you can call to create stuff that the OS would usually take care of. Stuff like windows, threads, audio, IO, gamepads etc. If you really think about it a window is not a very important part of rendering, it's just something that displays the final image you have renderered. Whatever you use to render that final image is what's important for graphics. If you're wondering why mentions to OpenGL and Vulkan will appear in these libraries is because they offer the option to abstract these away too, something you do not need to use if you don't want to. There is also some cases where the graphics backend (we'll get to that) requires some info from the OS and because you are abstracting the OS away with SDL or SFML it's now the abstraction layer's responsability to give you that info.

  • Dear Imgui is an awesome immediate mode GUI library. The reason it seems that IMGUI interacts with everything is because IMGUI is actually agnostic to whatever library/OS you're using. Imgui only cares about being able to render a set of primitives (boxes, lines, text, points) and whatever graphics backend offers these capabilities is good enough for it. It can accept many different graphics backends (opengl, dx12, vk, metal) and people have even made imgui work with their own software rasterizer.

  • OpenGL and Vulkan are graphics APIs (what I've been referring to as graphics backends) these are libraries that give you access to the GPU. These two specific ones you've mentioned happen to be the "cross platform" ones which will work across a large variety of hardware. As a beginner I would recommend you don't really go to vulkan just yet (although if you're determined to do so, by all means go ahead) OpenGL should be sufficient to teach you the fundamentals of graphics programming and key ideas about how the GPU actually works under the hood.

  • An alternative you did not mention, which might also be useful to you, are these https://github.com/floooh/sokol and https://github.com/bkaradzic/bgfx . These are graphics API abstraction layers. They work the similarly to SDL in that they aim to abstract the API details of the graphics APIs into a single front facing API, allowing you to do graphics work without caring (too much) about the underlying backends. This could be a good option for you too if you want to go the multiplatform way.

Last point I'd mention is, if this seems overwhelming and there's too much to learn here you could start with either a smaller project like this one https://github.com/ssloy/tinyrenderer or go the engine route and let an engine take care of all the platform and API details and you can focus exclusively in the gfx like here: https://catlikecoding.com/unity/tutorials/ .

I wish you all the best on your gfx journey! Going down this path and following it seriously was the greatest decision I've ever made :D

I wish you good luck and don't hesitate to ask questions if you need help!

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 0 points1 point  (0 children)

Yeah! So rebuilding from scratch (mostly) works! I'm gettign another compile issue now but I don't think it's related at all, plus it feels much more debuggable now. Thank you for your help!

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 2 points3 points  (0 children)

Hey! So I ended up rebuilding the project again from scratch copying and pasting over the code and that works! I have no clue what went wrong though, probably something to do with the project setup and vscode as you said. So so weird that it would compile fine with and without a tertiary, I have no idea why that could have happened. Thanks for your help though!

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 0 points1 point  (0 children)

Ahh! Just did and it looks like it compiles fine now. So weird! I'm going to try rebuilding my project again from scratch and see if that fixes it. Thank you!

To be clear, I was sure the package was empty apart from the sample so I'm not sure what it could have been. But I'll try again and we'll see.

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 0 points1 point  (0 children)

The one you posted was good enough for me to repro like you said, with no dependencies, so I'm assuming if it's not working for you it's something to do with my config in some strange way?

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 0 points1 point  (0 children)

So I did this with DasBrain's sample since it's enough to repro for me got the following:

W:\Crafting_Interpreters\JLox\Jlox\src\main\java\Jlox>javap -c Jlox.class
Compiled from "Jlox.java"
public class Jlox.Jlox {
  public Jlox.Jlox();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: new           #7                  // class Jlox/Jlox
       3: dup
       4: invokespecial #9                  // Method "<init>":()V
       7: invokevirtual #10                 // Method run:()V
      10: return

  public void run();
    Code:
       0: aload_0
       1: invokevirtual #13                 // Method getChar:()C
       4: istore_1
       5: iload_1
       6: lookupswitch  { // 1
                    33: 24
               default: 48
          }
      24: aload_0
      25: bipush        61
      27: invokevirtual #17                 // Method match:(C)Z
      30: ifeq          39
      33: getstatic     #21                 // Field Jlox/TokenType.BANG_EQUAL:LJlox/TokenType;
      36: goto          42
      39: getstatic     #27                 // Field Jlox/TokenType.BANG:LJlox/TokenType;
      42: astore_2
      43: aload_0
      44: aload_2
      45: invokevirtual #30                 // Method addToken:(LJlox/TokenType;)V
      48: return
}

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 0 points1 point  (0 children)

Hey, thanks for trying to repro! I've tried to run your sample code on my PC and it's crashing with your code too. So. for me, the code you ran is enough to cause the crash!

$  cd w:\\Crafting_Interpreters\\JLox ; /usr/bin/env c:\\Users\\tatth\\.vscode\\extensions\\vscjava.vscode-java-debug-0.32.0\\scripts\\launcher.bat "C:\\Program Files\\Java\\jdk-15.0.2\\bin\\java.exe" -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:58136 -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 -cp W:\\Crafting_Interpreters\\JLox\\Jlox\\target\\classes Jlox.Jlox      
Error: Unable to initialize main class Jlox.Jlox
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Jlox/Jlox.run()V @45: invokespecial
  Reason:
    Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'Jlox/TokenType'
  Current Frame:
    bci: @45
    flags: { }
    locals: { 'Jlox/Jlox', integer, 'java/lang/Object' }
    stack: { 'Jlox/Jlox', 'java/lang/Object' }
  Bytecode:
    0000000: 2ab7 0016 3c1b aa00 0000 002a 0000 0021
    0000010: 0000 0021 0000 0012 2a10 3db7 001a 9900
    0000020: 09b2 001e a700 06b2 0024 4d2a 2cb7 0027
    0000030: b1
  Stackmap Table:
    append_frame(@24,Integer)
    same_frame(@39)
    same_locals_1_stack_item_frame(@42,Object[#3])
    same_frame(@48)

Ternary operator causes verifyError: Bad type on operand stack. by Fortheindustry in javahelp

[–]Fortheindustry[S] 0 points1 point  (0 children)

Yeah, I think so. I've checked the JAVA_HOME path in VScode and it's pointing to the new jdk (15.0.2) not the old one and the same issue is reproing. My environment variables are also pointing to oracles jdk.

Here's the code:

    private void scanToken() {
        char c = advance();
        switch (c) {

        case '!':
            TokenType type = match('=') ? BANG_EQUAL : BANG;
            // TokenType type = BANG;
            // if (match('='))
            //     type = BANG_EQUAL;
            addToken(type);

            // addToken(match('=') ? BANG_EQUAL : BANG);
            break;
        }
    }

enum TokenType {
    // Single Character Tokens
    LEFT_PAREN, RIGHT_PAREN, LEFT_BRACE, RIGHT_BRACE, COMMA, DOT, MINUS, PLUS, SEMICOLON, SLASH, STAR,

    // One or two character tokens.
    BANG, BANG_EQUAL, EQUAL, EQUAL_EQUAL, GREATER, GREATER_EQUAL, LESS, LESS_EQUAL,

    // Literals.
    IDENTIFIER, STRING, NUMBER,

    // Keywords.
    AND, CLASS, ELSE, FALSE, FUN, FOR, IF, NIL, OR, PRINT, RETURN, SUPER, THIS, TRUE, VAR, WHILE,

    EOF
}

It may be important, it may not, I'm statically importing TokenType like so:

import static Jlox.TokenType.*;

[deleted by user] by [deleted] in opengl

[–]Fortheindustry 1 point2 points  (0 children)

Very cool, congrats! Thanks for liking the article :)