Welcome! Log In Create A New Profile

Advanced

guOrtho() and GX_SetViewport()

Posted by blitter 
guOrtho() and GX_SetViewport()
February 25, 2009 12:51AM
I've been attempting to set up an ortho screen so that the corner is located at 0,0 when I perform a GX_Position3f32() - I say "corner" meaning; exactly under the top black border, and a couple of cm from the left of an average display.

But here's the thing, I also want to allow for the pointer to be positioned right off the screen so that it will always scroll off without suddenly vanishing. So I use something like "GX_SetViewport(-64,-64,rMode->fbWidth+64,rMode->efbHeight+64,0,1);"...however, it's all a bit of a mess as if I draw a box the size of the screen (640x480 in PAL60) then there's a chunk missing and nothing is really centered. The mess appears when I try to correct things!

I would really like to have things positioned in a logical way in all modes: PAL50, PAL60/NTSC / 4:3, 16:9, and also when the user has their TV/monitor set at 16:10

As for the "GX_Position3f32()" in 2D mode I tried "GX_Position2f32()" but it causes a crash? Is there anything like "GX_Position2i()"?

Thanks for any understanding you can bring :)
Re: guOrtho() and GX_SetViewport()
February 25, 2009 11:28AM
I'm not sure I understood what you say but I'll try to answer

This is what I use for setting up a simple 2D layer:


guOrtho(perspective,0,480,0,639,1.0,300.0);
GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC);

As you can see, the order of arguments is slightly different from what you use. Once you fix that you can start thinking about the problem about the scroll. Remember that the arguments you pass to the function arent the size of your viewport in screen space but in 3D space. You're creating a viewport of the size of the screen, that shows a portion of 2D space of some size. What I mean is that changing the size of your proyection matrix won't affect your viewport size nor the positions wiimote can point to.

What can you do? I suggest you store the last correct coordinates of the wiimote and use them to scroll. For example, if the last correct coordinate was on the top of screen, keep scrolling up while wiimote points out of the screen.

And about the crash with GX_Position2f32(), have you forgotten setting the vertex attributes? I mean this
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0);
instead of this
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);

Hope that helps
Re: guOrtho() and GX_SetViewport()
February 26, 2009 01:21AM
Thanks for the reply.

The GX_SetVtxAttrFmt() was a complete overlook by me, it was left in the init code. Cheers that helped optimize my 2D GX_Begin()s.

As for setting up ortho mode, I wanted to achieve what TT had done with the HomeBrew Channel. Notice how they allow the pointer to scroll completely off screen. So your suggestion was out of the question! But thanks for it anyway :)
The mistake I was making, I guess ;) was presuming the Wii had some sort of "overscan" that could be written to. But instead the vi is stretched to accommodate.

Here's how I'm now doing things (with pointer acting exactly as desired!):

init code:
	//50/60Hz?
	if(rMode->xfbHeight == 528) PAL60 = false;
	else PAL60 = true;

	//widescreen?
	if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) widescreen = true;
	else widescreen = false;

	/* Widescreen patch by CashMan's Productions (http://www.CashMan-Productions.fr.nf) */
	if (widescreen) {
//		aspectRatio = 16.0f / 9.0f;
		rMode->viWidth = 678;
		rMode->viXOrigin = (VI_MAX_WIDTH_NTSC - 678)/2;
	}
	else {
	...

	screenWidth = rMode->fbWidth;			//note: fbWidth is always 640
	screenHeight = rMode->efbHeight;

...

drawing code:
	/*------------*/
	//3D
	GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);

	/*------------*/
	//2D
		GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0);
	
	...
	
	guOrtho(perspective, 0,rMode->viHeight-1, 0,rMode->viWidth-1, 0,300);
	GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC);
	GX_SetViewport(-64,-64,rMode->viWidth+64,rMode->viHeight+64,0,1);
	
	...
	
	//here is a test box (outline) representing max visible area on my monitor (I will adjust this after testing elsewhere)
	if(widescreen) {
		if(PAL60) DrawQuad(76, 69, screenWidth-90, screenHeight-81, (GXColor){0xff,0xff,0xff,0xff}, false);
		else DrawQuad(77, 58, screenWidth-93, screenHeight-58, (GXColor){0xff,0xff,0xff,0xff}, false);
	}
	else {
		if(PAL60) DrawQuad(59, 69, screenWidth-65, screenHeight-81, (GXColor){0xff,0xff,0xff,0xff}, false);
		else DrawQuad(59, 58, screenWidth-69, screenHeight-58, (GXColor){0xff,0xff,0xff,0xff}, false);
	}

As you can see, it's a hack and not very consistent. But it works...I just was hoping I could access a full 640x480 (PAL60) under all visible circumstances.
Sorry, only registered users may post in this forum.

Click here to login