| View previous topic :: View next topic |
| Author |
Message |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Sat Jan 16, 2010 8:51 pm Post subject: simple gu question |
|
|
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 |
|
 |
Criptych
Joined: 12 Sep 2009 Posts: 79
|
Posted: Sun Jan 17, 2010 2:30 am Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Sun Jan 17, 2010 3:08 am Post subject: |
|
|
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 |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sun Jan 17, 2010 7:50 am Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Sun Jan 17, 2010 7:29 pm Post subject: |
|
|
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 |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
|
| Back to top |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Sun Jan 17, 2010 7:51 pm Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Mon Jan 18, 2010 5:35 am Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Wed Jan 20, 2010 4:51 am Post subject: |
|
|
any help? how can i make the transparency work? _________________ Ciao! from Italy |
|
| Back to top |
|
 |
anmabagima
Joined: 01 Oct 2009 Posts: 96
|
Posted: Wed Jan 20, 2010 9:21 pm Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Wed Jan 20, 2010 11:15 pm Post subject: |
|
|
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 |
|
 |
anmabagima
Joined: 01 Oct 2009 Posts: 96
|
Posted: Wed Jan 20, 2010 11:49 pm Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Thu Jan 21, 2010 12:44 am Post subject: |
|
|
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 |
|
 |
anmabagima
Joined: 01 Oct 2009 Posts: 96
|
Posted: Thu Jan 21, 2010 2:12 am Post subject: |
|
|
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 |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Sat Jan 23, 2010 11:02 pm Post subject: |
|
|
ook thankyou very much! _________________ Ciao! from Italy |
|
| Back to top |
|
 |
|