Can't seem to draw lines :S

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

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Can't seem to draw lines :S

Post by Ghoti »

Hi folks,

I have this function of my 2d on 3d engine:

Code: Select all

int Engine2D::Render2DLineOn3D(float x1, float y1, float x2, float y2, int color) {

	lineVertex* DisplayVertices = (lineVertex*) sceGuGetMemory(2 * sizeof(lineVertex));

	sceGuColor(1);

	DisplayVertices[0].x = x1;
	DisplayVertices[0].y = y1;
	DisplayVertices[0].z = 0;

	DisplayVertices[1].x = x2;
	DisplayVertices[1].y = y2;
	DisplayVertices[1].z = 0;

	sceGuDrawArray(GU_LINES, GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, DisplayVertices);
   return 0;
}
and i use it through this call:

Code: Select all

engine2d->Render2DLineOn3D(1.0f, 1.0f, 480.0f, 272.0f, 1);
however the line is not rendered :S

what am i doing wrong ?

ohw wait here is the struct i use:

Code: Select all

typedef struct {	float				x, y, z;		} lineVertex;
hope someone can help me!

ps. I have searched the forum and found some similar problem however the solutions do not work with me :S
Last edited by Ghoti on Sat Jun 09, 2007 6:37 am, edited 1 time in total.
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

No idea...
Last edited by KickinAezz on Thu Jun 28, 2007 11:37 pm, edited 1 time in total.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

I'm sorry I do not understand exactly what you mean.
All 4 points should have x, y, z? a line has only 2 points and they have x, y and z as far as I can see.

whats the small thing I have forgotten ? (the return 0 was not present because it was a void function before, have in my code anyway but that did not matter.)

De function renders a line on screen in 2D space but in a scene where also 3D objects are rendered. so my 2D engine renders besides the line (or it should) also images on top of a 3D world. That is the function of that engine. I just want to render a line from pixel (1,1) to pixel (100,100) for example. I thought this should do the trick.

How can i change mine so that it will work ?
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

oh....
Last edited by KickinAezz on Thu Jun 28, 2007 11:38 pm, edited 1 time in total.
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

since you are mixing 2d and 3d i guess you are making a call to:

Code: Select all

void gumPerspective(ScePspFMatrix4* m, float fovy, float aspect, float near, float far);
now keep in mind your near is probably 1.0f or 0.5f or whatever, so anything with a z less than your near will be gone, and also keep in mind that you are using a viewport so your screen (according to the gu calls) is not (0, 0) to (480, 272), its more like (-2048, -2048) to (2048, 2048) or something like that, hopefully u get what im trying to say...

i recommend for simple lines you write directly to the vram :]
- be2003
blog
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

@be2003: my near is 2.1f at the moment, however trianglestrips with a z value of 0.0f are rendered also correct. This is due to the GU_TRANSFORM_2D if I understand it correctly. My line also uses this flag so the Z value should not matter since it will be rendered on the 2D surface.

Also the coordinates of my trianglestrip also uses just screencoordinates and that works also.

I'd like to solve this drawing of the line but if I cannot than I will look into the writing directly to vram.

anyway I hope you see something else that is wrong with my code or please correct me if I said something incorrect :)

hope you guys can help me :D
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

its Engine2D::Render2DLineOn3D(***);
not
engine2d->Render2DLineOn3D(**);

as its a class member function and not a STRUCT pointer member function
10011011 00101010 11010111 10001001 10111010
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

dot_blank wrote:its Engine2D::Render2DLineOn3D(***);
not
engine2d->Render2DLineOn3D(**);

as its a class member function and not a STRUCT pointer member function
um, no. if that were the case, the code wouldn't even compile. presumably, engine2d points to an Engine2D instance so using -> is fine.

edit: this time limit thing on editing is pretty annoying.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

