Memory: Heap vs. Stack Where they go, and malloc() (which you've probably seen before) C++ and "new" int *array = new int[n]; delete [] array; Disclaimer: I use malloc a lot more than new Examples of memory addresses What if we allocate something that's inside a stack frame, and refer to it later? - Chaos... - Kind of anyway. Learn to control it in 475 General storage locations: heap, stack, code segement, BSS (where globals can go) Ok, passing pointers vs. passing values, demo C++ has pass-by-reference - demo So, C++ has THREE ways to pass a variable - And, pass-by-reference is NOT the same as passing a reference Extra super bonus way: const reference - Just means you don't want to make a copy - On 64-bit, references are often bigger than variables - The optimizer will only sort of do what you say anyway - But, it's not all-knowing! Use optimizations to help it along Note: Why is C++ so confusing? Because I'm showing you the gotchas that'll keep you up at night It's really a very nice language that only bites when you're not careful - Trying doesn't always count Classes Why private? - Do you have a clutch safety switch? - Why do elevators have doors? - People really do disagree over this for good reasons Anyway, variables are private by default Methods can be either OO terms: property, method, instance, class, reference - What exactly is an object? A thing... Let's make a vector of references to two different types of object They'll both inherit from the same class Just animals or something We'll use new, and both add and remove them Displaying with the Video Card, general procedure for OpenGL 4.0+ or Vulkan Load whatever you want to display in main memory Format should be xyzxyzxyz, or xyzwxyzwxyzw, or something like that Move the list of vertices into video memory Same thing for colors, if you want those rgbargbargba, or rgbrgbrgb, or something like that Load a vertex shader It's a program that says what to do with the vertices (transformations, etc) Can also assign color to a vertex Load a fragment shader It's a program that figures out what color each fragment should be fragment = pixel Input will include which vertices were used to determine this fragment Can also include a color, determined by what the vertex shader output Start the main loop, which will: Prepare the transformation matrix or matrices for the next scene, if anything is moving Clear the framebuffer Draw a new frame An example will be kind of lengthy, but we need to do it anyway! Probably won't finish today Main topic for next week How would Vulkan be different? Nothing in the above is wrong for vulkan But each step will require more detail OpenGL makes a lot of assumptions about what you want They'll be basically correct for what we're doing If they weren't, then we'd be in for a hard time of it Lab 2: Probably OpenGL Project 1: Probably using OpenGL and C++ to draw something, a "get your feet wet" project ifndef and the preprocessor extern Exception Handling (considered harmful?)