Archive for programming

Using Sublime Text 3 For Handmade Hero

Posted in Handmade Hero with tags , , , on November 25, 2014 by Matthew VanDevander

Please note that this guide is intended as a supplement to the main video series for users who would rather use Sublime Text than Emacs, and does not cover all aspects of setting up your development environment. Namely the Visual Studio setup, which is the same regardless of what editor you are using. However, I have attempted to be as thorough as possible. If there are any errors or glaring omissions in this guide, please contact me on twitter @mvandevander and I will resolve them as soon as possible. Once again, although Sublime Text is cross-platform, this guide is not. I would appreciate any tips that would help the guide to be more cross-platform as well. 🙂

Setting Up the Command Line

Download Handmade Hero and put the source code inside a directory somewhere that you will remember. I put mine in “C:\Users\Matthew\Documents\Programming”, but anywhere is fine.

Create a batch file named startup.bat and place it in the Windows “Startup” folder, which can be found in the start menu or at “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup”

Inside the startup.bat file, you will want to put the following, replacing the directory on the right-hand side with the directory which contains the “build” and “handmade” folders:

subst w: C:\Users\Matthew\Documents\Programming

Now after this batch file is run, W:\ will point directly to that directory. Double click the file to run it. Since we put the batch file inside the Startup folder, it will run every time windows is booted and we won’t have to worry about setting it again.

Note for Windows 8 users: Once again Microsoft has seen fit to make things harder and more complex for users who want to get things done. On Windows 8, when you “run as administrator”, it is considered a different user than your base account. Therefore subst will take effect under the “user” that you ran it from. If it is run from cmd as admin, you have it there but it doesn’t show up in explorer normally, and if you just run it without the admin privileges, it won’t show up if you run cmd as administrator. So be sure that you are not running cmd from a shortcut set to launch it as administrator. We will never need a command prompt with admin privileges. Also be aware that there appear to be issues if you actually do subst the same directory under both and admin and a normal user account.

Create a new shortcut on your desktop (Right Click->New->Shortcut) and paste the following into the location box:

C:\Windows\System32\cmd.exe /k w:\handmade\misc\shell.bat

Name it “cmd” or whatever you like.

Right click on the new shortcut and hit Properties to edit it. On the Shortcut tab, under “Start In”, Put W:\. Feel free to go to the Colors tab and change the text and background colors to whatever you like. Here are some nice values:

Screen text: 200, 180, 100

Screen background: 20, 20, 20

Pop-up text: 20, 20, 20

Pop-up background: 200, 180, 100

While we’re at it, let’s go to the Font tab and change that awful default font to something nice. I chose Lucida Console at size 14.

Adding Sublime Text to the Mix

Download Sublime Text 3 and extract it into a directory you will remember. I put mine in C:\sublimetext

Inside W:\handmade\misc, add a new batch file called “edit.bat” which we will use to launch Sublime Text.

Put the following code inside edit.bat, changing the directory to the one you put Sublime Text in:


@echo off

start C:\sublimetext\sublime_text %1

Now if we click our desktop shortcut, we can open Sublime Text by typing “edit” and hitting return. We can even open up files by appending them to the edit command like so:

edit handmade\code\win32_handmade.cpp

If Microsoft Visual Studio is installed, we should also be able to build our game from that command line, by typing “build” and hitting return. Magnifico!

Integrating Our Build System with Sublime Text

But what would be really awesome is if we could get our builds working from inside Sublime Text with just a keypress!

Open Sublime Text. Go to Tools->Build System->New Build System

The contents of the file should look like this.


{

"shell_cmd": "build",

"file_regex": "^ *([A-z]:.*)[(]([0-9]+)[)]"

}

Save the build system file as “handmade.sublime-build”, and make sure it saves into the User subdirectory of Sublime Text. (It should by default)

Now if we open win32_handmade.cpp inside Sublime Text and select our new “handmade” build type from Tools->Build System, we can build the project by pressing F7 or Ctrl+B. We can even jump between any build errors by using F4 and Shift+F4. Neat!

So far, this is all going pretty great. But we can make it a little better by installing a couple of packages. In order to make installing packages easy, we will want to first install a plugin called Package Control. We can do that by going to this website and following the instructions there.

