simple gu question

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

Moderators: cheriff, TyRaNiD

Post Reply
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

simple gu question

Post by phobox »

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
Criptych
Posts: 64
Joined: Sat Sep 12, 2009 5:18 am

Post by Criptych »

You're on the right track. To draw the line in your example, you need something like this:

Code: Select all

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).
"You hungry? I haven't eaten since later this afternoon."
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

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
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

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
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

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
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

That would draw it in solid black, yes.

Jim
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

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
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

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
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

any help? how can i make the transparency work?
Ciao! from Italy
anmabagima
Posts: 87
Joined: Thu Oct 01, 2009 8:43 pm

Post by anmabagima »

Hi maybe you need to set the alpha check function:

Code: Select all

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: Select all

sceGuTexFilter(GU_NEAREST, GU_NEAREST);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);

	sceGuDisable(GU_BLEND);
regards
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

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
anmabagima
Posts: 87
Joined: Thu Oct 01, 2009 8:43 pm

Post by anmabagima »

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: Select all

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
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

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

Code: Select all

    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
anmabagima
Posts: 87
Joined: Thu Oct 01, 2009 8:43 pm

Post by anmabagima »

Hmm...

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

Code: Select all

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: Select all

sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vert);
Regards
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

ook thankyou very much!
Ciao! from Italy
Post Reply