Archive

Author Archive

Change GUI Label text colour on hover

November 14th, 2011 No comments

Hi,

Today I ran into a problem whereby I was drawing a GUI label that I want to have a different colour on hover to it’s normal state. Following the usual steps I altered the style in the GUI skin to have a different hover text colour expecting this to work. However it does not. The colour remaining the same even on hover. My draw code is fairly simple, akin to:

GUI.Label(rect,text,style);

So nothing wrong here. After playing around a bit I put in a background texture on the hover in the style to see if this made a difference and low and behold the text colour changed! I do not want a texture though so instead I created a 1×1 pixel texture which is completely alphaed out and used that as a background texture. Naff and pretty hidden behaviour but thats the workaround I found.

Also you need to change the drawing code to draw the item as a GUI.Button instead of a Label.

Categories: C/C++ Tags:

Update GUI Button text colour Unity

October 11th, 2011 No comments

I recently had a bit of text that I wanted to be able to click. This is easy to do, just make a GUI.Button with a custom style that has no background and use the text as the GUIContent parameter. However I wanted to change the colour of the text when you hover over the text, this proved trickier. I changed the hover text colour but nothing happened. I tried just putting in a background texture for the hover state in the GUI skin for a test and noticed that the text colour changed when I hovered over it!
So the solution that I found is to make a 1×1 transparent texture and use that as the background texture for the hover! Terrible I know but there is no other way I can see to fix it…

Categories: C/C++ Tags:

Changing GUI.Button text colour

October 11th, 2011 No comments

I recently had a bit of text that I wanted to be able to click. This is easy to do, just make a GUI.Button with a custom style that has no background and use the text as the GUIContent parameter. However I wanted to change the colour of the text when you hover over the text, this proved trickier. I changed the hover text colour but nothing happened. I tried just putting in a background texture for the hover state in the GUI skin for a test and noticed that the text colour changed when I hovered over it!
So the solution that I found is to make a 1×1 transparent texture and use that as the background texture for the hover! Terrible I know but there is no other way I can see to fix it…

Categories: C/C++ Tags:

Making NSAssert work

July 12th, 2011 No comments

Hi,

NSAssert is handy but it has been annoying me recently as the execution of the debugger doesn’t stop when an assert is hit. Instead we get a message output to the console and the execution is stopped in the update loop at a later point. When something hits an assertion I want the program execution to stop immediately. For some reason beyond me this is disabled in XCode by default. To enable it go to Run->Stop on Objective-C Exceptions

There you go, your exceptions will now work.

Categories: iPad, iPhone, iTouch, Objective C Tags:

Error from Debugger: Failed to launch simulated application: iPhone Simulator failed to install the application.

June 19th, 2011 No comments

I got the error below when attempting to Build and Go in XCode.

Error from Debugger: Failed to launch simulated application: iPhone Simulator failed to install the application.

My app wouldn’t launch in the iPhone Simulator and the console has little or no feedback.

I went through a few steps to fix this, firstly I tried to Clean All Targets but that didn’t work. What I did that worked was:

  • Close the iPhone Simulator
  • Open the terminal and execute
    sudo rm -Rfv ~/Library/Application\ Support/iPhone\ Simulator

Should work now when you Build and Go again.

Categories: C/C++ Tags:

HOWTO: Record a movie from the iPhone Simulator

June 6th, 2011 No comments

This is easy, only a few little steps.

1. First install SIMBL, use the pkg install and choose All Users install.

2. Download the iPhone Simulator Capture

3. Open up the iPhone Simulator and click on the iOS Simulator menu option and select About iOS Simulator. Note down the version number in brackets after the main version, it is 235 for me.

4. Open up the iPhone Simulator Capture.xcodeproj, navigate to Info.plist in the project view and update MaxBundleVersion to be the iOS Simulation version noted above.

5. Select Release and Build. You may see a post-build error, this is as the build process attempts to copy the output to two locations, the user SIMBL directory and the all-users SIMBL direction, only one is likely to exist from your install. The plugin should be copied to the SIMBL plugins directory*

6. Restart the Simulator and you’ll now see a Record menu option! It should be all fairly simple, one thing is that after you record a move you need to manually choose the Save Movie option afterwards, it does not save it to the HD as you go!

