コード例 #1
0
ファイル: MFView.cpp プロジェクト: FujiGameJam/fuji
MFInitStatus MFView_InitModule()
{
	// allocate view stack
	gpViewStack = (MFView*)MFHeap_Alloc(sizeof(MFView) * gDefaults.view.maxViewsOnStack);

	// set default ortho rect
	MFView::defaultOrthoRect.x = gDefaults.view.orthoMinX;
	MFView::defaultOrthoRect.y = gDefaults.view.orthoMinY;
	MFView::defaultOrthoRect.width = gDefaults.view.orthoMaxX;
	MFView::defaultOrthoRect.height = gDefaults.view.orthoMaxY;

	// initialise default view
	MFZeroMemory(&MFView::defaultView, sizeof(MFView));
	pCurrentView = &MFView::defaultView;

	pCurrentView->cameraMatrix = MFMatrix::identity;
	pCurrentView->view = MFMatrix::identity;
	pCurrentView->viewProj = MFMatrix::identity;

	MFView_SetOrtho(&MFView::defaultOrthoRect);
	MFView_ConfigureProjection(MFDEGREES(gDefaults.view.defaultFOV), gDefaults.view.defaultNearPlane, gDefaults.view.defaultFarPlane);
	MFView_SetAspectRatio(gDefaults.view.defaultAspect);
	MFView_SetProjection();

	pCurrentView = gpViewStack;
	MFView_SetDefault();

	return MFIS_Succeeded;
}
コード例 #2
0
ファイル: Title.cpp プロジェクト: KingDwag/feedback-editor
void TitleScreen::Draw()
{
	GHScreen::Draw();

	MFView_Push();

	MFRect rect;
	rect.x = (MFDisplay_GetAspectRatio() >= 1.5) ? -106.0f : 0.0f;
	rect.y = 0.0f;
	rect.width = (MFDisplay_GetAspectRatio() >= 1.5) ? 852.0f : 640.0f;
	rect.height = 480.0f;
	MFView_SetOrtho(&rect);

	MFPrimitive_DrawUntexturedQuad(20, 20, 640-40, 480-40, MakeVector(0,0,0,0.8f));

	CenterText(30, 34, MFVector::yellow, "Main Menu", pHeading);

	float height = TEXT_HEIGHT;
	float y = 90-height;
	float x = 55.0f;

//	MFFont_DrawText(pText, , y+=height, 20, MFVector::white, "H - Enter help screen");

//	CenterText(rect.height - 20 - 54, 44, MFVector::red, "Press ESC to continue", pFancy);

	MFView_Pop();
}
コード例 #3
0
ファイル: DebugMenu.cpp プロジェクト: TurkeyMan/fuji
void DebugMenu_Draw()
{
	if(MFInput_Read(Button_XB_RTrig, IDD_Gamepad)) return;

	MFView_Push();
	MFView_SetOrtho();

	if(debugMenuEnabled)
		pCurrentMenu->Draw();

	MFView_Pop();
}
コード例 #4
0
ファイル: main.cpp プロジェクト: FujiGameJam/fuji
void Game_Draw()
{
	if(!bShowModel)
	{
		MFView_SetOrtho();

		// draw model list
		if(models.size() > 0)
		{
			for(int a=0; a<(int)models.size(); ++a)
			{
				MFFont_DrawText2(MFFont_GetDebugFont(), 100.f, 100.f + (-menuIndex*20 + a*20), 20.f, a == menuIndex ? MFVector::yellow : MFVector::white, models[a].CStr());
			}
		}
		else
		{
			MFFont_DrawText2(MFFont_GetDebugFont(), 100.f, 100.f, 20.f, MFVector::red, "No models found!");
		}
	}
	else
	{
		if(pModel)
		{
			// set projection
			MFView_ConfigureProjection(MFDEGREES(60.f), 0.1f, 10000.f);
			MFView_SetAspectRatio(MFDisplay_GetNativeAspectRatio());
			MFView_SetProjection();

			// render the mesh
			MFRenderer_AddModel(pModel, NULL, MFView_GetViewState());
		}
		else
		{
			MFView_SetOrtho();
			MFFont_DrawText2(MFFont_GetDebugFont(), 100.f, 100.f, 20.f, MFVector::red, "Failed to load model!");
		}
	}
}
コード例 #5
0
ファイル: Theme.cpp プロジェクト: KingDwag/feedback-editor
void dBThemeScreen::Draw()
{
	MFRenderer_ClearScreen(MFRCF_All, clearColour);

	MFView_Push();
	MFRect rect = { 0.f, 0.f, 1280, 720 };
	MFView_SetOrtho(&rect);

	dBEntity *pE = NULL;
	while(pE = entityPool.Iterate(pE))
		pE->Draw();

	MFView_Pop();
}
コード例 #6
0
void Game_Draw()
{
	MFCALLSTACK;

	// set clear colour and clear the screen
	MFRenderer_SetClearColour(0.f, 0.f, 0.2f, 1.f);
	MFRenderer_ClearScreen();

	// push current view onto the stack
	MFView_Push();

	// set orthographic projection
	MFView_SetOrtho();

	// render some text
	MFFont_DrawText2(MFFont_GetDebugFont(), 200.f, 200.f, 50.f, MFVector::one, "Hello World!");

	// pop the current view
	MFView_Pop();
}
コード例 #7
0
ファイル: MFPrimitive_D3D11.cpp プロジェクト: TurkeyMan/fuji
//---------------------------------------------------------------------------------------------------------------------
MF_API void MFPrimitive_BeginBlitter(int numBlits)
{
	MFView_Push();

	MFRect rect;
	MFDisplay_GetDisplayRect(&rect);
	MFView_SetOrtho(&rect);

	MFMaterial *pMat = MFMaterial_GetCurrent();
	MFTexture *pTex = MFMaterial_GetParameterT(pMat, MFMatStandard_Texture, MFMatStandard_Tex_DifuseMap);
	MFTexture_GetTextureDimensions(pTex, &textureWidth, &textureHeight);

	uScale = 1.0f / (float)textureWidth;
	vScale = 1.0f / (float)textureHeight;
	halfTexelU = uScale * 0.5f;
	halfTexelV = vScale * 0.5f;

	MFPrimitive(PT_QuadList);
	MFBegin(numBlits * 2);
}
コード例 #8
0
MF_API void MFDebug_DebugAssert(const char *pReason, const char *pMessage, const char *pFile, int line)
{
	MFDebug_Message(MFStr("%s(%d) : Assertion Failure.",pFile,line));
	MFDebug_Message(MFStr("Failed Condition: %s\n%s", pReason, pMessage));
#if !defined(_RETAIL)
	MFCallstack_Log();
#endif

#if defined(MF_LINUX) || defined(MF_OSX)
	MFDebug_Breakpoint();
#endif

	if(!MFFont_GetDebugFont())
		return;

	while(!gQuit)
	{
		MFSystem_HandleEventsPlatformSpecific();

		MFSystem_UpdateTimeDelta();
		gFrameCount++;

		MFSystem_Update();
		MFSystem_PostUpdate();

		MFRenderer_BeginFramePlatformSpecific();

		MFRenderer_SetClearColour(0,0,0,0);
		MFRenderer_ClearScreen();

		MFView_SetDefault();
		MFView_SetOrtho();

		if(!(((uint32)gSystemTimer.GetSecondsF()) % 2))
		{
			MFMaterial_SetMaterial(MFMaterial_GetStockMaterial(MFMat_White));
			MFPrimitive(PT_QuadList);

			MFBegin(4);
			MFSetColour(1,0,0,1);
			MFSetPosition(50, 50, 0);
			MFSetPosition(590, 110, 0);

			MFSetColour(0,0,0,1);
			MFSetPosition(55, 55, 0);
			MFSetPosition(585, 105, 0);
			MFEnd();
		}

		MFFont_DrawText2f(MFFont_GetDebugFont(), 110, 60, 20, MakeVector(1,0,0,1), "Software Failure. Press left mouse button to continue.");
		MFFont_DrawText2f(MFFont_GetDebugFont(), 240, 80, 20, MakeVector(1,0,0,1), "Guru Meditation: ");

		MFFont_DrawText2f(MFFont_GetDebugFont(), 80, 120, 20, MakeVector(1,0,0,1), "Assertion Failure:");
		MFFont_DrawText2f(MFFont_GetDebugFont(), 80, 140, 20, MakeVector(1,0,0,1), MFStr("Failed Condition: %s", pReason));
		MFFont_DrawText2f(MFFont_GetDebugFont(), 80, 160, 20, MakeVector(1,0,0,1), MFStr("File: %s, Line: %d", pFile, line));
		MFFont_DrawText2f(MFFont_GetDebugFont(), 80, 190, 20, MakeVector(1,0,0,1), MFStr("Message: %s", pMessage));

#if !defined(_RETAIL)
		MFFont_DrawText2f(MFFont_GetDebugFont(), 80, 230, 20, MakeVector(1,0,0,1), "Callstack:");
		MFFont_DrawText2f(MFFont_GetDebugFont(), 100, 250.0f, 20, MakeVector(1,0,0,1), MFCallstack_GetCallstackString());
#else
		MFFont_DrawText2f(MFFont_GetDebugFont(), 80, 230, 20, MakeVector(1,0,0,1), "Callstack not available in RETAIL builds");
#endif

//		MFSystem_Draw();
		MFRenderer_EndFramePlatformSpecific();
	}
}
コード例 #9
0
void Game_Draw()
{
	MFView_SetOrtho();

	const char *pText;
	float x, y;
	int a, b;

	x = 30.0f;
	for(a=0; a<MFInput_GetNumGamepads(); a++)
	{
		if(MFInput_IsAvailable(IDD_Gamepad, a))
		{
			MFFont_DrawText2(MFFont_GetDebugFont(), x-10.0f, 15.0f, 15.0f, MFVector::one, MFStr("%s (%d):", MFInput_GetDeviceName(IDD_Gamepad,a), a));

			if(MFInput_IsReady(IDD_Gamepad, a))
			{
				y = 30.0f;
				for(b=0; b<GamepadType_Max; b++)
				{
					float value = MFInput_Read(b, IDD_Gamepad, a);
//					int ival = (int)(value * 255.f);
//					MFFont_DrawText2(MFFont_GetDebugFont(), x, y, 15.0f, MFVector::one, MFStr("%s: %.3g - %d (0x%02X)", MFInput_EnumerateString(b, IDD_Gamepad, a), value, ival, ival));
					MFFont_DrawText2(MFFont_GetDebugFont(), x, y, 15.0f, MFVector::one, MFStr("%s: %.3g", MFInput_EnumerateString(b, IDD_Gamepad, a), value));
					y += 15.0f;
				}
			}
			else
			{
				MFFont_DrawText2(MFFont_GetDebugFont(), x, 30.0f, 15.0f, MakeVector(1.0f, 0.0f, 0.0f, 1.0f), "Disconnected...");
			}

			x += 170.0f;
		}
	}

	int numMouses = MFInput_GetNumPointers();

	x = 80.0f;
	for(a=0; a<numMouses; a++)
	{
		MFFont_DrawText2(MFFont_GetDebugFont(), x, 355.0f, 15.0f, MFVector::one, MFStr("Mouse Pos: %g, %g", MFInput_Read(Mouse_XPos, IDD_Mouse, a), MFInput_Read(Mouse_YPos, IDD_Mouse, a)));
		MFFont_DrawText2(MFFont_GetDebugFont(), x, 370.0f, 15.0f, MFVector::one, MFStr("Mouse Delta: %g, %g", MFInput_Read(Mouse_XDelta, IDD_Mouse, a), MFInput_Read(Mouse_YDelta, IDD_Mouse, a)));
		MFFont_DrawText2(MFFont_GetDebugFont(), x, 385.0f, 15.0f, MFVector::one, MFStr("Mouse Wheel: %g, %g", MFInput_Read(Mouse_Wheel, IDD_Mouse, a), MFInput_Read(Mouse_Wheel2, IDD_Mouse, a)));
		pText = "Mouse Buttons:";
		for(b=Mouse_MaxAxis; b<Mouse_Max; b++)
		{
			if(MFInput_Read(b, IDD_Mouse, a))
			{
				pText = MFStr("%s %s", pText, MFInput_EnumerateString(b, IDD_Mouse, a));
			}
		}
		MFFont_DrawText2(MFFont_GetDebugFont(), x, 400.0f, 15.0f, MFVector::one, pText);

		x += 170.0f;
	}

	pText = "Keys:";
	for(a=0; a<Key_Max; a++)
	{
		if(MFInput_Read(a, IDD_Keyboard, 0))
		{
			pText = MFStr("%s %s", pText, MFInput_EnumerateString(a, IDD_Keyboard, 0));
		}
	}
	MFFont_DrawText2(MFFont_GetDebugFont(), 80.0f, 430.0f, 15.0f, MFVector::one, pText);
}
コード例 #10
0
void Game_Draw()
{
	MFCALLSTACK;

	MFRenderer_SetClearColour(0.f, 0.f, 0.2f, 1.f);
	MFRenderer_ClearScreen();

	// Set identity camera (no camera)
	MFView_Push();
	MFView_SetAspectRatio(MFDisplay_GetNativeAspectRatio());
	MFView_SetProjection();

	MFMaterial_SetMaterial(MFMaterial_GetStockMaterial(MFMat_White));

	// set the world matrix to identity
	MFMatrix world = MFMatrix::identity;

	// move the box into the scene (along the z axis)
	world.Translate(MakeVector(0, 0, 5));

	// increment rotation
	static float rotation = 0.0f;
	rotation += MFSystem_TimeDelta();

	// rotate the box
	world.RotateYPR(rotation, rotation * 2.0f, rotation * 0.5f);

	// begin rendering the box
	MFPrimitive(PT_TriList);
	MFSetMatrix(world);

	// begin rendering 12 triangles (12 * 3 vertices)
	MFBegin(3 * 12);

	// draw a bunch of triangles
	MFSetColour(1,0,0,1);
	MFSetPosition(-1,-1, -1);
	MFSetPosition(-1, 1, -1);
	MFSetPosition( 1, 1, -1);
	MFSetPosition(-1,-1, -1);
	MFSetPosition( 1, 1, -1);
	MFSetPosition( 1,-1, -1);

	MFSetColour(0,1,0,1);
	MFSetPosition(-1,-1,1);
	MFSetPosition( 1,-1,1);
	MFSetPosition( 1, 1,1);
	MFSetPosition(-1,-1,1);
	MFSetPosition( 1, 1,1);
	MFSetPosition(-1, 1,1);

	MFSetColour(0,0,1,1);
	MFSetPosition( 1,-1,1);
	MFSetPosition( 1,-1,-1);
	MFSetPosition( 1, 1,-1);
	MFSetPosition( 1,-1,1);
	MFSetPosition( 1, 1,-1);
	MFSetPosition( 1, 1,1);

	MFSetColour(1,0,1,1);
	MFSetPosition(-1,-1,1);
	MFSetPosition(-1, 1,1);
	MFSetPosition(-1, 1,-1);
	MFSetPosition(-1,-1,1);
	MFSetPosition(-1, 1,-1);
	MFSetPosition(-1,-1,-1);

	MFSetColour(1,1,0,1);
	MFSetPosition(-1, 1,1);
	MFSetPosition( 1, 1,1);
	MFSetPosition( 1, 1,-1);
	MFSetPosition(-1, 1,1);
	MFSetPosition( 1, 1,-1);
	MFSetPosition(-1, 1,-1);

	MFSetColour(0,1,1,1);
	MFSetPosition(-1,-1,1);
	MFSetPosition(-1,-1,-1);
	MFSetPosition( 1,-1,-1);
	MFSetPosition(-1,-1,1);
	MFSetPosition( 1,-1,-1);
	MFSetPosition( 1,-1,1);

	MFEnd();

	MFRect disp;
	MFDisplay_GetDisplayRect(&disp);
	MFView_SetOrtho(&disp);
	pUI->Draw();

	MFView_Pop();
}
コード例 #11
0
void MFCallstack_Draw()
{
    MFCALLSTACK;

    if(drawCallstack)
    {
        const MFDisplaySettings *pDisplaySettings = MFDisplay_GetDisplaySettings();
        float width = (float)pDisplaySettings->width;
        float height = (float)pDisplaySettings->height;
        float xoffset = width / 10.0f;
        float yoffset = height / 6.0f;

        MFView_Push();

        MFRect rect = { 0.f, 0.f, width, height };
        MFView_SetOrtho(&rect);

        float rtcFreq = 1000000.f / (float)MFSystem_GetRTCFrequency();

        MFVector callstackPos = MakeVector(xoffset, yoffset, 0.f, 0.f);

        // sort the calls
        qsort(gpProfiles, gNumProfileFunctions, sizeof(gpProfiles[0]), MFCallstack_SortPred);

//		if(!drawCallstackMeter)
        {
            // just draw the callstack profiling information..
            MFPrimitive_DrawUntexturedQuad(callstackPos.x - 10.f, callstackPos.y - 10.f, (width - callstackPos.x) + 10, callstackPos.y + (float)gNumProfileFunctions*16.0f + 10, MakeVector(0, 0, 0, 0.8f));

            for(int a=0; a<gNumProfileFunctions; a++)
            {
                uint32 microseconds = uint32((float)gpProfiles[a]->totalTime * rtcFreq);
                uint32 percent = uint32((float)microseconds / 166.66666f);

//				MFVector colour = gProfileColours[gpProfiles[a]->functionColour];
                MFVector colour = MFVector::one;
                MFFont_DrawTextf(MFFont_GetDebugFont(), callstackPos, 16.0f, colour, "%s", gpProfiles[a]->pFunctionName);
                MFFont_DrawTextf(MFFont_GetDebugFont(), callstackPos + MakeVector((width - xoffset) - 250.0f, 0, 0), 16.0f, colour, "- %dus (%d%%) %d calls", microseconds, percent, gpProfiles[a]->numCalls);
                callstackPos.y += 16.0f;
            }
        }
        /*
        		else
        		{
        			// draw a meter up the top of the screen representing the frame..

        			MFPrimitive_DrawUntexturedQuad(callstackPos.x - 10.f, callstackPos.y - 10.f, width - callstackPos.x + 10, callstackPos.y + (float)(gNumProfileTotals+1)*16.0f + 18, MakeVector(0, 0, 0, 0.8f));

        			MFVector meterPos = MakeVector(xoffset - 8.f, yoffset*0.5f - 15.0f, 0.0f);
        			MFVector meterDimensions = MakeVector(width - (xoffset-8.0f)*2.0f, 20.0f, 0.0f);

        			// draw the meter container
        			MFPrimitive_DrawUntexturedQuad(meterPos.x - 2.0f, meterPos.y - 2.0f, meterPos.x + meterDimensions.x + 2.0f, meterPos.y + meterDimensions.y + 2.0f, MakeVector(1.0f, 1.0f, 1.0f, 0.8f));
        			MFPrimitive_DrawUntexturedQuad(meterPos.x, meterPos.y, meterPos.x + meterDimensions.x, meterPos.y + meterDimensions.y, MakeVector(0.0f, 0.0f, 0.0f, 1.0f));

        			// draw the overhead counter
        			uint32 frameDuration = uint32(gBeginTime - gLastBeginTime);
        			float frameTime = (float)frameDuration * rtcFreq;
        			MFCallstackInternal_DrawMeterBlock(meterPos, meterDimensions, (float)(gEndTime - gLastBeginTime) / (float)frameTime, 1.0f, MakeVector(0.0f, 1.0f, 1.0f, 1.0f));
        			MFCallstackInternal_DrawMeterLabel(callstackPos, MakeVector(0.0f, 1.0f, 1.0f, 1.0f), "Frame Overhead/VSync", NULL);
        			callstackPos.y += 24.0f;

        			// draw all the totals
        			for(int a=0; a<gNumProfileTotals; a++)
        			{
        				uint32 microseconds = uint32((float)gpProfiles[a]->totalTime * rtcFreq);
        				uint32 percent = uint32((float)microseconds / 166.66666f);

        				MFCallstackInternal_DrawMeterLabel(callstackPos, gProfileColours[a % gProfileColourCount], gProfileTotals[a].pFunctionName, MFStr("- %dus (%d%%) %d calls", microseconds, percent, gProfileTotals[a].numCalls));
        				callstackPos.y += 16.0f;
        			}

        			// draw all the function profiles
        			float totalTime = (float)(gBeginTime - gLastBeginTime);
        			for(int a=0; a<gNumProfileResults; a++)
        			{
        				int colour = MFCallstackInternal_GetTotalIndex(a);
        				MFCallstackInternal_DrawMeterBlock(meterPos, meterDimensions, (float)(gProfileResults[a].startTime - gLastBeginTime) / totalTime, (float)(gProfileResults[a].endTime - gLastBeginTime) / totalTime, gProfileColours[colour % gProfileColourCount]);
        			}
        		}
        */

        MFView_Pop();
    }
}
コード例 #12
0
ファイル: Track.cpp プロジェクト: KingDwag/feedback-editor
void Fretboard::Draw(float time, dBChart *pSong, int track)
{
	MFCALLSTACKc;

	MFView_Push();

	MFRect rect;
	MFView_GetViewport(&rect);

	float aspect = rect.width / rect.height;
	aspect = MFClamp(0.82f, aspect, 2.0f);
	MFView_SetAspectRatio(aspect);

	if(viewPoint == 0)
	{
		// incoming
		MFView_ConfigureProjection(MFDEGREES(65.0f)/aspect, 1.0f, 100.0f);

		// Setup the Camera in 3D space.
		MFMatrix cameraMatrix;
		MFVector start = MakeVector( 0, 8, 3 );
		MFVector dir = MakeVector( 0, 5, -8 );
		dir = (dir-start) * (1.0f/1.777777777f);
		cameraMatrix.LookAt(start + dir*aspect, MakeVector(0.0f, 0.0f, 5.0f));
		MFView_SetCameraMatrix(cameraMatrix);
	}
	else if(viewPoint == 1)
	{
		// overhead
		MFView_ConfigureProjection(MFDEGREES(45.0f), 1.0f, 100.0f);
/*
		float aspect = MFDisplay_GetNativeAspectRatio();
		MFView_SetAspectRatio(aspect);

		MFRect projRect;
		projRect.y = 15;
		projRect.height = -30;
		projRect.x = -projRect.y * aspect;
		projRect.width = -projRect.height * aspect;
		MFView_SetOrtho(&projRect);
*/

		// Setup the Camera in 3D space.
		MFMatrix cameraMatrix;
		cameraMatrix.LookAt(MakeVector(0, 30, 10), MakeVector(0, 0, 10), MakeVector(0, 0, 1));
		MFView_SetCameraMatrix(cameraMatrix);
	}
	else if(viewPoint == 2)
	{
		// overhead
		MFView_ConfigureProjection(MFDEGREES(45.0f), 1.0f, 100.0f);
/*
		float aspect = MFDisplay_GetNativeAspectRatio();
		MFView_SetAspectRatio(aspect);

		MFRect projRect;
		projRect.y = 15;
		projRect.height = -30;
		projRect.x = -projRect.y * aspect;
		projRect.width = -projRect.height * aspect;
		MFView_SetOrtho(&projRect);
*/

		// Setup the Camera in 3D space.
		MFMatrix cameraMatrix;
		cameraMatrix.LookAt(MakeVector(0, 20, 13), MakeVector(0, 0, 13), MakeVector(-1, 0, 0));
		MFView_SetCameraMatrix(cameraMatrix);
	}

	MFView_SetProjection();

	MFMaterial *pFB = pSong->pFretboard ? pSong->pFretboard : pFretboard;
	MFMaterial_SetMaterial(pFB);
	MFPrimitive(PT_TriStrip, 0);

	int start = -4;
	int end = 60;
	int fadeStart = end - 10;

	float fretboardRepeat = 15.0f;
	float fretboardWidth = 7.0f;

	float columnWidth = fretboardWidth / 5.0f;
	float ringBorder = 0.1f;

	// draw the fretboard...
	MFBegin(((end-start) / 4) * 2 + 2);
	MFSetColourV(MFVector::white);

	float halfFB = fretboardWidth*0.5f;

	float offset = time*scrollSpeed;
	float topTime = time + end/scrollSpeed;
	float bottomTime = time + start/scrollSpeed;

	int a;
	float textureOffset = fmodf(offset, fretboardRepeat);
	for(a=start; a<end; a+=4)
	{
		float z = (float)a;
		MFSetTexCoord1(1.0f, 1.0f - (z+textureOffset) / fretboardRepeat);
		MFSetPosition(halfFB, 0.0f, z);
		MFSetTexCoord1(0.0f, 1.0f - (z+textureOffset) / fretboardRepeat);
		MFSetPosition(-halfFB, 0.0f, z);
	}

	float z = (float)a;
	MFSetTexCoord1(1.0f, 1.0f - (z+textureOffset) / fretboardRepeat);
	MFSetPosition(halfFB, 0.0f, z);
	MFSetTexCoord1(0.0f, 1.0f - (z+textureOffset) / fretboardRepeat);
	MFSetPosition(-halfFB, 0.0f, z);

	MFEnd();

	// draw the selection region
	MFMaterial_SetMaterial(pFrets);
	MFPrimitive(PT_TriStrip, 0);

	if(gEditor.selectStart != gEditor.selectEnd)
	{
		float selectStartTime = GETSECONDS(pSong->CalculateTimeOfTick(gEditor.selectStart));
		float selectEndTime = GETSECONDS(pSong->CalculateTimeOfTick(gEditor.selectEnd));

		if(selectStartTime < topTime && selectEndTime > bottomTime)
		{
			selectStartTime = (MFMax(bottomTime, selectStartTime) - time) * scrollSpeed;
			selectEndTime = (MFMin(topTime, selectEndTime) - time) * scrollSpeed;

			MFBegin(4);
			MFSetColour(1.0f, 0.0f, 0.0f, 0.5f);
			MFSetPosition(-halfFB, 0.0f, selectEndTime);
			MFSetPosition(halfFB, 0.0f, selectEndTime);
			MFSetPosition(-halfFB, 0.0f, selectStartTime);
			MFSetPosition(halfFB, 0.0f, selectStartTime);
			MFEnd();
		}
	}

	// draw the fretboard edges and bar lines
	const float barWidth = 0.2f;

	MFMaterial_SetMaterial(pBar);
	MFPrimitive(PT_TriStrip, 0);

	MFBegin(4);
	MFSetColour(0.0f, 0.0f, 0.0f, 0.8f);
	MFSetTexCoord1(0,0);
	MFSetPosition(-halfFB, 0.0f, barWidth);
	MFSetTexCoord1(1,0);
	MFSetPosition(halfFB, 0.0f, barWidth);
	MFSetTexCoord1(0,1);
	MFSetPosition(-halfFB, 0.0f, -barWidth);
	MFSetTexCoord1(1,1);
	MFSetPosition(halfFB, 0.0f, -barWidth);
	MFEnd();

	MFMaterial_SetMaterial(pEdge);
	MFPrimitive(PT_TriStrip, 0);
	MFBegin(34);

	MFSetColour(0.0f, 0.0f, 0.0f, 0.3f);
	for(int col=1; col<5; col++)
	{
		if(col > 1)
			MFSetPosition(-halfFB + columnWidth*(float)col - 0.02f, 0.0f, (float)end);

		MFSetTexCoord1(0,0);
		MFSetPosition(-halfFB + columnWidth*(float)col - 0.02f, 0.0f, (float)end);
		MFSetTexCoord1(1,0);
		MFSetPosition(-halfFB + columnWidth*(float)col + 0.02f, 0.0f, (float)end);
		MFSetTexCoord1(0,1);
		MFSetPosition(-halfFB + columnWidth*(float)col - 0.02f, 0.0f, (float)start);
		MFSetTexCoord1(1,1);
		MFSetPosition(-halfFB + columnWidth*(float)col + 0.02f, 0.0f, (float)start);

		MFSetPosition(-halfFB + columnWidth*(float)col + 0.02f, 0.0f, (float)start);
	}
	MFSetColourV(MFVector::white);
	MFSetPosition(-halfFB - 0.1f, 0.0f, (float)end);

	MFSetTexCoord1(0,0);
	MFSetPosition(-halfFB - 0.1f, 0.0f, (float)end);
	MFSetTexCoord1(1,0);
	MFSetPosition(-halfFB + 0.1f, 0.0f, (float)end);
	MFSetTexCoord1(0,1);
	MFSetPosition(-halfFB - 0.1f, 0.0f, (float)start);
	MFSetTexCoord1(1,1);
	MFSetPosition(-halfFB + 0.1f, 0.0f, (float)start);

	MFSetPosition(-halfFB + 0.1f, 0.0f, (float)start);
	MFSetPosition(halfFB - 0.1f, 0.0f, (float)end);

	MFSetTexCoord1(0,0);
	MFSetPosition(halfFB - 0.1f, 0.0f, (float)end);
	MFSetTexCoord1(1,0);
	MFSetPosition(halfFB + 0.1f, 0.0f, (float)end);
	MFSetTexCoord1(0,1);
	MFSetPosition(halfFB - 0.1f, 0.0f, (float)start);
	MFSetTexCoord1(1,1);
	MFSetPosition(halfFB + 0.1f, 0.0f, (float)start);

	MFEnd();

	// draw the frets....
	MFMaterial_SetMaterial(pBar);
	MFPrimitive(PT_TriStrip, 0);

	int bottomTick = pSong->CalculateTickAtTime((int64)(bottomTime*1000000.0f));
	int res = pSong->GetRes();
	int ticks = bHalfFrets ? res/2 : res;
	int fretBeat = bottomTick + ticks - 1;
	fretBeat -= fretBeat % ticks;
	float fretTime = GETSECONDS(pSong->CalculateTimeOfTick(fretBeat));

	while(fretTime < topTime)
	{
		bool halfBeat = (fretBeat % res) != 0;
		bool bar = false;

		if(!halfBeat)
		{
			GHEvent *pLastTS = pSong->sync.GetMostRecentEvent(GHE_TimeSignature, fretBeat);

			if(pLastTS)
				bar = ((fretBeat - pLastTS->tick) % (pLastTS->parameter*res)) == 0;
			else if(fretBeat == 0)
				bar = true;
		}

		float bw = bar ? barWidth : barWidth*0.5f;
		MFBegin(4);

		float position = (fretTime - time) * scrollSpeed;

		if(!halfBeat)
			MFSetColourV(MFVector::white);
		else
			MFSetColourV(MakeVector(1,1,1,0.3f));
		MFSetTexCoord1(0,0);
		MFSetPosition(-halfFB, 0.0f, position + bw);
		MFSetTexCoord1(1,0);
		MFSetPosition(halfFB, 0.0f, position + bw);
		MFSetTexCoord1(0,1);
		MFSetPosition(-halfFB, 0.0f, position + -bw);
		MFSetTexCoord1(1,1);
		MFSetPosition(halfFB, 0.0f, position + -bw);

		MFEnd();

		fretBeat += ticks;
		fretTime = GETSECONDS(pSong->CalculateTimeOfTick(fretBeat));
	}

	// draw the notes...
	GHEventManager &noteStream = pSong->notes[track];
	GHEvent *pEv = noteStream.First();

	int64 topTimeus = (int64)(topTime*1000000.0f);
	while(pEv && pEv->time < topTimeus)
	{
		if((pEv->event == GHE_Note || pEv->event == GHE_Special) && pEv->tick + pEv->parameter >= bottomTick)
		{
			float evTime = GETSECONDS(pEv->time);

			// TODO: we need to calculate the end of the hold...
			float noteEnd = evTime;
			if(pEv->parameter)
				noteEnd = GETSECONDS(pSong->CalculateTimeOfTick(pEv->tick + pEv->parameter));

			if(pEv->event == GHE_Note && pEv->played != 1)
			{
				// draw a note
				int key = pEv->key;
				bool tap = false;

				// check if there is a previous note, and it is in range
				if(pEv->Prev() && pEv->Prev()->tick < pEv->tick && pEv->Prev()->tick > pEv->tick - (res/2) && pEv->Prev()->key != pEv->key
					&& (!pEv->Next() || !(pEv->Next()->tick == pEv->tick))
					&& !pEv->Prev()->parameter && !(pEv->Prev()->Prev() && pEv->Prev()->Prev()->tick == pEv->Prev()->tick))
				{
					tap = true;
				}

				int noteX = gConfig.controls.leftyFlip[0] ? 4-key : key;

				float position = (GETSECONDS(pEv->time) - time)*scrollSpeed;
				float xoffset = -halfFB + columnWidth*0.5f + (float)noteX*columnWidth;

				if(pEv->parameter)
				{
					MFMaterial_SetMaterial(pFrets);

					float whammyTop = (noteEnd - time)*scrollSpeed;

					MFPrimitive(PT_TriStrip, 0);

					// TODO: we could consider not drawing this part of the hold line.. seems reasonable that it terminates at the line...
					if(gEditor.state == GHPS_Stopped)
					{
						if(position < 0.0f)
						{
							MFBegin(4);
							MFSetColourV(gColours[key]);
							MFSetPosition(xoffset - 0.2f, 0.0f, MFMin(whammyTop, 0.0f));
							MFSetPosition(xoffset + 0.2f, 0.0f, MFMin(whammyTop, 0.0f));
							MFSetPosition(xoffset - 0.2f, 0.0f, position);
							MFSetPosition(xoffset + 0.2f, 0.0f, position);
							MFEnd();
						}
					}

					if(whammyTop > 0.0f)
					{
						// this half could have waves cruising down it if we wanted to support the whammy...
						MFBegin(4);
						MFSetColourV(gColours[key]);
						MFSetPosition(xoffset - 0.2f, 0.0f, MFMin(whammyTop, (float)end));
						MFSetPosition(xoffset + 0.2f, 0.0f, MFMin(whammyTop, (float)end));
						MFSetPosition(xoffset - 0.2f, 0.0f, MFMax(position, 0.0f));
						MFSetPosition(xoffset + 0.2f, 0.0f, MFMax(position, 0.0f));
						MFEnd();
					}
				}

				if(evTime >= bottomTime)
				{
					MFMatrix mat;
					mat.SetScale(MakeVector(0.5f/20, 0.5f/20, 0.5f/20));
					mat.Translate(MakeVector(xoffset, 0.03f, position));
					MFModel_SetWorldMatrix(pButton, mat);

					MFStateBlock *pSB = MFStateBlock_CreateTemporary(64);
					MFStateBlock_SetVector(pSB, MFSCV_DiffuseColour, pEv->played == -1 ? MakeVector(0.3f, 0.3f, 0.3f, 1.0f) : MFVector::white);
//					MFStateBlock_SetVector(pSB, MFSCV_DiffuseColour, position < 0.0f ? MakeVector(0.3f, 0.3f, 0.3f, 1.0f) : MFVector::white);

//					MFRenderer_SetRenderStateOverride(MFRS_MaterialOverride, (uint32&)(tap ? pButtonMat[key] : pButtonRing[key]));
					MFRenderer_AddModel(pButton, pSB, MFView_GetViewState());

					// render the note time
					if(bRenderNoteTimes)
					{
						MFView_Push();
						MFView_SetOrtho(&rect);

						MFVector pos;
						MFView_TransformPoint3DTo2D(MakeVector(xoffset, 0.0f, position), &pos);
						pos.x += 16.0f;
						pos.y -= 26.0f;

						int minutes = (int)(pEv->time / 60000000);
						int seconds = (int)((pEv->time % 60000000) / 1000000);
						int milliseconds = (int)((pEv->time % 1000000) / 1000);
						MFFont_DrawTextf(pText, pos, 20.0f, MFVector::yellow, "%s: %d:%02d.%d\nTick: %g", MFTranslation_GetString(pStrings, TRACK_TIME), minutes, seconds, milliseconds, (float)pEv->tick/res);

						MFView_Pop();
					}
				}
			}

			if(pEv->event == GHE_Special)
			{
//				static MFVector specialColours[3] = { MakeVector(1,0,0,1), MakeVector(1,1,0,1), MakeVector(0,0,1,1) };
//				static float specialX[3] = { halfFB + 0.2f, halfFB + 1, -halfFB - 1 };
//				static float specialWidth[3] = { 0.8f, 0.8f, 0.8f };
				static MFVector specialColours[3] = { MakeVector(1,0,0,0.5f), MakeVector(1,1,0,0.5f), MakeVector(0,0,1,0.5f) };
				static float specialX[3] = { -halfFB, halfFB - 0.8f, -halfFB };
				static float specialWidth[3] = { 0.8f, 0.8f, fretboardWidth };

				float bottom = (evTime - time)*scrollSpeed;
				float top = (noteEnd - time)*scrollSpeed;

				int key = pEv->key;

				MFMaterial_SetMaterial(pFrets);

				MFPrimitive(PT_TriStrip, 0);
				MFBegin(4);
				MFSetColourV(specialColours[key]);
				MFSetPosition(specialX[key], 0.0f, MFMin(top, (float)end));
				MFSetPosition(specialX[key]+specialWidth[key], 0.0f, MFMin(top, (float)end));
				MFSetPosition(specialX[key], 0.0f, MFMax(bottom, (float)start));
				MFSetPosition(specialX[key]+specialWidth[key], 0.0f, MFMax(bottom, (float)start));
				MFEnd();
			}
		}

		pEv = pEv->Next();
	}

//	MFRenderer_SetRenderStateOverride(MFRS_MaterialOverride, NULL);

	// draw circles at the bottom..
	MFMaterial_SetMaterial(pRing);
	for(int a=0; a<5; a++)
	{
		DrawRing(-halfFB + (float)a*columnWidth + columnWidth*ringBorder, 0.0f, columnWidth*(1.0f-ringBorder*2));
	}

	for(int a=0; a<5; a++)
	{
		dBControlType keys_righty[] = { dBCtrl_Edit_Note0, dBCtrl_Edit_Note1, dBCtrl_Edit_Note2, dBCtrl_Edit_Note3, dBCtrl_Edit_Note4 };
		dBControlType keys_lefty[] = { dBCtrl_Edit_Note4, dBCtrl_Edit_Note3, dBCtrl_Edit_Note2, dBCtrl_Edit_Note1, dBCtrl_Edit_Note0 };
		dBControlType *keys = gConfig.controls.leftyFlip[0] ? keys_lefty : keys_righty;

		int ringPos = gConfig.controls.leftyFlip[0] ? 4-a : a;

		MFMaterial_SetMaterial(pColourRing[a]);
		DrawRing(-halfFB + (float)ringPos*columnWidth, 0.0f, columnWidth, !TestControl(keys[a], GHCT_Hold));
	}

	// render trigger particles
	MFParticleSystem_Draw(pParticles);

	// render text and stuff
	MFView_SetOrtho(&rect);

	pEv = pSong->sync.GetNextEvent(bottomTick);

	while(pEv && pEv->time < topTimeus)
	{
		float evTime = GETSECONDS(pEv->time);

		if(evTime > bottomTime)
		{
			if(pEv->event == GHE_BPM)
			{
				float position = (evTime - time) * scrollSpeed;

				MFVector pos;
				MFView_TransformPoint3DTo2D(MakeVector(halfFB + 0.2f, 0.0f, position), &pos);
				pos.y -= 12.0f;
				MFFont_DrawTextf(pText, pos, 24.0f, MakeVector(0,0.5f,0,1), "%s: %g", MFTranslation_GetString(pStrings, TRACK_BPM), (float)pEv->parameter * 0.001f);
			}
			if(pEv->event == GHE_Anchor)
			{
				int minutes = (int)(pEv->time / 60000000);
				int seconds = (int)((pEv->time%60000000)/1000000);
				int milliseconds = (int)((pEv->time%1000000)/1000);

				float position = (evTime - time) * scrollSpeed;

				MFVector pos;
				MFView_TransformPoint3DTo2D(MakeVector(halfFB + 0.2f, 0.0f, position), &pos);
				pos.y -= 12.0f;
				MFFont_DrawTextf(pText, pos, 24.0f, MakeVector(0,0.5f,0,1), "A: %02d:%02d.%03d\n   %s: %g", minutes, seconds, milliseconds, MFTranslation_GetString(pStrings, TRACK_BPM), (float)pEv->parameter * 0.001f);
			}
			else if(pEv->event == GHE_TimeSignature)
			{
				float position = (evTime - time) * scrollSpeed;

				MFVector pos;
				MFView_TransformPoint3DTo2D(MakeVector(-halfFB - 0.2f, 0.0f, position), &pos);
				const char *pString = MFStr("TS: %d/4", pEv->parameter);
				pos.x -= MFFont_GetStringWidth(pText, pString, 24.0f);
				pos.y -= 12.0f;
				MFFont_DrawTextf(pText, pos, 24.0f, MFVector::yellow, pString);
			}
		}

		pEv = pEv->Next();
	}

	// render events
	pEv = pSong->events.GetNextEvent(bottomTick);

	int lastChecked = -1;
	float yEventOffset = -12.0f;
	while(pEv && pEv->time < topTimeus)
	{
		float evTime = GETSECONDS(pEv->time);

		if(evTime > bottomTime)
		{
			if(pEv->event == GHE_Event)
			{
				if(lastChecked != pEv->tick)
				{
					yEventOffset = -12.0f;
					lastChecked = pEv->tick;

					if(pSong->sync.FindEvent(GHE_TimeSignature, pEv->tick, 0))
					{
						yEventOffset -= 24.0f;
					}
				}

				float position = (evTime - time) * scrollSpeed;

				MFVector pos;
				MFView_TransformPoint3DTo2D(MakeVector(-halfFB - 0.2f, 0.0f, position), &pos);

				if(!MFString_CompareN(pEv->GetString(), "section ", 8))
				{
					// draw a line across?

					pos.x -= MFFont_GetStringWidth(pText, &pEv->GetString()[8], 24.0f);
					pos.y += yEventOffset;
					MFFont_DrawTextf(pText, pos, 24.0f, MFVector::blue, &pEv->GetString()[8]);
				}
				else
				{
					pos.x -= MFFont_GetStringWidth(pText, pEv->GetString(), 24.0f);
					pos.y += yEventOffset;
					MFFont_DrawTextf(pText, pos, 24.0f, MFVector::white, pEv->GetString());
				}

				yEventOffset -= 24.0f;
			}
		}

		pEv = pEv->Next();
	}

	// render track events
	pEv = pSong->notes[track].GetNextEvent(bottomTick);

	lastChecked = -1;
	yEventOffset = -12.0f;
	while(pEv && pEv->time < topTimeus)
	{
		float evTime = GETSECONDS(pEv->time);

		if(evTime > bottomTime)
		{
			if(pEv->event == GHE_Event)
			{
				if(lastChecked != pEv->tick)
				{
					yEventOffset = -12.0f;
					lastChecked = pEv->tick;

					if(pSong->sync.FindEvent(GHE_TimeSignature, pEv->tick, 0))
					{
						yEventOffset -= 24.0f;
					}

					GHEvent *pOther = pSong->events.FindEvent(GHE_Event, pEv->tick, 0);
					while(pOther && pOther->tick == pEv->tick)
					{
						yEventOffset -= 24.0f;
						pOther = pOther->Next();
					}
				}

				float position = (evTime - time) * scrollSpeed;

				MFVector pos;
				MFView_TransformPoint3DTo2D(MakeVector(-halfFB - 0.2f, 0.0f, position), &pos);

				pos.x -= MFFont_GetStringWidth(pText, pEv->GetString(), 24.0f);
				pos.y += yEventOffset;
				MFFont_DrawTextf(pText, pos, 24.0f, MakeVector(0.6f, 0.8f, 1.0f, 1.0f), pEv->GetString());

				yEventOffset -= 24.0f;
			}
		}

		pEv = pEv->Next();
	}

	MFView_Pop();
}