Thursday, October 5, 2017

Developing Winapi apps from a USB flash drive

Back at university, I'd like to continue to study Windows API, but I don't want to bring my entire laptop there, with campus being a little far from my dorm and especially with computers available there. I was thinking about moving some tools over to my USB flash drive to do so.

I was thinking the most important tools were a compiler and linker. In my C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin, there was a cl.exe compiler that represents the VC++14.0 compiler and a link.exe for linker. I saw they were command line tools, so I was assuming there was a way to do port tools like these to a USB, but I didn't know if those were the only ones I had to move. I was wondering if there was a download somewhere that could help me out with this.

So I asked on msdn about it, and got a lot of feedback/ideas. To get straight to the main idea, user Simple Samples recommended I try Eclipse for C/C++ for ease of use, and after a lot of research, I was able to get something portable working! I'd like to share my method here. Pretty sure it's working, I'll be doing the process again on a USB 3.0 external hard drive as I write this, to double check. If there are any more nuances/mistakes I find, I'll make sure to update it here.

Here's the main tools I used at the time I wrote this:
  -MinGW (g++ version says 6.3.0)
  -Eclipse Neon.3 IDE for C/C++ Developers, 64-bit (not the newest IDE at this time, I've just used that version before with Python)
  -JDK version 8u144 64-bit

Here's the general process:
  1. Download/unzip Eclipse to a folder on the USB.
  2. Download/install MinGW to a folder on the USB.
  3. Download/install the JDK to a folder on the USB.
  4. Setup the eclipse.ini file -vm option to point to the directory where the the Java Virtual Machine (javaw.exe) is intalled.
  5. Use setlocal and set to temporarily append the MinGW and MinGW\bin paths to PATH before running eclipse.
  6. Configure and run a Windows API project that uses the MinGW compiler toolchain.

Here's the process in detail:
1. Download the Eclipse Neon.3 IDE from the Eclipse website. Here's a link to the Neon.3 package listing. I chose to download using the Windows 64-bit option for my convenience. 32-bit is okay, but that means you must download either the 32-bit version of JDK (containing JRE) or just JRE by itself. Just to list it here, for the 64-bit download, I got a "eclipse-cpp-neon-3-win32-x86_64.zip".

2. When you open the zip file, you'll see a folder called "eclipse". Move/extract that folder to your root USB drive directory. At the time I'm doing this with my USB external drive, I moved it to F:\. (The directory where you place eclipse [and JDK and MinGW too] isn't important, but it's pretty convenient in my opinion to place it as the root usb directory.)

3. Download the MinGW GUI installer to install the MinGW compiler toolchain to your USB. You can go to the MinGW home page, and click the "Download Installer" button in the top right corner, which will redirect you to a SourceForge page to get the .exe. I got a "mingw-get-setup.exe" file.

4. Run the mingw .exe you got. In the license dialog, click Install. In the "Specify Installation Preferences" dialog, in the Installation Directory entry, click Change, and select a folder to install MinGW in. In my drive, I made a folder called F:\MinGW, just to be consistent with the default C:\MinGW installation path. From the MinGW Getting Started site, it's highly recommended to avoid paths w/ spaces.

5. Still in the "Specify Installation Preferences" dialog, check "... also install support for the graphical user interface.". Select the "... just for me (the current user)" radiobutton. (The Getting Started page recommends not to select the "all users" option. It was even disabled when I was doing this.) Uncheck the "... in the start menu" and "... on the desktop"  options.

Overall, I think these options are for the GUI tool called "MinGW Installation Manager" (in <mingw path>\bin) you can use for easy MinGW package management (including downloading, installing, and removing packages). I use that later on. It would make sense to just have it set for the current user since this is a portable install. And it wouldn't make sense to somehow link it to all the users of one computer, when you want to use the tools in multiple different computers. I deselect the start menu/desktop shortcut options also because it wouldn't make sense to have it since you're putting tools on a USB.

Here's a screenshot below of the options:



6. Click Continue. After the download of the MinGW Installation Manager is complete, click Continue. The manager will open up.

7. Click on the checkboxes for the following and click "Mark for Installation":
  -mingw-developer-toolkit
  -mingw-32-base (C compiler)
  -mingw-32-gcc-g++ (C++ compiler)
  -msys-base

I don't actually think you need the mingw-developer-toolkit and msys-base packages since the descriptions for those in the manager say they're for MSYS, which according to the MinGW homepage is a Unix-based command-line IDE. I'm just totally guessing here, so just to be safe, I include them.



8. Click Installation -> Apply Changes. Click Apply. Downloading and installing(copying) the files will take while. When it's done with everything, it'll display a dialog like below. Click Close. You'll see in the Installation Manager green check boxes next to successfully installed packages. You can close the Manager too.


9. The next thing is to install the right Java tools to get the Eclipse GUI running. From what I know so far, you need something called the Java Runtime Environment (JRE) in order to run GUI apps based on Java, like Eclipse. Some computers already have Java installed, and if a computer's PATH is set up right (especially to the right -bit version, like 32- or 64-bit), Eclipse will run. But it's handier to have a local one installed, especially for consistency.

Having the JRE by itself is good for end-users, but I'm going to use the JDK instead, which contains developer tools in addition to an end-user copy of the JRE in a folder called "jre". (There's no special purpose when talking about this installation, it's just my choice. I don't even know Java at this time haha.)

To emphasize, you must download the bit version of JDK that matches your Eclipse bit version. 64-bit Eclipse requires 64-bit JDK, which I'll be using.

