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 

simple gu question

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



Joined: 24 Mar 2008
Posts: 140

PostPosted: Sat Jan 16, 2010 8:51 pm    Post subject: simple gu question Reply with quote

this is the first time i'm trying to use psp internal gu library.

the question is: how can i draw a line from let's say (10,20) to (400, 220), specifing the cordinates in pixels and working in 2D (for now)?

i think that i should use
sceGuDrawArray
with as first argument GU_LINES, but i don't know much more...
any help?

thanks
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
Criptych



Joined: 12 Sep 2009
Posts: 79

PostPosted: Sun Jan 17, 2010 2:30 am    Post subject: Reply with quote

You're on the right track. To draw the line in your example, you need something like this:
Code:
typedef struct { float x, y, z; } vType;
vType *vert = (vType *)sceGuGetMemory(2 * sizeof(vType));
vert[0].x =  10; vert[0].y =  20; vert[0].z = 0;
vert[1].x = 400; vert[1].y = 220; vert[1].z = 0;
sceGuDrawArray(GU_LINES, GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vert);

This will allocate the memory for the endpoints and draw the line in the current color (set by sceGuColor).
_________________
PSP-2000 // CFW: 5.50 GEN-D2 ...and not upgrading until OFW supports homebrew!
(But I did downgrade to 1.50 with TimeMachine...)
"I want you to tell me how the machine makes you feel."
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Sun Jan 17, 2010 3:08 am    Post subject: Reply with quote

oh thanks, except for
typedef struct { float x, y, z; } vType;

has this to be called in the main loop?


EDIT: i cannot make it work..

the problem is with

sceGuEnable(GU_BLEND);
sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

that is called in the init gu function.
if i comment these lines out, i can se perfectely the line but strings written by intrafont are messed up. with these lines "active" the texts rendered by intrafont are ok, but the line is not there on the screen!

EDIT2:
another question.
how to use GU_LINE_STRIP to draw a line by specifting first two vertices and than only one? for example how to draw this array?

vert[0].x = 10; vert[0].y = 20; vert[0].z = 0;
vert[1].x = 400; vert[1].y = 220; vert[1].z = 0;
vert[2].x = 100; vert[2].y = 120; vert[2].z = 0;

is the array correct? or should it be written in another way?
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Jan 17, 2010 7:50 am    Post subject: Reply with quote

You need to disable the blending before you draw the line sceGuDisable(GU_BLEND), or make sure you are setting the alpha to 1.

For the second question - yes, provided you sceGuGetMemory enough space.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Sun Jan 17, 2010 7:29 pm    Post subject: Reply with quote

sorrounding the block with
sceGuDisable(GU_BLEND); and
sceGuEnable(GU_BLEND);
is working but i would like to set the alpha to 1 instead of doing this.


to set the alpha to 1 is this ok? sceGuColor(0xFF000000); .. it is not working..

thanks....
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Jan 17, 2010 7:31 pm    Post subject: Reply with quote

That would draw it in solid black, yes.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Sun Jan 17, 2010 7:51 pm    Post subject: Reply with quote

but it doesn't... the line is not visible

can you please tell me what sceGuBlendFunc does? i want to learn... thankyou thankyou
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Mon Jan 18, 2010 5:35 am    Post subject: Reply with quote

it seems that i need to enable something to make the transparency work!
i created a rectangle with alpha to 0x80 but is looks like as if alpha was 0xFF...
should i change the parameters for sceGumDrawArray?
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Wed Jan 20, 2010 4:51 am    Post subject: Reply with quote

any help? how can i make the transparency work?
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
anmabagima



Joined: 01 Oct 2009
Posts: 96

PostPosted: Wed Jan 20, 2010 9:21 pm    Post subject: Reply with quote

Hi maybe you need to set the alpha check function:

Code:

sceGuEnable(GU_ALPHA_TEST);
sceGuAlphaFunc(GU_GREATER, 0, 0xff);


Using intrafont you should set the following after writing your string to restore your current GU behavior (this was my finding):
Code:
sceGuTexFilter(GU_NEAREST, GU_NEAREST);
   sceGuTexMode(GU_PSM_8888, 0, 0, 0);

   sceGuDisable(GU_BLEND);


regards
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Wed Jan 20, 2010 11:15 pm    Post subject: Reply with quote

thankyou but i have some problems with alpha. by adding those two lines in the init function, anything except intrafont strings gets drawed!, i cannot seen anything..

thanks for functions to restore gu settings after intrafont
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
anmabagima



Joined: 01 Oct 2009
Posts: 96

PostPosted: Wed Jan 20, 2010 11:49 pm    Post subject: Reply with quote

Hi,

I've wrapped the intraFont in a texthelper class to use it properbly in my GU developments. The Output-Method looks like following:

Code:
void clTextHelper::writeText(fontType ft, const char *text, short tx, short ty){
   //assuming sceGuSart was already called ...

   sceGuEnable(GU_BLEND);
   sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

   intraFontPrint(font[ft], tx, ty, text);
   //intraFont call does destroy the kind of texture handle
   //restore is needed:
   sceGuTexFilter(GU_NEAREST, GU_NEAREST);
   sceGuTexMode(GU_PSM_8888, 0, 0, 0);

   sceGuDisable(GU_BLEND);
}


Hope this helps
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Thu Jan 21, 2010 12:44 am    Post subject: Reply with quote

thanks for that but i cannot make transparency work...
when i insert

Code:

    sceGuAlphaFunc(GU_GREATER, 0, 0xFF);
    sceGuEnable(GU_ALPHA_TEST);


in the initialization function, the only thing that gets drawed is the intrafont strings, everything else (lines and poligons) are invisible, regardless the alpha value..

EDIT: when an utility dialog is running on the screen (like msg dialog) the alpha works correctely
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
anmabagima



Joined: 01 Oct 2009
Posts: 96

PostPosted: Thu Jan 21, 2010 2:12 am    Post subject: Reply with quote

Hmm...

could you try to add a color component to your vertice like:

Code:
typedef struct { int color;float x, y, z; } vType;


setting up your vertices with color = 0xffffffff; which should make them white.

However, if the string is written to the screen than Alpha blending works for them as this library uses alphablending to have a bit of transparency between the letters ;o)

change the drawing call to :

Code:
sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vert);


Regards
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Sat Jan 23, 2010 11:02 pm    Post subject: Reply with quote

ook thankyou very much!
_________________
Ciao! from Italy
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