| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Jun 08, 2007 11:53 pm Post subject: Can't seem to draw lines :S |
|
|
Hi folks,
I have this function of my 2d on 3d engine:
| Code: | 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: | | 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: | | 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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Last edited by Ghoti on Sat Jun 09, 2007 6:37 am; edited 1 time in total |
|
| Back to top |
|
 |
KickinAezz
Joined: 03 Jun 2007 Posts: 328
|
Posted: Sat Jun 09, 2007 6:29 am Post subject: |
|
|
No idea...
Last edited by KickinAezz on Thu Jun 28, 2007 11:37 pm; edited 1 time in total |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sat Jun 09, 2007 6:45 am Post subject: |
|
|
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 ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KickinAezz
Joined: 03 Jun 2007 Posts: 328
|
Posted: Sat Jun 09, 2007 9:50 am Post subject: |
|
|
oh....
Last edited by KickinAezz on Thu Jun 28, 2007 11:38 pm; edited 1 time in total |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Sat Jun 09, 2007 4:53 pm Post subject: |
|
|
since you are mixing 2d and 3d i guess you are making a call to:
| Code: |
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 |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sat Jun 09, 2007 6:54 pm Post subject: |
|
|
@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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Sat Jun 09, 2007 7:23 pm Post subject: |
|
|
its Engine2D::Render2DLineOn3D(***);
not
engine2d->Render2DLineOn3D(**);
as its a class member function and not a STRUCT pointer member function _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Sat Jun 09, 2007 7:47 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sun Jun 10, 2007 6:41 am Post subject: |
|
|
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: | 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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Sun Jun 10, 2007 2:05 pm Post subject: |
|
|
ahh thanx for the clarification :)
as for GU_TRANSFORM_2D
do not use this for 3D plotting _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Sun Jun 10, 2007 4:25 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sun Jun 10, 2007 6:25 pm Post subject: |
|
|
@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 ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Sun Jun 10, 2007 8:35 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sun Jun 10, 2007 9:01 pm Post subject: |
|
|
well i have tried just drawing the line and nothing else:
| Code: | 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: | | sceGuDisable(GU_TEXTURE_2D); | but that also does not seem to work :S _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Mon Jun 11, 2007 12:56 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Mon Jun 11, 2007 1:16 pm Post subject: |
|
|
lol
just a thought... try this?
| Code: |
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 |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Mon Jun 11, 2007 5:42 pm Post subject: |
|
|
| Is lighting on or off? It might be ignoring your colors or something...What about blending? |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Mon Jun 11, 2007 6:33 pm Post subject: |
|
|
@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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Tue Jun 12, 2007 4:41 am Post subject: |
|
|
hmm... very weird
could u post how u setup the gu? _________________ - be2003
blog |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Jun 12, 2007 5:19 am Post subject: |
|
|
here it is:
| Code: | 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. _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Tue Jun 12, 2007 5:35 am Post subject: |
|
|
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: |
//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:
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: |
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 |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Tue Jun 12, 2007 5:45 am Post subject: |
|
|
a nice square drawn with GU_SPRITES:
 _________________ - be2003
blog |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Jun 12, 2007 6:12 am Post subject: |
|
|
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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Tue Jun 12, 2007 6:17 am Post subject: |
|
|
no problem
just make sure you enable GU_DEPTH_TEST when you arent drawing anything 2D _________________ - be2003
blog |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Jun 12, 2007 6:26 am Post subject: |
|
|
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 :) _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
|