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 

Projecting whole texture ontop of 100s of triangles? how?

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



Joined: 14 Oct 2005
Posts: 154

PostPosted: Sun Jul 30, 2006 12:16 pm    Post subject: Projecting whole texture ontop of 100s of triangles? how? Reply with quote

To prevent clippinmg, im assuming you can project a texture ontop of alot of triangles, thus stopping it completey... (PSPGL)

Im looking for something like, for each 1 pixel on the PSP screen, i want to have 2 triangles on them... That will stop even 1 pixel from clipping (?)...

So say i have, i dunno, uhh.. 64x64 dimensions for a texture... Id need 64*2 by 64*2 triangles, 2 per pixel, and project that texture ontop of them...

If you know any better way to prevent clipping in PSPGL besides tiling textured quads, instead of texturing a huge quad (my current and best clipping solution), then please tell me as this is bothering me so... OH and i have a camera all set up, gluLookAt is implemented, so if i can change the 'view' values to something else to prevent the clipping from a distance very well, then please tell me..
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Jul 30, 2006 2:31 pm    Post subject: Reply with quote

Even subdividing your geometry isn't really going to fix your problem.

When you say 'clipping' you mean 'culling'. The PSP is not rendering your triangles because for some reason it doesn't like them. Either the perspective calculation has gone out of the guard-band, or the z is behind the viewplane (for any individual point).

What can you do?

1) Someone suggested moving your near plane a bit further forwards. Good idea, that will help prevent overflows in the perspective calculation.

2) Enable 2D clipping (scissoring). That means the geometry is clipped to the 480x272 window after the perspective calculation has been done. You will probably still need to near z clip.

3) Enable full 3D clipping. That means a near clip plane and 4 planes defining the view cone.

When you've been turning off clipping and scissoring in PSPGL you're actually turning off the things that can help you.

Either let PSPGL do the clipping, or do it yourself. The clipping is dynamic depending on the camera and you can't pre-compute it.

If you still need to tesselate your geometry, then to get the texture coordinates is simple.
If your original quad has 0->1 for u and 0->1 for v, then if you split each edge 64 times then the u and v are just 0,1/64,2/64,3/64,...

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



Joined: 14 Oct 2005
Posts: 154

PostPosted: Sun Jul 30, 2006 4:01 pm    Post subject: Reply with quote

Hmmm... I understand that last part totally... Kind of like setting offsets, and only mapping those offsets as textures... Thats a tad too much work ;) Time to whip out the Red Book ;)

Ill be doing the scissoring technique, but in your opinion, what would you use for a 3d world?

EDIT

Ok, ive found this... Now scissor testing should, as stated in this, only draw whats in the range of the parameters given, so setting ti to the PSPS resolution will prevent culling?

NEHE Tutorial somethin... wrote:

A wonderful GL command called glScissor(x,y,w,h). What this command does is creates almost what you would call a window. When GL_SCISSOR_TEST is enabled, the only portion of the screen that you can alter is the portion inside the scissor window. The first line below creates a scissor window starting at 1 on the x axis, and 13.5% (0.135...f) of the way from the bottom of the screen on the y axis. The scissor window will be 638 pixels wide (swidth-2), and 59.7% (0.597...f) of the screen tall.

In the next line we enable scissor testing. Anything we draw OUTSIDE the scissor window will not show up. You could draw a HUGE quad on the screen from 0,0 to 639,480, and you would only see the quad inside the scissor window, the rest of the screen would be unaffected. Very nice command!


Please correct me if im wrong... (Also, what are your thoughts towards me converting my PSPGL 3d world to the main GU? Since culling isnt a problem there for some reason... Is it worth converting it?)
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Jul 30, 2006 5:35 pm    Post subject: Reply with quote

Quote:
Hmmm... I understand that last part totally... Kind of like setting offsets, and only mapping those offsets as textures... Thats a tad too much work ;) Time to whip out the Red Book ;)

You're not making much sense. If you have the Red Book then read it!

You set the UVs along with the vertices. You can use a for loop to do it simply.
eg.
Code:

#define STEP (1.0f/64.0f)
float x,y;
for (y = 0; y < 1.0f; y += STEP)
for (x = 0; x < 1.0f; x += STEP)
{
glBegin(GL_QUADS);
  glTexCoord2(x,y);
  glVertex3f(x,y,0);

  glTexCoord2(x+STEP,y);
  glVertex3f(x+STEP,y,0);

  glTexCoord2(x+STEP,y+STEP);
  glVertex3f(x+STEP,y+STEP,0);

  glTexCoord2(x,y+STEP);
  glVertex3f(x,y+STEP,0);
glEnd();
}
}

That will draw you a 1x1 plane (use the modelview to scale it) with the whole of the currently bound texture spread across it.

If you pick 2D scissoring, you still have the problem of what to do when any of your z coordinates lie behind the near z clip plane (or even when z goes -ve). What are you planning to do then?

3D engines always end up with proper 3D clipping.

No point moving to gu if you can't get GL working. The problems might be better or worse there, but there's nothing fundamentally wrong with GL. You should be able to get it going.

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



Joined: 26 Jun 2006
Posts: 275

PostPosted: Mon Jul 31, 2006 12:54 am    Post subject: Reply with quote

It's easy to project, you just need to scale your coords into tex space.


Here's a function to change a value from one scale to another.

Code:



float Scale( float val,float from,float to)
{
   float sf = val / from;
   return to * sf;
}


I.e

float TexU = Scale( VertexX,MapWidth,1 );
float TexV = Scale( VertexY,MapHeight,1 );

you might want to first convert your vertex coord into positive space.
i.e it's from -50,to 50, change it to 0 to 100 first.
Back to top
View user's profile Send private message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Mon Jul 31, 2006 5:31 pm    Post subject: Reply with quote

Well, ive written a tiling system that has enabled me to draw huge rooms made out of texured quads, sized as 1x1x0 dimensions... So i may as well replace my current simple... 4 vertex points with the code Jim supplied, and it should map my texture correctly, when correctly means no culling...
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