Easy!

* You can verify the build completed correctly by going to ~Library/Application Support/SIMBL/Plugins and you’ll see the file “iPhone Simulator Capture.bundle” if the install succeeded. If it isn’t there then check the user directory ~Users/MYUSERNAME/Library/Application Support/SIMBL/Plugins directory. If it is in neither then you may need to copy the bundle manually, check the iPhone Simulator Capture build/Release directory.

Categories: iPhone, iTouch, Mac Tags:

Notepad starts off-screen

May 19th, 2011 No comments

So you’ve changed you primary, secondary screens and now notepad opens off screen and you can’t get to it. Alt-tabbing does nothing to fix it, how do you resolve this?

The default position for Windows Notepad is stored in this Registry key:

HKEY_CURRENT_USER\Software\Microsoft\Notepad

Close all open Notepad windows and change the following values as shown:
iWindowPosX : 0
iWindowPosY : 0
iWindowPosDX : 200
iWindowPosDY: 200

This would set default position to top-left. You can resize and position Notepad window later as you wish.

Categories: Windows Tags:

A simple HashedString implementation

May 17th, 2011 No comments

Hi,

In my first forays into my engine development I’ve found it necessary to come up with my own simple hashed string implementation. I plan on using this in place of strings wherever possible for identifiers of objects or for storage. My requirements are fairly simple, I want to have an implementation that resolves a string to an unsigned integer. In debug I want to be able to identify the string in the debugger so I have a debug only char array that is used to store the original string when passed in.

For my hash functions I used the code from General Purpose Hash Functions. I haven’t looked at the hashing algorithms in much detail, a lot of the math looks above my head. I chose the DJB hash function as it is described as being one of the most efficient hashing algorithms ever produced.

One of the things I haven’t considered as of yet is that collisions may be possible. I’ll have to look at the various hashing implementations and pick the one that looks to be the best choice and come up with a system to cope with clashes. This will probably involve doing some tests on a wide range of strings, for now however I don’t have many strings and so my implementation will suffice.

Below are the header and implementation of my HashString along with the HashFunctions found at the link above. You may need to fiddle with them slightly to get them working for your purposes but they’re largely for illustration purposes anyway. These are provided as is, I may find bugs and will endeavour to reupload the fixes.

GeneralHashFunctions.c
HashedString.h
GeneralHashFunctions.h

Categories: C/C++ Tags:

Writing a game engine – Part 2

May 3rd, 2011 No comments

A quick one today, I’ve got a basic application up and running using the simple framework located here.

One interesting thing to note is that Nehe uses global variables for the active, fullscreen and keys variables. I don’t want to do this. I want to have these as members of an Application class to begin with and eventually I’ll create an input handler class and also a renderer that may hold onto these. However due to the way in which the windows are created only static non-member functions can be used to handle the callbacks from the window to handle messages like WM_NCCREATE, WM_ACTIVATE, WM_CLOSE, WM_KEYDOWN and so on. To allow a member function to be able to handle these messages you need to do perform some trickery. You need to define two static callback methods that will handle and messages from the window.

Firstly, we need to alter the way in which the window is created. The first thing we need to do is the give the name of one of the static methods you defined as the initial callback i.e. called on creation of the window:

wc.lpfnWndProc		= &InitialWndProc;						// WndProc Handles Messages

The next thing you need to do is to alter the CreateWindowEx call and add change the last parameter from NULL to ‘this’. This last parameter is an optional extra data that is passed to the creation of the window. By passing this we are passing a pointer to the current Application class to the window creation callback.

So I mentioned two static methods earlier. The first method is to handle the creation of the window:

static LRESULT CALLBACK InitialWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
		if (Msg == WM_NCCREATE) {
			LPCREATESTRUCT create_struct = reinterpret_cast(lParam);
			void * lpCreateParam = create_struct->lpCreateParams;
			Application * theApp = reinterpret_cast< Application*>(lpCreateParam);
			SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast(theApp));
			SetWindowLongPtr(hWnd, GWLP_WNDPROC, reinterpret_cast(&StaticWndProc));
			return theApp->WndProc(hWnd, Msg, wParam, lParam);
		}
		return DefWindowProc(hWnd, Msg, wParam, lParam);
	}