After you have installed Package Control, go to Preferences->Package Control, and on the pop-up click Install Package. You will want to get SublimeLinter, SublimeLinter-annotations, and Highlight Build Errors.

Exit and reload Sublime.

Now all of our TODOs will be marked, and we will get line highlights for every build error.

Additional Tweaks

If you would like to change the settings for the highlighting, there are lots of options that you can access simply by right clicking in any code window and going under the SublimeLinter submenu.

I would suggest changing the Gutter Theme to None to remove the dots in the sidebar, and changing the Mark Style to Fill. Keep in mind though, that if you want to use the other linting features of SublimeLinter, most of those require those Gutter marks.

You can also edit the JSON file directly by either clicking Open User Settings from that menu, or you can go to Preferences->Package Settings->SublimeLinter->Settings – User. I am not sure why (probably a bug), but for some reason the settings file will be blank unless you have made changes to it from the right-click menu. To get the file to fill out, you have to save it and reload it.

I would suggest tweaking the file by adding “NOTE” to the list of warnings, so that NOTE is highlighted in our code. So that section will read like this:

"warnings": [

"TODO",

"NOTE",

"README"

]

We’re all set and ready to rock now! Happy heroing!

Advertisements

Adventures in Shader-ville

Posted in Computers, Duet, Games, Technical with tags , , , , , , , , , , , , , , , , , on July 24, 2012 by Matthew VanDevander

g++ triangle.cpp ... -lglew32 -lopengl32
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x7): undefined reference to `__imp____glewDeleteProgram'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x27): undefined reference to `__imp____glewUseProgram'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x69): undefined reference to `__imp____glewEnableVertexAttribArray'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x90): undefined reference to `__imp____glewVertexAttribPointer'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0xc7): undefined reference to `__imp____glewDisableVertexAttribArray'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0xff): undefined reference to `__imp____glewCreateShader'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x11d): undefined reference to `__imp____glewShaderSource'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x131): undefined reference to `__imp____glewCompileShader'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x143): undefined reference to `__imp____glewGetShaderiv'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x18b): undefined reference to `__imp____glewCreateShader'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x1a9): undefined reference to `__imp____glewShaderSource'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x1bd): undefined reference to `__imp____glewCompileShader'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x1cf): undefined reference to `__imp____glewGetShaderiv'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x217): undefined reference to `__imp____glewCreateProgram'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x225): undefined reference to `__imp____glewAttachShader'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x23d): undefined reference to `__imp____glewAttachShader'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x255): undefined reference to `__imp____glewLinkProgram'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x26a): undefined reference to `__imp____glewGetProgramiv'
/tmp/cc2DLE4T.o:triangle.cpp:(.text+0x2ba): undefined reference to `__imp____glewGetAttribLocation'
collect2: ld returned 1 exit status

Does that look like anything to you? Yeah. Me neither. In honor of that fact, this article is intended to be understandable enough to be interesting and readable for even an inexperienced non-programmer type. However, it will also provide some very useful information which may save from grief someone else who is attempting the same thing as I just have. Therefore, I will try to provide as many useful links as possible.

Continue reading

Culling

Posted in Computers, Duet, Games, Rants, Technical with tags , , , , , , , on January 18, 2011 by Matthew VanDevander

I suppose it is unrealistic to suggest that performance is never an issue when creating a video game. Since the better a game performs, the more graphical tricks you can cram up your games proverbial sleeves. But with the speed of modern computers, 2D games tend to not require much optimization. And as they primarily use tile-based graphics, it is relatively trivial to determine which tiles in the level are on screen (and therefore should be drawn), and which are not.

However, there are some newer 2D games, such as Braid, or Aquaria which use a entirely different method for their graphics which is not tile-based, but instead uses images which can be repeated positioned, rotated, and scaled arbitrarily to build a level. These images are rendered to the screen using modern 3D graphics hardware, which—being designed for 3D games—is rather fast for this application. Even still, there can be quite a large number of these images building up a level, so it is useful to devise an accurate and speedy method for determining which objects are on screen, and which are not. Continue reading