forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Orthogonal projection problems

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Sat Feb 25, 2006 9:47 pm    Post subject: Orthogonal projection problems Reply with quote

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:
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumOrtho(0,480,272,0,0,1);

This code works for OpenGL, but not for PSP :( I also tried:
Code:
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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Feb 25, 2006 10:19 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Sat Feb 25, 2006 10:33 pm    Post subject: Reply with quote

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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Feb 25, 2006 10:43 pm    Post subject: Reply with quote

Then most likely something is wrong with your drawing code, as I cannot see anything wrong in the setup of the ortho view then.
Back to top
View user's profile Send private message Visit poster's website
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Sat Feb 25, 2006 11:51 pm    Post subject: Reply with quote

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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Feb 26, 2006 12:27 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Sun Feb 26, 2006 3:06 am    Post subject: Reply with quote

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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Feb 26, 2006 10:58 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Mon Feb 27, 2006 3:06 am    Post subject: Reply with quote

Thank you very much, I'll stick with 2D then :)
_________________
Sorry for my bad english
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group