Here we are taking the extra data that was passed into the CreateWindowEX, casting it to an Application pointer and then telling hWnd (the handle to the window) what the new user data (GWLP_USERDATA) will be and also WNDPROC will be that will handle messages from now on in. Essentially what this does is that it tells the window that all messages should be sent to the static method StaticWndProc with the user data being theApp (which is cast to a long pointer). Also note the call to theApp->WndProc, this is important later.

The second static method you need to define is the one that will pass on all messages that come to the window during runtime.

static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
		LONG_PTR user_data = GetWindowLongPtr(hWnd, GWLP_USERDATA);
		Application * theApp = reinterpret_cast< Application*>(user_data);
		return theApp->WndProc(hWnd, Msg, wParam, lParam);
	}

This is simple, all it does is take the user data from window that we setup earlier, cast it to the right Application* type and then pass along the callback to the class’s desired member.

So now we can have a member function on Application like so:

LRESULT CALLBACK Application::WndProc(	HWND	hWnd,			// Handle For This Window
											UINT	uMsg,			// Message For This Window
											WPARAM	wParam,			// Additional Message Information
											LPARAM	lParam)			// Additional Message Information
	{
		switch (uMsg)									// Check For Windows Messages
		{
			case WM_ACTIVATE:							// Watch For Window Activate Message
			{
				if (!HIWORD(wParam))					// Check Minimization State
				{
					m_active=TRUE;						// Program Is Active
				}
				else
				{
					m_active=FALSE;						// Program Is No Longer Active
				}

				return 0;								// Return To The Message Loop
			}

			case WM_SYSCOMMAND:							// Intercept System Commands
			{
				switch (wParam)							// Check System Calls
				{
					case SC_SCREENSAVE:					// Screensaver Trying To Start?
					case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
					return 0;							// Prevent From Happening
				}
				break;									// Exit
			}

			case WM_CLOSE:								// Did We Receive A Close Message?
			{
				PostQuitMessage(0);						// Send A Quit Message
				return 0;								// Jump Back
			}

			case WM_KEYDOWN:							// Is A Key Being Held Down?
			{
				m_keys[wParam] = TRUE;					// If So, Mark It As TRUE
				return 0;								// Jump Back
			}

			case WM_KEYUP:								// Has A Key Been Released?
			{
				m_keys[wParam] = FALSE;					// If So, Mark It As FALSE
				return 0;								// Jump Back
			}

			case WM_SIZE:								// Resize The OpenGL Window
			{
				reSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
				return 0;								// Jump Back
			}
		}

		// Pass All Unhandled Messages To DefWindowProc
		return DefWindowProc(hWnd,uMsg,wParam,lParam);
	}

And have achieved what I wanted, be able to have member variables and a member function be able to handle the various messages that come from the window.

Note: There is no error handling if the Application casting goes wrong, I might add that at some point.

Categories: C/C++ Tags:

Writing a game engine – Day 1

April 14th, 2011 2 comments

Ok so I’ve decided to write my own engine. I’m doing this not to make a game or anything but to learn from it. I’ve read the articles where people say ‘make a game not an engine’ but I think it is very important to actually learn by doing. I’ve been reading a lot recently and feel like a lot of the stuff almost goes in one ear and out the other, mainly because I’m not actually doing anything to follow up my learnings.
So I’m going to begin creating an C++ Open GL based engine (over my lunchtime). The main aims are:

  • Minimise the use of virtual functions and inheritance
  • Minimise the use of STL
  • Have modular and heavily configurable sub-systems
  • Aim for deferred rendering in my scene
  • Implement a simple data-based GUI that includes an in-game editor (possibly haven’t decided on this yet)
  • Incorporate scripting
  • Make use of threading/multi cores

Today I’m not really doing anything in particular, just reading. I’d imagine I’ll be doing this for a while before I even write a line of code.

I’ve read the excellent Game Engine Architecture by Jason Gregory but will start again looking at it taking real note and actually sketching out some designs. I like the idea of the way Unity do things with Entities and a property system.

I intend to revisit this post during the coming months and amend, laugh and update it… will be an interesting challenge ahead. It’s certainly going to take a long time given that I can only give it about 45 minutes a day!

Categories: C/C++ Tags: