OpenGL Camera 2d with zoom and rotation

I’ve been working on OpenGL for some time now and one of the things that some people have asked me is how to do that 2d camera with zoom and rotation in a similar way to a post regarding a XNA 2D Camera I wrote some time ago. Some of them where just subtracting the camera position to all objects drawn, but that’s just ‘ugly’ in my opinion. And the advantage of using a more complicated (at first glance) system as a matrix is that you can easily apply more complicated operations like scaling and rotation. ...

July 11, 2013 · 3 min · 587 words · David Amador

OpenGL 2D Independent Resolution Rendering

Around two years ago I made a tutorial for XNA in which you could render 2D games scaled to the current window resolution with proper letter-boxes or pillar-boxes. As many know since then I moved to C++ and OpenGL, and ocasionally people ask me “Can you still do that independent resolution thing?”, and yes it’s perfectly possible. I’ve used this on all latest Windows, Mac and iOS, in case you are wondering. ...

April 22, 2013 · 3 min · 539 words · David Amador

Xbox 360 Controller Input in C++ via XInput

So you have that Xbox360 controller laying around and want to connect it to your game? On XNA this is an out of the box option but if you’re using C++ you have a bit more work to do first. First of all, you will need the DirecX 9.0+ sdk. The includes. #define WIN32_LEAN_AND_MEAN // We don't want the extra stuff like MFC and such #include <windows> #include <XInput.h> // XInput API #pragma comment(lib, "XInput.lib") // Library. If your compiler doesn't support this type of lib include change to the corresponding one Let’s define the buttons ...

April 15, 2012 · 4 min · 842 words · David Amador

Using Git for revision control

If you are coding, no matter what it is, games, software, websites, you should be using a code revision control of some sort. Are you using? Cool. Is it Git? Smart choice, so you probably don’t need to read the rest of this post. For the rest I’m giving some help on how to start from scratch. First of all I recommend some reading on Revision Control so that you understand what I’m talking about. ...

July 8, 2011 · 2 min · 363 words · David Amador

Making Big Grass Tiled Backgrounds in XNA

I’ve seen this quite a bit around on XNA forums and got 2 emails last week asking about this: I want to make a 3000×3000 grass background by tiling this small grass image I have. Should I make one big image or should I make a for cycle drawing the image (3000/TileSize) times? My answer is neither of them. The big image has a huge impact on every Draw and more, you are limiting your map to the max Texture Size the graphic card can handle. ...

April 19, 2010 · 2 min · 308 words · David Amador

XNA 2D Independent Resolution Rendering

Note: 22/04/2013 – Due to popular request I made an article about achieving this effect in OpenGL Independent Resolution Rendering?? What’s this all about? Basically a way of not caring what you resolution is. Ever had Gui elements misplaced because you changed the resolution? Or getting out of the screen? If you are doing a game on Xna just for Xbox360 you can basically use a 1280×720 base resolution and the Xbox will scale the game for you making the proper Letterbox. ...

March 26, 2010 · 2 min · 386 words · David Amador

Drawing Lines in XNA

One of the things I realized is very handy when prototyping or debugging is to draw a line on a specific location. Like drawing lines around collision boxes to see if your character is making a proper collision. For my games I’ve made a small LineBatch. Basically LineBatch uses a SpriteBatch to draw the lines by stretching a 1×1 white Texture2D to your line size. You can give it 2 points ( start and end point of course) and a color. There’s an overload function that receives the Layer parameter. ...

January 26, 2010 · 1 min · 163 words · David Amador

Xna Screen Manager

I know there’s lot’s of this stuff over the internet but I keep bumping into people asking for this. A way to easily switch from a Game Screen to a Menu or Options without having tons of flags and “if” clauses on the class Game. I’ve made a small project with a Screen Manager. The ScreenManager is static and can contain Screens. Instead of having typical Draw Update functions drawing SpriteBatches on the Game class we should have something like this: ...

January 24, 2010 · 2 min · 314 words · David Amador

How to do a XNA fps counter

Frame rate or FPS, how it is most commonly known is a way for you to know how many images per second is you game drawing. The more the better. Less then 30 and you start to see hiccups. So how can you measure your frame rate in XNA? Inside your game1 class declare these vars: SpriteFont _spr_font; int _total_frames = 0; float _elapsed_time = 0.0f; int _fps = 0; On function LoadContent() do // Put the name of the font _spr_font = Content.Load("kootenay"); you have on your project On the update pump do: ...

November 23, 2009 · 2 min · 254 words · David Amador

How to do a Xna Log file

Although the title says XNA log file this is actually a C# log file, I’ve just thrown this title cause lot’s of people search for xna log instead of C# log file. Many have asked me why take time to do a log file when you can throw exceptions when something goes wrong. Well the answer is simple, to keep track of what’s happening, log steps, write to the file exactly what when wrong even if you are on Release mode, and more, if someone complains the game is crashing you simply ask for the log file and see what when wrong. ...

November 20, 2009 · 2 min · 350 words · David Amador