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 

IntraFont and Image rendering

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



Joined: 04 Jan 2009
Posts: 8

PostPosted: Sun Jun 20, 2010 9:56 am    Post subject: IntraFont and Image rendering Reply with quote

I am having a problem I've seen other people have had with IntraFont and rendering images. I fixed it on my own, it turned out to be sceGuTexMode(GU_PSM_T4,.... screwing everything up. I fixed it, but the fix requires I call sceGuTexMode(GU_PSM_8888,0,0,0); every frame.

It's clearly visible that when I do this the FPS drops well below 20. When I do not use IntraFont at all and don't call sceGuTexMode every frame the FPS is 60 like it should be.

Is there any alternative to this other than implementing my own image font class?
Back to top
View user's profile Send private message
BenHur



Joined: 20 Oct 2007
Posts: 30

PostPosted: Mon Jun 21, 2010 2:55 am    Post subject: Re: IntraFont and Image rendering Reply with quote

Hi stinkee2
stinkee2 wrote:
I am having a problem I've seen other people have had with IntraFont and rendering images.

Let me guess: you (like the other people) did not read the readme...
stinkee2 wrote:
I fixed it on my own

...or you could just have read the readme...
stinkee2 wrote:
, it turned out to be sceGuTexMode(GU_PSM_T4,.... screwing everything up. I fixed it, but the fix requires I call sceGuTexMode(GU_PSM_8888,0,0,0); every frame.

It's clearly visible that when I do this the FPS drops well below 20. When I do not use IntraFont at all and don't call sceGuTexMode every frame the FPS is 60 like it should be.

E.g. the intraFont sample code has no performance problem with the sceGuTexMode call added. You're probably doing something wrong, but without code I don't even start guessing.
stinkee2 wrote:
Is there any alternative to this other than implementing my own image font class?
Alternative to what? Your performance problem? (debug/optimize your code) intraFont? (pgeFont is recommended for ttf fonts, but you'll run into the same problems as intraFont uses similar techniques.)

Cheers, BenHur
Back to top
View user's profile Send private message
stinkee2



Joined: 04 Jan 2009
Posts: 8

PostPosted: Mon Jun 21, 2010 5:55 am    Post subject: Reply with quote

Actually, I used the intrafont files from the SDK sample because I was not connected to the internet when I decided to implement your library. The one in the SDK sample didn't have a readme.

...Whoops, I just checked. It does in the doc\intraFont directory.

Anyway, I tried drawing the images the same way they are drawn in the graphics library, the same thing happens.

Font drawing function
Code:

void GFPrintf(const Vector2D &V,u32 Color,float Size,const char *Text,...)
            {
                if(!UseFont)
                {
                    return;
                }
                va_list Args;
                va_start(Args,Text);
                char *str = (char*)malloc(256 * sizeof(char));
                vsnprintf(str,255,Text,Args);
                va_end(Args);
                intraFontSetStyle(_PSP_FONT,Size / 100.0f,Color,Fade(DEFAULT_TEXT_COLOR,230),INTRAFONT_ALIGN_LEFT);
                intraFontPrint(_PSP_FONT,V.X,V.Y + (14.0f * (Size / 100.0f)),str);
                free(str);
                sceGuTexMode(GU_PSM_8888,0,0,0); //Without this I get 60FPS
            }


Image drawing code:
Code:


        void DrawImage(const Vector2D &Pos,const Dimension2D &Size,bool Center,Image *Img)
            {
                if(!Img) return;
                sceGuDisable(GU_DEPTH_TEST);
                sceGuEnable(GU_TEXTURE_2D);

                Dimension2D Dimensions = Size;
                if(Size.Width == 0.0f || Size.Height == 0.0f) Dimensions = Dimension2D(Img->imageWidth,Img->imageHeight);

                sceKernelDcacheWritebackInvalidateAll();

                Vector2D V1 = Pos;
                if(Center) V1 -= Dimension2D(Dimensions.HalfWidth(),Dimensions.HalfHeight());

                sceGuTexImage(0,Img->textureWidth,Img->textureHeight,Img->textureWidth,(void *)Img->data);
                float u = 1.0f / ((float)Img->textureWidth);
                float v = 1.0f / ((float)Img->textureHeight);
                sceGuTexScale(u,v);

                VertexUV* vertices = (VertexUV*) sceGuGetMemory(2 * sizeof(VertexUV));

                //Top Left
                vertices[0].U = 0;
                vertices[0].V = 0;
                vertices[0].X = V1.X;
                vertices[0].Y = V1.Y;
                vertices[0].Z = 0;

                //Bottom Right
                vertices[1].U = Dimensions.Width;
                vertices[1].V = Dimensions.Height;
                vertices[1].X = Pos.X + Dimensions.Width;
                vertices[1].Y = Pos.Y + Dimensions.Height;
                vertices[1].Z = 0;

                sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);

                sceGuEnable(GU_DEPTH_TEST);
                sceGuDisable(GU_TEXTURE_2D);
            }

I don't think it's really necessary to post my code though.

Without using intrafont I get 60FPS with the image drawing function, so It's not my code.
EDIT: Unless there's something I'm doing or rather not doing that I don't know about.
Back to top
View user's profile Send private message
BenHur



Joined: 20 Oct 2007
Posts: 30

PostPosted: Mon Jun 21, 2010 7:28 am    Post subject: Reply with quote

The stuff you posted looks ok to me (but I can't check your main loop, where all the GU start, finish and displaylist stuff happens). Also: I don't know whether you removed just the sceGuTexMode(GU_PSM_8888,0,0,0); call to get 60 FPS or you set UseFont to false.
Some more questions that you might want to check: Did you ever run your code with font drawing but without image drawing? How much text are you drawing? Is there clipping involved?
Other than that I'm clueless - maybe somebody with a deeper knowledge of the GU could help you.

Cheers, BenHur

PS: if GU_PSM_T4 is really your problem (which right now I have a hard time believing), you could adapt the intraFont code easily - the intraFont textures would use up more memory, but everything should still work.
Back to top
View user's profile Send private message
stinkee2



Joined: 04 Jan 2009
Posts: 8

PostPosted: Mon Jun 21, 2010 10:06 am    Post subject: Reply with quote

Well, the game loop is while(Running()) and this is that function:
Code:


        bool Running()
            {
                Btns.ReadButtons();
                Btns.UpdateFreezeTime();
                if(GraphicsEnabled)
                {
                    //Calculate the FPS for the frame
                    CalculateFPS();

                    //If fading in or out
                    if(FadingIn || FadingOut)
                    {
                        if(FadingIn) FadeAlpha -= FadeInc;
                        if(FadingOut) FadeAlpha += FadeInc;
                        if(FadeAlpha < 0)
                        {
                            FadeAlpha = 0;
                            FadingIn = false;
                        }
                        if(FadeAlpha > 255)
                        {
                            FadeAlpha = 255;
                            FadingOut = false;
                        }
                        DrawRect(SetAlpha(FadeColor,FadeAlpha),Vector2D(0,0),Dimension2D(480,272),true,false,0.0f);
                    }

                    //End & Render the last frame
                    sceGuFinish();
                    sceGuSync(0,0);
                    sceDisplayWaitVblankStart();
                    sceGuSwapBuffers();

                    //Start a new Frame
                    sceGuStart(GU_DIRECT,DisplayList);

                    //Clear Screen
                    sceGuClearColor(PSP_BACK_COLOR);
                    sceGuClearDepth(0);
                    sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

                    //Set View Matrix To Active Camera
                    sceGumMatrixMode(GU_VIEW);
                    sceGumLoadIdentity();
                    ScePspFVector3 eye,center,up;
                    eye.x = ViewCamera->Position.X;
                    eye.y = ViewCamera->Position.Y;
                    eye.z = ViewCamera->Position.Z;
                    center.x = ViewCamera->Target.X;
                    center.y = ViewCamera->Target.Y;
                    center.z = ViewCamera->Target.Z;
                    up.x = ViewCamera->Up.X;
                    up.y = ViewCamera->Up.Y;
                    up.z = ViewCamera->Up.Z;

                    sceGumLookAt(&eye,&center,&up);

                    //sceGumMatrixMode(GU_PROJECTION);
                    //sceGumLoadIdentity();

                    //Ambient Light
                    sceGuAmbientColor(PSP_AMBIENT_COLOR);

                    //Render the GUI if needed
                    if(_UseGUI)
                    {
                        DrawGUI();
                    }
                }
                return true;
            }


What I have here is more than just a simple game, I think might even deserve the title "engine". It has a full GUI, 3D capabilities, 2D stuff (even a built in tile engine), Artificial Intelligence stuff, etc... I just havn't released it yet. That's beside the point though. I developed it completely from scratch, it uses the GU. I'm no noob :p.

Also, UseFont is only false if the user decides to comment out the line in the main include that initializes your font library. Which I thank you for making, It's marvelous.

Not much text, it happens when I draw only 3 short strings of text. "New Game", "Start Game", and "Exit".

I'd like to thank you for taking your time to post here :D.
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