So, to install the JDK, download the installation exe from the Java site. (The one for the 8u144 version I'm using is here). In the "Java SE Development Kit 8u144" section, I accepted with license agreement and downloaded the Windows x64 version, "jdk-8u144-windows-x64.exe". (You need to accept it before downloading.)

10. Run the java install .exe. When you get to the "Choose the Java features to install" dialog, click Change, and select/make a folder on your USB to install Java in. Like the MinGW install, I chose F:\Java\jdk1.8.0_144\ just for consistency. I think having a Java folder is a good idea since JDK (and standalone JRE) installations are just copying files, like the MinGW install, and you can have different versions in different folders without worrying about registry entries and whatnot. Click Next after you've set that up.

(After the download/install, the JDK folder will be set up, with "developer binaries" in the bin folder apparently containing more tools than a standalone JRE like "javac.exe". There'll also be an end user JRE in a "jre" folder, which itself contains another "bin" binaries folder. The installation dialog is still up at this point, I just wanted to point it out. You can see for yourself with Explorer).

 Now the installation dialog will ask you where you want to install a standalone JRE. Click Change, and select another, empty folder. I chose F:\Java\jre1.8.0_144. Continue/finish the install.

Looking at it now, it sounds a little confusing, having multiple JRE's available, each with the same javaw.exe Java Virtual Machine, aka JVM (not sure why it's called "javaw" though):
  1. <JDK path>\bin
  2. <JDK path>\jre\bin
  3. <JRE path>\bin

Any of those should work when setting up eclipse to use a given JVM.

11. To setup Eclipse to run its Java GUI based on the JRE you installed, open the eclipse.ini file that's in the same directory as eclipse.exe (mine is F:\eclipse\eclipse.ini). I prefer to open it in Notepad++ instead of Notepad because at least for me, the tabs/newlines don't display correctly in Notepad. Before the -vmargs listing (before the line that says -vmargs), Add the following options as two lines:

-vm
<directory containing JRE, javaw.exe [JVM] specifically>

You can use relative or absolute directories. This is what I put:

-vm
..\Java\jdk1.8.0_144\jre\bin
-vmargs
...

My file directory is like below:

F:\
  |
  -Java
  |
  -eclipse
    |
    -eclipse.ini

Don't use quotations marks, even if the directory you choose has spaces in it. The .ini can already process the line as is. If you put quotation marks, the .ini will literally try to look for a path containing a quotation mark. And since that never happens, running Eclipse (eclipse.exe) won't work.

If Eclipse can't find the JRE and therefore a JVM in that JRE, it'll display an error message box about it. Here's what it looks like


11. Before running eclipse.exe, temporarily edit your PATH variable in cmd to point to <MinGW install location> and <MinGW install location>\bin. I don't know batch scripting, but I'm familiar with cmd, so I opened it up and used these commands before running eclipse.exe.

setlocal
set PATH=%PATH%;F:\MinGW;F:\MinGW\bin

12. Run eclipse.exe from the cmd. Choose a workspace to place your projects in. I chose F:\workspace.

13. Now to setup and run a Winapi project. When the GUI comes up, click the Restore button on the top left. It's the button that looks like two cascading windows. This'll setup the Eclipse GUI so that you can see your C/C++ IDE tools.


14. Click File->New->C++ Project. Type a project name. Choose "Empty Project" for Project Type. Choose "Use default location", which will place your project folder in your workspace. Choose "MinGW GCC" as your compiler toolchain. My dialog's like below:


15. Click Finish. Click File->New->Source File. In the Source File edit box, type a name. I chose main.cpp. Click Finish.



16. (NOTE: I forgot to set up my PATH in cmd when I wrote this, and I edited in what's not Step 11. The dialog below may look different for the MINGW_HOME and MSYS_HOME variables, but the process is still the same.)

Before typing in Winapi source, set up the Project Properties. I'll start with the Environment variables. Go to Project -> Properties -> C/C++ Build -> Environment. The MINGW_HOME and MSYS_HOME are of interest. (MSYS_HOME has no effect in the overall build, but there's no harm in properly setting it, so I'll mention it here).  Set the Configuration dropdown to [All Configurations] so you can edit the Debug and Release settings at the same time.

To edit the environment variables to use the right drive letter, I added my own for my convenience called USB_ROOT for convenience. To add one, click Add, type in the environment variable name you want. Type in the root. (I prefer not adding the backslash here, so that I explicitly type it in the Properties dialog later). Click OK. Here's what my dialog looks like now:


17. Edit the MINGW_HOME and MSYS_HOME path variables to use the root variable you use. Select a variable, click Edit, and change as needed. Use the dollar sign and bracket notation to do so. Here's my new dialog:


18. Next is to edit the C++ include search path so that Eclipse can correctly find/parse header files, especially windows.h. Still in the Properties dialog, go to C/C++ General -> Paths and Symbols. Select GNU C++ in the Languages section. For the Include directories section, click Add. Click File System to search for your <mingw install path>\include folder. (Mine was F:\MinGW\Include). Click ok. This is what my dialog looks like now:


When you click ok, you may see a warning about "Duplicate paths". Here's the complete info. dump when I right-clicked to Copy the warning (the first line is more about just copying section headers):

Description Resource Path Location Type
Invalid project path: Duplicate path entries found (/TestWin [Include path] isSystemInclude:true includePath:F:/MinGW/include), path: [/TestWin]. TestWin pathentry Path Entry Problem



I googled this, and saw it may be actually a bug. Here's the bug report I found. It says Rebuilding the project is a possible fix, but it still appears for me. It may be possible to fix, from what I've seen from google so far, but now, for this blog, I'll ignore it.

19. Type in your Winapi source. Here's a dropbox link to my main.cpp. All credits go to Brook Miles site "theForger's Win32 API Programming Tutorial" (my first Winapi tutorial too : )   ) .

20. Build and Run. And that's it! Here's my final result:



I think what would be important is what's below as you move to different computers, as the drive name can change:
  -setting up your PATH variable
  -making sure right drive is specified when choosing workspace
  -updating Project -> Properties -> C/C++ Build -> Environment
  -updating Project -> Properties -> Paths and Symbols, and the GNU C++ and Include Directories entries
  -updating your eclipse.ini file, if you chose to make it absolute instead of relative

I feel like this can be automated with batch scripting, a Powershell script, or python if you can make it portable. I don't know batch or Powershell at this point. For Python, I'm sure it can be done. Overall, for the Project Properties, you'd have to find the right file to edit though, which I don't know at this point.

Post Notes:
-When you install MinGW with MSYS, I think you need to set up MSYS in some way to use the MinGW you installed. I haven't tried this yet. One of the blogs I researched mentioned this, if you're interested. But oveall though, you don't need to set up MSYS to use MinGW. MSYS is a set of coding tools in UNIX, completely separate from MinGW when you initially install them.

-You can set up the Project Properties before adding a source file.

-Editing the PATH variable to the right MinGW location is important. If you look in the screenshot for Step 16, you'll the default MINGW_HOME and MSYS_HOME variables point to a mingw install I did on my laptop's C drive. Without editing PATH, you may not get the MinGW GCC toolchain option when you first make a new project (if a computer doesn't have MinGW installed locally). (Check?)

-This is a YouTube tutorial that helped me to install MinGW. It's pretty funny too.

-It's good to install eclipse, MinGW, and JDK/JRE to new/empty folders. Since they don't depend on environment variables or the Registry, if you wanted to "uninstall" them, you just delete the folders. As a side note, I think that's how install/uninstall were done back then, just copy/paste files. The environment variables and the registry, combined with installation dialogs, just make it easier for the end-user. At least I'm guessing that's how it works.

-Your drive file system shouldn't matter. I initially did this on a USB flash drive with a FAT32 file system. I wrote this blog doing this on a USB 3.0 external hard drive, formatted to NTFS (I checked by right clicking on them in Explorer and clicked on Properties). They both worked.

-Having a USB w/ fast read/write is good. From a quick search, looks like they don't really give that info. You'd have to manually test it yourself with some program. SanDisk is a good brand, from my experience. USB 3.0 is of course the way to go here.

-With developing with a USB, you'll be wearing it out faster. It's good to make backups and not store critical files here permanently.

-Looks like by default, MinGW links Windows API libraries for you without you having to specify them in the compiler options (the ones that came with the mingw32-base package, according to the Installation Manager). That's pretty handy, especially if you're just starting out doing this.

-In your MinGW installation folder, in the bin folder, you'll find mingw-get.exe that's the MinGW GUI Installation Manager. I'm guessing you only get this if you choose the "install support for GUI" option during the install process

-In the overall process, I've realized that developing Winapi apps isn't exclusive to the VC++ compiler. That's pretty cool.

-Using the --version option in a mingw compiler like g++.exe or mingw32-g++.exe will give you the version number. At this time, my MinGW version was listed as "(MinGW.org GCC-6.3.0-1) 6.3.0".

-Eclipse versions are sort of confusing at first, in my opinion. What you see most directly is the version name and not number. Seems like Eclipse likes to name its versions based on outer space. What I've found was that different named Eclipse versions represent different major releases of Eclipse. Then, minor version releases are named using letters and numbers, with newer versions coming in later numbers or letters. You can see the complete listing here

-User Pavel A from that msdn post I linked mentioned CDT. I think that's more of a plugin. I got an IDE. I don't think they're the same. The CDT sounds harder to install. That's what I did, for ease-of-use purposes.

Sites:

I researched a lot of sites while doing this. I tried to keep as much as them as I could while doing the research, thought it'd be nice to share it on this blog post.

Eclipse on a USB Flashdrive
How to compile and run C++ with MinGW using Eclipse and CDT? - Stack Overflow
Installing Eclipse for C/C++ and MinGW | Another day at the office...
c++ - Configuring Eclipse for MinGW - Stack Overflow
Portable MinGW and MSYS
MinGW Site, Getting Started
MinGW Site, HOWTO Install the MinGW (GCC) Compiler Suite
omtlab - Configure your eclipse for C++
Stack Overflow - How to find out if an installed Eclipse is 32 or 64 bit version?
Stack Overflow - What is the difference between JVM, JDK, JRE & OpenJDK?

Some sites I ended up putting on my txt list don't seem relevant to this post now that I look at it, but I still thought it'd be nice to share them:

Stack Overflow - Eclipse CDT Debug not in executable format: File format not recognized after strawberry installation
Eclipse Forums - "Failure to execute MI command during Debug - Helios"

Tuesday, August 29, 2017

Building pbrt-v3 in VS 2015, other notes

I thought I'd write other things I found interesting while writing in my blog about how I built pbrt-v3. Again, I hardly know anything about pbrt itself or Cmake, but I still I thought it'd be cool to share what I found about them (and the whole process in general, too).

-Two major things I put here:
  -Debug vs. Release build of pbrt
  -Possible minor bug fix with PBRT_FLOAT_AS_DOUBLE

-The pbrt authors included a Users' Guide in their site. They also provide info. about their Input File Format (probably about the .pbrt files like "teapot-metal.pbrt".

-Biggest thing to note: from the pbrt site, pbrt in "Debug mode" is understandably very slow compared to "Release mode". For "Release mode" and the faster render times, during CMake usage, the option CMAKE_BUILD_TYPE is automatically set to "Release".

But you can still build the VS solution in Debug mode, and the corresponding pbrt.exe outputs the banner *** DEBUG BUILD *** when you run it, to notify you of slow rendering times for debugging purposes. So make sure to also build the solution in Release mode if you just want to render.

Again, the differences are massive. I only found this out today, as I'm writing this! haha. I didn't really read the banner, I was just focused on getting something to work when I first did this.

Here's two images showing how different the rendering times are:

Debug build (also my first successful pbrt render back in January!): 26572.9s = 7.4 hrs



Release build: 880.5s = 14.675 min (30x faster!)


-Possible minor bug fix:

EDIT: got a confirmation from one of the pbrt authors! : ) was a bug. better solution than pointer casting is to actually create a local Float[] array where you can pass in float elements that can be implicitly converted to double elements, see highlighted edit below

(Basically, found if you #define PBRT_FLOAT_AS_DOUBLE, get an error in ptex.cpp, line 130 in VS 2015 saying can't convert a "float*" to "const pbrt::Float[]", which now is "const double[]", explicitly casting the result variable in that line to "const pbrt::Float*" worked for me)

The pbrt site says you can uncomment the //#define PBRT_FLOAT_AS_DOUBLE line in the src/core/pbrt.h file that's in the pbrt repo you can check out. You can do this even if you already have a pbrt VS solution made, since it's just a .h file you're editing.

When I built on Release - x64, however, I got these errors:

C2664 'pbrt::RGBSpectrum pbrt::RGBSpectrum::FromRGB(const pbrt::Float [],pbrt::SpectrumType)': cannot convert argument 1 from 'float *' to 'const pbrt::Float[]'

argument of type "float *" is incompatible with parameter of type "const pbrt::Float"




This is in a file called ptex.cpp, in line 130, in the pbrt project. From looking at the project properties, the pbrt project is supposed to make some "libpbrt.lib" library. With this error, the .lib file isn't made, which caused errors about not being able to open that .lib file.



The function definition containing line 130 is:

template <>
inline Spectrum fromResult<Spectrum>(int nc, float *result) {
if (nc == 1)
return Spectrum(result[0]);
else
return Spectrum::FromRGB(result);
}

Wasn't familiar with the "template <>" or "inline" keywords at the time, but saw with VS that Spectrum::FromRGB takes a "const pbrt::Float *" as its first argument. Looking back at the pbrt.h file, turning on PBRT_FLOAT_AS_DOUBLE changes the Float typedef from a float to a double (also, the pbrt.h defines this in a pbrt namespace [hence pbrt::Float]):

#define PBRT_FLOAT_AS_DOUBLE
#ifdef PBRT_FLOAT_AS_DOUBLE
typedef double Float;
#else
typedef float Float;
#endif  // PBRT_FLOAT_AS_DOUBLE

So going back to that code snippet, since "const pbrt::Float*" pretty much meants "const double *", passing "result" tries to implicitly convert a float* to a double*, and apparently that's an error in VS 2015 (not sure if that's universal).

So I put an explicit cast like below, built the solution again, and it worked.

return Spectrum::FromRGB((const pbrt::Float*)result);

I wrote about the bug fix I did in the Github issue tracker for the pbrt repo. It's minor compared to the entire scope of pbrt itself, but I thought it could help. Interestingly, I looked back at the pbrt solution I made back in January, and didn't find a ptex.cpp file there. Looks like this is relatively new. May be related to some texture cache feature they implemented back in March, according to their site news.

Edit  Got a confirmation that this line was a bug. One of the pbrt authors pushed a fix today

template <>
inline Spectrum fromResult<Spectrum>(int nc, float *result) {
if (nc == 1)
return Spectrum(result[0]);
else {
Float rgb[3] = { result[0], result[1], result[2] };
return Spectrum::FromRGB(rgb);
}

}


This is a better solution, to actually pass a pbrt::Float[] into Spectrum::FromRGB by creating a local Float array variable called "rgb". (I assume the size is 3 just because "rgb" is 3 values.) Looks like since it's assured that the array pointed to by "result" is size 3, can initialize the "rgb" by passing in float values pointed to by the "result" array. The values are then implicitly converted to double values since Float is of type double due to the PBRT_FLOAT_AS_DOUBLE define, and then the array is good to go to be passed into the "FromRGB" function.

Cleaner and makes more sense than converting a float* to a double*, but still, happy I got some sort of bug fix working. Pretty cool, this would be the first bug I ever found in source code as big as this. Minor bug, but still, big self-achievement for me! : )

-The pbrt site says it supports pfm, exr, tga, png file formats (where pfm and exr are more "accurate" file formats because they can store floats for what I think are color values). In the "teapot-metal.pbrt" file, in line 9 (doing this from Notepad++), you can change "teapot-metal.exr" to "teapot-metal.png" if you just want to see the image in a program like IrfanView immediately.



The pbrt-v3-scenes folder contains already made .exr files at pbrt-v3-scenes/images. A teapot-metal.exr is available in the "simple" folder.


-If you try to "Download ZIP" at the pbrt repo site or try to do clone the repo w/o the --recursive flag, you'll get an error in CMake GUI about the flag.


-When running "pbrt teapot-metal.pbrt" in cmd, teapot-metal.pbrt references other files. If it doesn't find them, it shows a warning, like below. The .pbrt file uses custom-made text inputs, from what I'm seeing. They include references to other files.



Building pbrt-v3 in VS 2015, rendering a metal teapot

Finding Physically Based Rendering: From Theory to Implementation at my university last August and then figuring out this January how to build pbrt-v3 and use cmake for the first time was really exciting for me. Hardly knew anything about them then (and now too haha), but would like to look more into raytracing with this in the future.

For now, I'd like to share the bare steps I took to get pbrt-v3 built in VS 2015 in 64-bit and to render a "teapot-metal.pbrt" sample. Again, I know close to nothing about pbrt and little about cmake, but I still think it'd be cool to share the steps I found to get something rendered here, for people interested in computer graphics at this level.

EDIT: Important to note is that Debug build of pbrt for debugging purposes runs way slower than Release build. Also, possible minor bug fix with PBRT_FLOAT_AS_DOUBLE. Made general other notes about pbrt in a blog post here

(Using Windows 8.1, Visual Studio 2015, and CMake 3.7.2. For git, I just got it working by installing Github Desktop for Windows)

1. Open cmd. Switch to a folder where you want the pbrt-v3 source code folder to be cloned into.

2. Type "git clone --recursive https://github.com/mmp/pbrt-v3/.
  -Cloning will take a while. A folder named "pbrt-v3" will appear when done.

3. Open CMake GUI.
  -For "Where is the source code", click "Browse Source", and select the "pbrt-v3" folder.
  -For "Where to build the binaries", select an empty folder. I made a folder called "pbrt_build".

4. Click "Configure". In "Specify the generator for this project", Select "Visual Studio 14 2015 Win64" (this will make a VS 2015 solution that only has a 64-bit build option). Click Finish.

5. CMake will do configuration processing. When it's finished, it'll show values in red. Click "Configure" again to confirm the configuration.

6. Click "Generate" to actually create a VS 2015 solution. Then click "Open Project" to open the solution.

7. VS 2015 will probably do some initial processing. When it's done, click "Build -> Build Solution".
  -The configuration I'm building in is Debug - x64.

8. With a successful build, you'll get a "pbrt.exe" to use. I'd say check it out at this point, for curiosity.

  -To check out the build, open your solution directory (you can right-click "Solution 'PBRT-V3' (40 projects)" in the Solution Explorer and click "Open Folder in File Explorer").

  -Open the Debug folder from there. There'll be a bunch of exes, "pbrt.exe" included. Open cmd in the Debug folder (you can Shift -> Right-click -> Open command window here, for convenience).

  -Type "pbrt". You'll see version information. Hit "Ctrl+C" at the prompt to exit the program.



9. Knowing about pbrt.exe, you can render a sample. I'll be focusing on a file set based on a teapot-metal.pbrt. To check out the entire sample set linked in the pbrt site, follow steps 10 and 11. The sample set is massive, 10 GB, so I provided the files for the teapot in my dropbox in step 12 if you just want that.

10. To check out the entire 10 GB sample set linked in the pbrt site, in cmd, switch to a folder where you want to clone a "pbrt-v3-scenes" folder into.

11. Type "git clone git://git.pbrt.org/pbrt-v3-scenes".
  -The scenes folder is super massive, 10 GB. Cloning seems to compress the folder to ~3.11 GB from looking at cmd, but still very large.



12. If you want to just get the files for rendering the sample teapot I'll be using, here's a link in my dropbox. Download all the files somewhere. Make sure to preserve the directory structure. The files referenced in teapot-metal.pbrt are relative.

13. Run cmd. Type "pbrt <directory>\teapot-metal.pbrt". For my computer, I downloaded the entire 10 GB sample set, and I typed:

pbrt "C:\Users\Nicolas\Desktop\pbrt_test\pbrt-v3-scenes\simple\teapot-metal.pbrt"

  -You should see licensing info. immediately, and a progress bar appear after a while (probably due to some pre-procsessing stuff).

14. Wait a long time. Keep your computer on.
  -When I did my first pbrt render with this teapot, the stats showed 26752.9 seconds. (That's 7.4 hours!)

15. On completion, you'll see a teapot-metal.exr file in the same directory as where you ran the pbrt command. Open/convert as needed. For me, I had to convert it to some file I could open. Currently, I find you can use Convertio to convert an exr to a jpg for example. It's free, no hassle.

16. That's it! Here's the jpg I got while writing this:







Saturday, August 12, 2017

Information Overload Thoughts

I had a sticky note about something along the lines of "blog about society changing with the information overload shift". I think it said that, I just deleted it on Sticky Notes a few seconds ago, and unfortunately there's no Undo.

I had that for a while now after last university quarter as a freshman. I'd just finished a linear algebra class, my last writing class, and an intermediate python programming class. And to really emphasize it, that was my last official general writing class. Looking at the course catalog, I think I'm required to take an "upper division computer science writing class", but other than that, that was in a sense my last writing class I'd ever have to take in life.

Anyways, I'm being vague about the class details, sorry, but I want to focus on my thoughts on the end of the quarter. My last writing class's focus was on "Argument & Research". Apparently, at the end of the quarter and my first freshman year, I was having thoughts about being information overloaded. Like, I was thinking to myself, "Isn't taking ~3 to 4 classes per 10 week quarter to graduate a tiny bit too much?" It's a lot of information to digest and think about, in my opinion. Though I did well in all my classes last quarter, I'd often think to myself that 3 to 4 classes in that time span is a little bit much to ask.

And I'd have thoughts about what if the university requirement was lowered so that you could pace yourself to around 2 to 3 classes per quarter to graduate. Put less stress on yourself, dedicate more time to the content of classes, allow students to pursue their own interests. I think that the more you encourage people to pursue their own interests, the more it'll benefit them in the long run, and I think that'll make for a better education (and better life accomplishments in general).

Looking back at it more, I'd say even middle school and high school were more content packed, at least from my experience. I remember doing a lot of worksheets and projects, like --a lot-- of them, really. I mean, the subjects were interesting. Going off the top of my head, I took classes about life science, algebra 1 and algebra 2. Band elective in middle school. Art in high school. Spanish 1-2 and Spanish 3-4 in high school. They were interesting, but keeping up with them was really hard. That was like, 6 - 8 subjects per week, looking back at a high school calendar pdf I scanned. Like 3 classes on a Monday, the other 3 on a Tuesday, and with homework. (And also, summer reading! I just wanted to take a break, but in middle school and high school, had to read a book and do a report over the summer. Just wanted a full break then though!)

So alright, now that I think about it, I do see my university schedule as more flexible than my middle school and high school one. Like, a lot. I guess I also feel more flexible since I dorm around the campus. So yes, I am thankful for the change of pace from high school to university. But nonetheless, I'd argue that multitasking with at least 3 to 4 classes is a little bit over the top, regardless of type of schooling, if someone wanted to seriously study all those subjects.

However, I do realize that dropping the amount of classes can have a lot of cons too. People could feel less motivated. And at least in the university, professors and staff may have thought a long time on how courses should be structured or the content they want to present to a student taking a certain major, like Biology or Computer Science. So they can be justified in course rigor. Also, having various classes would help someone gain breadth, knowledge-wise. Like, gaining familiarity with both art and math could be pretty beneficial if someone wanted to be well-rounded.

Anyways, it's hard to remember my feelings about how school was back in middle school, high school, and last freshman year. I just remember feeling a little bit troubled by how much info. I'd have to process with multiple classes. I did genuinely think about course content, (and especially with comp. sci. now!). In middle school and high school, I may have try-harded a lot on my assignments, I can admit that. I did have a few extracurricular activities in middle school and high school. And I may have procrastinated a lot too (but not always!). So all-in-all, it's hard to say right now whether the bigger problem is how much school work is presented, or how much I want to spend on it. Maybe it's equally both. If I were to write more about this, it'd have to be while I'm back in the full university quarter next month.

Nonetheless, what I really feel for sure is that, being at the university I'm at right now, I get more free time to pursue my computer graphics interests, and I'm extremely happy to do that. As long as I get to devote most of my time to that, I'll be happy with any workload.

------
Alright, I ended up writing a lot about my thoughts of school and workload, guess wanted to put my thoughts fully there, but what I really wanted to write about was some feeling of "information overload in general" I had.

Like, I thought to myself, "Oh, we're being bombarded with too much information, and like we're using youtube and social media so much and we shouldn't use it as much."

I think it was one of the reasons why I hardly use facebook anymore since starting at university (only use it to check on university pages). And I'm not for other social media either. Not sure if it's just natural for my age, or I'm just busy with university or my computer graphics hobbies.

Looking back at that though, I really think that's mostly incorrect and negative. With internet especially, it's always good to have a lot of information at hand. Especially for news. I'm focused a lot of programming, it's good to have quick access to check on world events once in a while. Whether for fun or for serious purposes, it's great I can view all this on just one computer. And social media's a great way to connect with others. Back pre-internet era, if someone moved or changed address/phone numbers, it'd be hard to keep in touch if they don't tell their friends about it. Though I can't say for certain, I didn't live in that time (technically though haha, when I was really young my family didn't have internet though. And when we started, it was w/ kilobit speeds and DSL, if I recall the terms right). With things like facebook and Skype, you just send a message to stay in touch, you don't even need to consider networking, just get a good internet connection. Besides social media, I've gotten a lot of help from forums, especially with OpenGL and Windows API, and I'm really thankful for that. I'd like to give back to them one day.

So I think my thoughts on what I thought was "information overload and society" are more like "my thoughts about what I'm doing on the computer and what I should moderate for myself", and "advice tips I wanted to list from that". Basically, my thoughts are more of personal reflection now that I think about it. With YouTube, I use it a lot on my phone, mostly for watching let's plays when I wanna give my head a break. (Currently, I'm rewatching MegamanNG's Phoenix Wright: Justice for All walkthrough. On Part 9 as I'm writing this.) As I'm writing this, I'd have to say to myself to remind myself once in a while not to take content like this for granted. Not just let's plays. Any video in general. Of course I'm gonna forget this a lot, I'm busy with life in general. So most importantly, I'd say to myself not to overload with too much of YouTube. I'd say focusing more on my hobbies and interests have makes me happier in the long run. Really, doing personal projects on Windows API and OpenGL is really cool, at least for me. I'd like to try ray tracing one day, and maybe even computer vision. I hope I do more team projects (teaming up in programming is hard from my experience, but I'd like to get better at it. I think team projects is a good thing, and feels better in the long run too).

Anyways, ya, I guess in the end, these ending thoughts would be more personal reflection. I'd like to share it publicly on a blog though just because I feel like it, and I'd also like to share tips I've felt like I've gained from my experience with using the computer a lot. If I'd have any concern about society in general with the idea of "information overloading", I just hope the level of work expected in schools and work don't go overboard just because we have more information, but other than that, this is mostly self reflection.

Tips in the end:
-It's always good to have a lot of information and tools. Just don't overload yourself.

-Pursue your hobbies/interests. Make your own content. I'd say the more you do this, the more you can understand to value what you can do/what you have.

----------------
Ending Notes

-looks like tips I put here match up similarly to a previous reflection I did. was nice coincidence haha, didn't do that on purpose

-Speaking of YouTube, I've been thinking about YouTube demographics. Looked this up, looks like men are mostly into sports and games. I wonder if YouTube's algorithms take this into effect when recommending videos to me. I see sports/games videos a lot in my recommended list. Though it could also be that I just looked a lot of these types of videos up naturally, and YouTube considered that. Just wanted to note that here.

Thursday, August 3, 2017

Using WS_CLIPSIBLINGS and WS_CLIPCHILDREN in OpenGL drawing

I've been looking back at a Windows API minimal.c example from here to review OpenGL, and I noticed in that the CreateWindow funciton included the WS_CLIPSIBLINGS and WS_CLIPCHILDREN styles like so:

    hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW |
   WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
   x, y, width, height, NULL, NULL, hInstance, NULL);

At first thought, that seemed unnecessary to me, as I thought that you'd only include that if you want to prevent a window from drawing onto siblings (with the same parent) or its own child windows. But I think that's the point, you don't want OpenGL to ever draw on those other windows.

Haven't tested it with full code yet, but pretty sure it's right, and I'd thought it'd be helpful to point it out in a blog post like this. Got some info. from this pdf titled "3. OpenGL Under MFC" (I use pure Windows API though, but doesn't matter overall haha.)

Monday, July 10, 2017

VAIO Care filling my hard-drive

A while ago, my computer was running out of hard drive space. Had 500 GB. Found that odd, I was pretty sure I wasn't adding any big files. Even downloads shouldn't have eaten up GB's so quickly.

I used WinDirStat to check files. Found a folder that was bloated with around 30-50 GB. Forgot what it was (wanted to write about this, just forgot). Was one of the folders found in:

C:\Program Files\Sony\VAIO Care

Not the VAIO Care folder itself. But one of the subdirectories. Noticed VAIO Care was doing hidden routine checkups or something and storing some data files or something in this folder. Was racking up huge. Deleted all of them, laptop still okay.

Wanted to stop this routine stuff from VAIO Care, didn't use it anyways. Found that I had to go to Explorer. Right click on "This PC", click "Manage".



I disabled all the VAIO Care scheduled tasks. In the tree browser on the left of the Task Scheduler, I went to:

Computer Management (Local) -> System Tools -> Task Scheduler - > Task Scheduler Library -> Sony Corporation -> VAIO Care

I highlighted all the tasks, and clicked disable in the bottom left. If I remember right, some tasks I had to single click and disable. Anyways, after that, the folder I mentioned earlier stopped filling with report files.



So ya. File bloating. Don't like it. Just happy to figure the source.

Saturday, June 24, 2017

Personal Reflection, College Freshman: Routine

Around the end of my freshman year here at college, I asked my roommate if he wanted to make a website with me. I was interested in doing a personal reflection, where we'd each share our thoughts about how we changed. I planned to let him make the website. He came up with the theme "Routine": how are day-to-day things have changed over time. He thought of an interesting title, "Life Lessons from 102C" (that was the dorm we stayed in). Unfortunately, as of now, we never got to making the website. Guess he forgot. If he remembers and wants to work on it, hopefully he'll send me a message about it in the future.

Nonetheless, I did end up writing my entry about what I wanted to put on the website, and I wanted to share it here on my blog, before I forget about it altogether. Here it is. We planned to talk about different aspects of routine, such as expectations and change of location. I sectioned up my entry based on those.

Here's some links to 2 things I mentioned in my entry. Wasn't sure how to link it in, will just put it here for now.

Screen Reminder
-A little Python 3.X program I wrote that pops up a Tkinter window every 15-25 minutes to remind me to look away from the computer at something ~20 feet away for at least 20 seconds. Based it off of the "20-20-20" rule I read here
-In other words, the program reminds me to take breaks. I don't follow the rule dogmatically, just the idea of reminding for breaks has helped me a lot.
-Also, had a text file keep track of how many times it popped up the window. So far, 1966 times! (6/24/17)

-Dropbox link here. Added a little "readme.txt" just to get minor details in.

Air Bomber
-Game project I worked on at VGDC game dev. club here at UCI. itch.io link here.


Also, link to prompt and last draft I made. Did put legitimate time and thought in to this, so wanted to acknowledge my own work haha.
Prompt: Dropbox link
Last Draft: Dropbox link

===========

Intro:
It’s my first year here at UCI, and in college in general, and I wanted to write a bit about how I feel like I’ve changed over this year, how my routine changed mainly. With the change in pace in high school and being away from family, I feel like I’ve gotten more time to think about my life, and I guess I’ve gotten the time to want to write this as well. I’d say it’d be mainly a life marker for me to look back to in the future, writing down tips and details, but hey, if anyone reads this (and thanks for reading too), I hope you get something out of it as well.

Expectations and Results:
Coming out of high school felt quite like a bit of a release for me. Looking back at it, I felt like it was way too intense, too much work. The math and English homework was a lot, and maybe I was just getting tired of classwork in general. The teachers were nice, but the workload wasn’t.
One month after high school, I’d be starting Freshman Edge here at UCI, which was pretty much taking summer classes. Psych 7A wasn’t a pretty good class for me (I’m not someone for memorizing a bunch of facts), and UNI STU 83 was a sort of “adjusting to UCI” introduction class. Nonetheless though, it was pretty much the first time I got to live sort of on my own, with a roommate in a double room. Away from parents and most everyone I knew. It felt really nice to me, like I’d get a chance to put a “fresh start” on my life.  I mean, to be more realistic, my parents were still paying my tuition, but still, it was as close to what I call a “fresh start” as I could think of.

When Fall Quarter started, I was feeling pretty excited. Starting with Freshman Edge, I felt like I had more free time than I did than high school, and I wanted to do so much. But I’ve noticed over time I have my limits, and I’d rather do less classes so I could focus on my programming hobby more. I mean, doing computer science classes, I was learning programming there, but I wanted as much free time to do my own thing for my own enjoyment.

My original plan back in the beginning was, “I’m going to start with 3 classes, then I’m going to do 4 every single quarter until the end, and I’ll consider 3 classes as sort of like a backup, when I need a break.” But that definitely didn’t happen. Fall quarter, did 3 classes. After Winter quarter, 4. First time trying out 4 classes, and I felt that was intense. This last spring quarter coming to an end, I started to try to do 4 classes, but dropped out of a GE (General Education) class because of the workload, so I could focus more on my other three: Writing 39C, ICS 33, and Math 3A.

I’d look back at it right now, and can say in one point, these classes were heavy. Writing 39C is a lot of writing, a little less than high school, but still a lot (my instructor was nice, and the mass incarceration topic was interesting, it was just that the curriculum required us to write these large Historical Conversations Project (HCP) and Advocacy Project (AP) papers). And ICS 33 had weekly quizzes and large programming assignments, that was heavy already. Math 3A was a good workload, though, with a weekly assignment. So ya, maybe for one, I was just taking pretty intense classes this time.

But I look at it in another way, and I’m now thinking to myself that I’d probably won’t be able to handle 4 classes every quarter continuously anymore. I’d burn out. Even if I was able to handle it, I’d won’t feel as free to do my hobbies in my free time. I’d be tired out studying. Interestingly, I came out of high school with enough college credits to be considered sophomore status on entering UCI. And if I were to do a lot of classes, I probably would be graduating in 3 years. But I’d rather spend an extra year to not burn myself out so that I can pursue my own interests. I admit, that’d raise my tuition a lot, to be at the university for the next year (then again, I wonder why tuition is so high here). I’d feel bad for having increasing financial strain on my family, but I think being able to pursue my interests more would be better for me in the long run, and I think I’ll be able to land a better job with the skills to pay off the tuition more with my parents. Anyways, that was my first expectation: was thinking about taking so many classes, but I would rather take less now so I can pursue my hobbies more.

Location:
Switching topics, when it came to locations and routine here at UCI, I first thought I’d always want to stay in the same place and work continuously. There were a few “quiet places” here at UCI I could go to study and work on hobby stuff, like the Ayala Science Library, but over time I realized I wanted to be more flexible with myself than that.

Now that I think about it more, I don’t think my change in location routine was much by choice. I was developing some knee pain this quarter. It may have been by carrying my laptop all over with me back then or just (more likely) that I wasn’t exercising that much. Anyways, with the knee pain, I started to stay in my dorm room more, and I now biked around campus. And so when class would finish, I’d bike back to my dorm if I wanted to continue to work on my laptop.

As I’m writing this in my dorm, I’d say I’d look over my routine moving and around and say going to the same place just to study was a bit too much. It was more convenient for me to stay in my dorm room and use my computer here. Plus carrying my laptop all over the place became cumbersome. With that though, being in my room with a bed next to me all the time, I sort of feel more often to stay sedentary (sitting on the computer is a lot already), and I know it’s bad for me to do that all the time.  I try to do in-place jumping and pushups once every while to keep myself healthy. I can’t run because of my knee, but I wish I could do it again. I miss it a lot. Maybe over the summer, I’ll get a chance again. Quiet hours at night has always been an issue here at my dorm, unfortunately, but still, overall it became more convenient to keep my laptop in my room so I didn’t have to lug it everywhere I went.

With regards to using my laptop a lot, ya, even that too, with a programming hobby, I’ve felt like over time that I need to take more breaks. I wrote a “Screen Reminder” program in Python that pops up a tkinter window saying “Screen Eye Reminder” every 15 – 25 minutes (I randomize it every run). I made it mainly to remind myself to look away from the computer every once so often. It makes my eyes feel better, --seriously--. I do it all the time now. I used to always wear Gunnar Gaming classes when I used the computer, but now with just taking breaks, I don’t use them anymore, and I don’t have to worry about dirt on glasses (I use the glasses only when playing video games now, which I do rarely now too.). Anyways, besides that, I feel like the program helps me to take a break/walk outside more often. It feels great to do that, relaxes my eyes and clears my head too.

Lastly, with being in my room a lot, I can say my roommate is away most of the time too, even on weekdays. It actually used to be the other way around back in Fall and Winter Quarter if I remember right, with me outdoors and him indoors. He usually goes back home every weekend too. I guess in one sense, routine-wise, I feel more comfortable working in an emptier environment. Easier to concentrate. (I’d say it the same to anyone, not just my roommate. Just in general, the less noise, the more comfortable I feel.).

Nonetheless, I admit it can get pretty lonely here too. It’s a hard balance, in my opinion. For one, I’d like to be alone so I can concentrate and feel at ease. But on the other hand, being by yourself all the time can take its toll. I guess, I’d just like it if It was always quiet around my room so I can work on stuff, but it’d be nice maybe outdoors, when I’m more free at mind, to get ideas running with someone once in a while.

How I feel Like I’ve Changed:
For a start, looking at the expectations and results I wrote about earlier, I feel like a big thing I’ve learned about in my first year is to take my time with things. I’d rather do less school-wise so I can focus on my hobbies, and with anything in general, I’ve found it more comfortable to take more breaks. I’ve gotten to try a lot of programming in my spare time, and I’ve realized not to overload myself. Living in a dorm, I’ve gotten more time to think on my own, which I really appreciate. All the breathing room and stuff. And with taking more breaks, as I mentioned before I found myself going outdoors more. It cleared my head and relaxed my eyes. Just made me relaxed in general. I wasn’t like super happy, I just felt calmed.

Being in the Video Game Development Club here at UCI was quite a game changer too, pun intended. I participated back in Winter 2017. I had a game idea called Air Bomber. It ended up being a 2D downwards side scroller where you drop bombs below on enemies before continuing downwards. I ended up in a 3 person team. When I originally pitched the idea online, no one signed up, and I was about to choose another group during a club meeting until two other people show up. So ya, then we worked on Air Bomber on Unity. We finished the game in one quarter, like I’d planned. That was a seriously big experience before. I’ve had a little bit of experience with game development before, but this time I dedicated as much time as I could to make sure it was finished. Looking back at it, I’m proud of it. It’s not a super AAA game, but I learned a lot of programming from it. But I wished I could’ve made the scope lower. One person in the group was new, but I wanted to increase the scope to push myself and the artist in the group (he had experience too). But I realized that it feels better in the long run to get everyone’s ideas in, not leave anyone out. That probably means the game’s not going to be as good, but it feels better for everyone in the end (and you still learn stuff too). I’d say if you’re ever in a situation where you’ve got a team and some of your team members are genuinely interested but new to the experience, lower the project expectations and encourage group ideas more. And if it really is that low scoped, have a personal self project to push yourself during the time.

One of the most major things I feel like changed my life a lot is limiting my digital entertainment. I’ve decided to cut off my social media virtually entirely, and I’m trying to minimize what I watch on YouTube as much as possible. I feel like in the past, I sort of got hooked onto these things. Not obsessed, that’d be too dramatic. I just feel like I’ve done so much time on Facebook and YouTube, I wasn’t liking it anymore, and I wanted to do other things with my life, like pursuing programming, hobbies in general. Besides, I hardly ever posted on Facebook, just used it for homework and looking at the news feed. The messaging was fun, but I missed talking in person more. Even as rare as that is, an in-person talk felt more genuine than online chatting. Video games and movies, I didn’t feel too obsessed with them, I really enjoyed them. Overall, they’re just technology, they don’t force me to use it, it was up to me to limit it. And by doing it, ya, I don’t feel as excited anymore, but I feel amazingly clear-headed because of this, just as much as taking my time.

Final Thoughts
So that’s my first year at UCI, routine-wise. Getting some free time, pursuing my hobbies, taking my time. I see that I’ve changed a lot, and I plan to keep these habits in my life. I’m pursuing a general computer science major. Just looking for a stable job now. I still want to do game dev in my spare time. I still dream of making a cool 3D game, with a nice team. Social-wise, well, I haven’t really connected with anyone this year. Though I’m not really talkative I’ve realized. I really enjoy these hobbies dearly, just personal projects in general. I hope to find someone one day I could really pursue them with, and bounce ideas off each other. Maybe someone I know already would be interested, not sure. Or maybe someone in the future. Anyways, ya, that’s where I am, looking forward. Keeping it slow, pursuing what I love, hoping to find others to team up with in the future. It’s not the happiest life, but it’s one I’m happy to live.

So to sign off, here are some tips I felt like I’ve gained for myself. Hope it helps anyone reading this:

-Don’t overload yourself. Take breaks. Stay healthy.

-Don’t overload yourself with media and online messaging. Appreciate less, and think more for yourself. Yes, you can always be connected with others, but you should make time alone to think about your life  as well.

-Pursue your hobbies. Find what you love. Make some cool stuff, not just watch, listen, or copy it. I’d say the best hobbies are those that allow you to pursue your own ideas.

-Even with hobbies, don’t do them alone always. Find others to work on team hobbies too.

-Be yourself. I’d even argue that being yourself is more important than having friends, but that’s a huge extreme I admit. Not sure about that, would have to look back at this in the future.

-Ask for help if you need to, and give help in return. I haven’t asked too much in the forums with programming for example, but people were nice to respond, and I’d like to give back too one day (when I can actually answer haha).


-Take your time. Life’s too short to rush to do everything.