ohw :) i see that i was not clear enough, sorry about that.
ufoz is right. It is an instance of the 2D engine so the arrow is just correct. The code compiles also and I have a lot more functions in the engine that i call precise the same way as it should :D
calling the function does not seem to be the problem. The code in it however does. :(

I have played around a bit and have changed it a little bit, still not working but it should work a bit better for my needs.

Code: Select all

int Engine2D::Render2DLineOn3D(float x1, float y1, float x2, float y2, int color) {

	sceGuDisable(GU_DEPTH_TEST);

	lineVertex* DisplayVertices = (lineVertex*)sceGuGetMemory(2 * sizeof(lineVertex));

	sceGuColor(GU_RGBA(255, 0, 255, 255));

	DisplayVertices[0].x = x1;
	DisplayVertices[0].y = y1;
	DisplayVertices[0].z = 0.0f;

	DisplayVertices[1].x = x2;
	DisplayVertices[1].y = y2;
	DisplayVertices[1].z = 0.0f;

	sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, DisplayVertices);

	sceGuEnable(GU_DEPTH_TEST);

	return 0;

}
I have disabled the depth test so it should render it over everything when it is called. In my render sub I call it as the last function.
Ihave changed the GU_LINES to GU_LINE_STRIP but that also does not seem to help :S
and the last I give it a color that is noticable on a white background.

hope someone can find the error :S

Ghoti

PS thanks for the replies so far !! Hope we'll figure it out :D
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

ahh thanx for the clarification :)
as for GU_TRANSFORM_2D
do not use this for 3D plotting
10011011 00101010 11010111 10001001 10111010
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

hmm
about the GU_TRANSFORM_2D, i wasnt really sure how that flag affected the rendering so i wasnt sure if it was getting clipped because of the near

maybe there is some firmware glitch in it, like single lines dont show when they arent rasterized

try to draw a triangle instead and make the third point just 0.001 float away from the second one and try it. you never know
- be2003
blog
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

@be2005: Do not hope it is a firmware glitch :S I have tried rendering a trianglestrip without a texture on it and that does not work either :S so the code i use to normally render a triangle with texture change the texture coordinates into a color attribute and assigned white to it does not render a thing :S (have changed the drawarray flags also) so maybe I'm forgetting a different renderflag or something?

@dot_blank: I have tried the transform_3d also just to be sure but it does not work also.

maybe I should be using the rendering to vram then :S I have not done this yet so any pointers on this ?
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Your function is fine.

The error is elsewhere in your code.

If you've not already, I'd recommend 'just' drawing a line on screen and nothing else, as a way of testing.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

well i have tried just drawing the line and nothing else:

Code: Select all

int MainMenu::Render() {

	sceGuStart(GU_DIRECT,list);

	// clear screen
	sceGuClearColor(0xffff0000);
	sceGuClearDepth(0);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

	// render projection and view settings
	matrix_identity((float*)&projection);
	matrix_projection((float*)&projection,70.0f,16.0f/9.0f,2.1f,400.0f);
	sceGuSetMatrix(GU_PROJECTION,&projection);
	matrix_identity((float*)&view);
	sceGuSetMatrix(GU_VIEW,&view);

	// render the line below the title
	engine2d->Render2DLineOn3D(0.0f, 42.0f, 480.0f, 42.0f, 1);
	engine2d->Render2DLineOn3D(1.0f, 42.0f, 470.0f, 143.0f);
                sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuSwapBuffers();
	return 0;
the first function is the function I posted here, the second renderline function tries to render a trianglestrip.

well the problem seems that for some reason everything that has no textures is not rendered. The line is not rendered. The trianglestrip is not rendered and a fadeout and in system i wanted to make also is not rendered.(using a quad with screensize that has variable alpha value)

it seems that just rendering something without texture is not rendered... :(

i have tried using

Code: Select all

sceGuDisable(GU_TEXTURE_2D);
but that also does not seem to work :S
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

drawing a line directly to vram is fairly simple if that is the case...

this is very weird though, have you tried disabling GU_CULL_FACE? im not quite sure if the rasterizer takes care of that aspect either....
- be2003
blog
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

lol
just a thought... try this?

Code: Select all

typedef struct
{
   unsigned int color;
   float x, y, z;
} colorVertex;

int Engine2D::Render2DLineOn3D(float x1, float y1, float x2, float y2, unsigned int color)
{ 
   colorVertex* DisplayVertices = (colorVertex*) sceGuGetMemory(2 * sizeof(colorVertex)); 

   DisplayVertices[0].color = color;
   DisplayVertices[0].x = x1; 
   DisplayVertices[0].y = y1; 
   DisplayVertices[0].z = 0;

   DisplayVertices[1].color = color;
   DisplayVertices[1].x = x2; 
   DisplayVertices[1].y = y2; 
   DisplayVertices[1].z = 0; 

   sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, DisplayVertices);

   return 0; 
} 
use this to draw a red line
engine2d->Render2DLineOn3D(1.0f, 1.0f, 480.0f, 272.0f, 0xff0000ff));

