Orthogonal projection problems

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Orthogonal projection problems

Post by Brunni »

I'm new in 3D development, and I would just like to create an orthogonic projection so that I can draw 2D things using GU_TRANSFORM_3D (not 2D).
I'm trying with sceGumOrtho but it hangs my PSP :(

Code: Select all

sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumOrtho(0,480,272,0,0,1);
This code works for OpenGL, but not for PSP :( I also tried:

Code: Select all

void myOrtho(float left, float top, float right, float bottom, float near, float far)			{
	ScePspFMatrix4 matrix;
	float *m = (float*)&matrix;
	float width = right-left; 
	float height = bottom-top; 
	float depth = near-far;
	m[0*4+0] = 2.0f/width; 
	m[1*4+1] = 2.0f/height; 
	m[2*4+2] = 2.0f/depth; 
	m[3*4+0] = -(left+right)/width; 
	m[3*4+1] = -(top+bottom)/height; 
	m[3*4+2] = -(near+far)/depth; 
	m[3*4+3] = 1.0f;
	sceGuSetMatrix(GU_PROJECTION, &matrix);
}
But it's false (nothing is displayed then)... What should I do?
Thank you very much in advance for your replies!
Sorry for my bad english
Image Oldschool library for PSP - PC version released
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Just a guess, but probably you should try something else than 0 for the near z plane, because this can lead to divisions by zero. Also try something bigger than 1 for accuracy reasons. Also adjust the far plane then and allow something bigger than one. I'd also recommend not using only this very short visible z range of 0-1. It won't hurt your programming if you allow for deeper z values, since it's just internally.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

I'm sorry, but it doesn't work for me (but doesn't hang if near != 0).
Maybe I'm doing something wrong... with OpenGL it also doesn't draw anything with another value than 0 for near, even when the vertices z value == near value. I really don't know what to do :(
Any help appreciated, thanks :)
Sorry for my bad english
Image Oldschool library for PSP - PC version released
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Then most likely something is wrong with your drawing code, as I cannot see anything wrong in the setup of the ortho view then.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Okay thanks, I modified the cube sample for an already set-up 3D environment, and it works, but the problem now is that my texture (u, v) coordinates must be between 0 and 1! Or I have to do a sceGuTexScale with 1/texture size, which will slow down my 2D drawing code :(
Is there a possibility to bypass this, like in 2D mode?
Sorry for my bad english
Image Oldschool library for PSP - PC version released
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Not that I know off. Maybe some combination of sceGuTexProjMapMode and sceGuTexMapMode could lead to the result.
But sceGuTexScale shouldn't slow down the drawing too much really, however you could also still prescale all texture coordinates when you load up your level/sprites/whatever rather than before each drawing.
This should definitely work without any speed-drop.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Ok thank you very much. What would you think is best for my 2D (exclusively) library, 2D or orthogonic 3D?
The only advantage for 3D now is the windowing (I asked in the other topic), sceGuOffset won't take effect in 2D. But the disadvantage is a quite huge (for a lib) speed-down...
Sorry for my bad english
Image Oldschool library for PSP - PC version released
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

I'd say it depends on how you want the windowing to work. If you want only one window, you could just fake windowing by rendering a black mask over the screen. If you want more than one window, you could also render your screens to seperate textures and then render the textures in the window size to a black screen.
If this is an option for you, I'd definitely stick with 2D rendering. Only if you are really at the need of something very special that cannot be emulated or otherwise implemented in 2D I'd use 3D rendering.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Thank you very much, I'll stick with 2D then :)
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Post Reply