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

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

Moderators: cheriff, TyRaNiD

Post Reply
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

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

Post by sg57 »

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

Post by Jim »

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
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

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

Post by Jim »

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

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

  glTexCoord2&#40;x+STEP,y&#41;;
  glVertex3f&#40;x+STEP,y,0&#41;;

  glTexCoord2&#40;x+STEP,y+STEP&#41;;
  glVertex3f&#40;x+STEP,y+STEP,0&#41;;

  glTexCoord2&#40;x,y+STEP&#41;;
  glVertex3f&#40;x,y+STEP,0&#41;;
glEnd&#40;&#41;;
&#125;
&#125;
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
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

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



float Scale&#40; float val,float from,float to&#41;
&#123;
   float sf = val / from;
   return to * sf;
&#125;
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.
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

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...
Post Reply