i hope i didnt make any newb mistakes, but i think u can see what i was going for... away from the primitive colors and onto the vertex colors
- be2003
blog
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

Is lighting on or off? It might be ignoring your colors or something...What about blending?
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

@ufoz: Well i have set the ambient to full white, all my other things on screen are displayed. I have 3 pictures I draw to screen using a similar function as for the lines only then for an image with texture. Those are displayed. Everything without a texture does not seem to be displayed. :S
anyway i have tried disabling light on a global level as on a local level in the function but that did not show the line. I did the same for the blending :( still no luck. :(

@be2003: GU_CULL_FACE also did do anything good :( as for the other thing I had allready tried that but to be sure i tried it again and still no change. There is still no line or a triangle without a texture on it :(

I'm going to try and render the line with instead of a color just adding a texture to the line maybe then it will appear :S
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

hmm... very weird

could u post how u setup the gu?
- be2003
blog
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

here it is:

Code: Select all

int GameApp::Init3DGraphics() {

	// Initialize the Graphical Unit System
	sceGuInit();
	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,512);
	sceGuDispBuffer(480,272,(void*)0x88000,512);
	sceGuDepthBuffer((void*)0x110000,512);
	sceGuOffset(2048 - (480/2),2048 - (272/2));

	// create a viewport centered at 2048,2048 width 480 and height 272
	sceGuViewport(2048,2048,480,272);
	sceGuDepthRange(0xc350,0x2710);

	// enable custom scissor
	sceGuScissor(0,0,480,272);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_LIGHTING);
	sceGuEnable(GU_BLEND);

	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuFinish();

	// wait untill the list has finished.
	sceGuSync(0,0);

	// turn on the display
	sceGuDisplay(GU_TRUE);


	return 0;
};
hope it helps.
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

LOL! so i stopped being lazy and made a nice example...
the example is the cube demo from the pspsdk with the following added after the cube is drawn...

Code: Select all

//draw line
sceGuDisable(GU_TEXTURE_2D);

unsigned int color = 0xff000000;
colorVertex* DisplayVertices = (colorVertex*) sceGuGetMemory(2 * sizeof(colorVertex)); 

DisplayVertices[0].color = color; 
DisplayVertices[0].x = 1.0f; 
DisplayVertices[0].y = 1.0f; 
DisplayVertices[0].z = 0; 

DisplayVertices[1].color = color; 
DisplayVertices[1].x = 480.0f; 
DisplayVertices[1].y = 272.0f; 
DisplayVertices[1].z = 0; 

sceGuDrawArray(GU_LINES, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, DisplayVertices);

sceGuEnable(GU_TEXTURE_2D);
but ofcourse you will need the colorVertex structure from above...

that code produces the following results:

Image

as you can see, the line is drawn but the 3D cube is drawn over the 2D line. so 3d is drawn over 2d...

but if you do a quick:

Code: Select all

sceGuDisable(GU_DEPTH_TEST);
sceGuEnable(GU_BLEND);
sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
and make sure you draw the line after all the 3d then the line will be drawn over the 3d scene!

good luck
- be2003
blog
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

a nice square drawn with GU_SPRITES:

Image
- be2003
blog
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi !!!!!

THANKS !!!! it now works :D:D:D:D: both the line and the sprites and trianglestrips :D

really really alot of thanks!!! now i can finish my menu for my game :D:D:D:D really thanks again
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

no problem
just make sure you enable GU_DEPTH_TEST when you arent drawing anything 2D
- be2003
blog
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Yeah i know the 3D game is ready only my menu was not working yet but my game uses 2d and 3d combined :) I only could not get the lines to work :S
but once again thank you :)
Post Reply