BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to make a texture tile across a GL_TRIANGLE_STRIP (quad)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Paul Nicholls
Guest





PostPosted: Wed Aug 17, 2005 4:23 am    Post subject: How to make a texture tile across a GL_TRIANGLE_STRIP (quad) Reply with quote



Hi all,
I can get a texture to tile across a triangle strip (quad) ok if the
texture tiles from the lower left edge (0,0,0) like so:

// quad vertices positions
// 4 - 3
// | |
// 1 - 2
//
glBegin(GL_TRIANGLE_STRIP);
x := cArenaScale * Vertex2.x;
y := FArenaBoundary.FArenaHeight;
z := cArenaScale * Vertex2.z;

glTexCoord2d(Edge.EdgeLength/cWallTextureWidth,FArenaBoundary.FArenaHeight/cWallTextureHeight);
glVertex3f(x,y,z); //3

x := cArenaScale * Vertex1.x;
y := FArenaBoundary.FArenaHeight;
z := cArenaScale * Vertex1.z;

glTexCoord2d(0,FArenaBoundary.FArenaHeight/cWallTextureHeight);
glVertex3f(x,y,z); //4

x := cArenaScale * Vertex2.x;
y := 0;
z := cArenaScale * Vertex2.z;

glTexCoord2d(Edge.EdgeLength/cWallTextureWidth,0);
glVertex3f(x,y,z); //2

x := cArenaScale * Vertex1.x;
y := 0;
z := cArenaScale * Vertex1.z;

glTexCoord2d(0,0); glVertex3f(x,y,z); //1
glEnd;

But I am having a dickens of a time trying to make a texture tile across a
triangle strip (quad) if the centre of the strip is at (0,0,0) and I want
the texturing to start from the center of the quad.

Here is some ASCII art to hopefull help :)

(MinX,0,MinZ)

o--------------
Quote:
| |
T | T |
| |
------z-------
| |
T | T |
| |
--------------o(MaxX,0,MaxZ)


z = (0,0,0)
T = texture (not stretched) tiled across the quad as much as it can fit

I hope I'm making sense :)

Thanks in advance,
Cheers,
Paul.

"The plastic veneer of civilization is easily melted in the heat of the
moment" - Paul Nicholls.
[email]paul_nicholls (AT) hotmail (DOT) NOSPAM.com[/email]

Remove ".NOSPAM" to reply.



Back to top
Paul Nicholls
Guest





PostPosted: Wed Aug 17, 2005 4:54 am    Post subject: Re: How to make a texture tile across a GL_TRIANGLE_STRIP (q Reply with quote



<SNIP>

Thanks guys, but I have figured it out :)

// Min/Max X and Z are the extents of the tri strip/quad that I want to
draw tiled

MinX := FArenaBoundary.BoundingBox.MinX;
MaxX := FArenaBoundary.BoundingBox.MaxX;
MinZ := FArenaBoundary.BoundingBox.MinZ;
MaxZ := FArenaBoundary.BoundingBox.MaxZ;

// workout the texture scaling factor for the x and z direction
FloorScaleX := (MaxX - MinX) / cFloorTextureWidth;
FloorScaleZ := (MaxZ - MinZ) / cFloorTextureHeight;

// Draw Floor
glBindTexture(GL_TEXTURE_2D,FTextures[1]);

// 4 - 3
// | |
// 1 - 2
//
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(+0.5*FloorScaleX,+0.5*FloorScaleZ);
glVertex3f(MaxX,0,MinZ); //3

glTexCoord2d(-0.5*FloorScaleX,+0.5*FloorScaleZ);
glVertex3f(MinX,0,MinZ); //4

glTexCoord2d(+0.5*FloorScaleX,-0.5*FloorScaleZ);
glVertex3f(MaxX,0,MaxZ); //2

glTexCoord2d(-0.5*FloorScaleX,-0.5*FloorScaleZ);
glVertex3f(MinX,0,MaxZ); //1
glEnd;

Hope this helps someone else :-)

cheers,
Paul.


Back to top
Jeremy Darling
Guest





PostPosted: Fri Aug 19, 2005 12:17 pm    Post subject: Re: How to make a texture tile across a GL_TRIANGLE_STRIP (q Reply with quote



Paul,
I'm curious why your not using GLScene for something like this. It
definately makes your life easier when it comes to OpenGL in Delphi and
speeds the development time.

Jeremy

"Paul Nicholls" <paul_nicholls (AT) hotmail (DOT) NOSPAM.com> wrote

Quote:
Hi all,
I can get a texture to tile across a triangle strip (quad) ok if the
texture tiles from the lower left edge (0,0,0) like so:

// quad vertices positions
// 4 - 3
// | |
// 1 - 2
//
glBegin(GL_TRIANGLE_STRIP);
x := cArenaScale * Vertex2.x;
y := FArenaBoundary.FArenaHeight;
z := cArenaScale * Vertex2.z;


glTexCoord2d(Edge.EdgeLength/cWallTextureWidth,FArenaBoundary.FArenaHeight/cWallTextureHeight);
glVertex3f(x,y,z); //3

x := cArenaScale * Vertex1.x;
y := FArenaBoundary.FArenaHeight;
z := cArenaScale * Vertex1.z;

glTexCoord2d(0,FArenaBoundary.FArenaHeight/cWallTextureHeight);
glVertex3f(x,y,z); //4

x := cArenaScale * Vertex2.x;
y := 0;
z := cArenaScale * Vertex2.z;

glTexCoord2d(Edge.EdgeLength/cWallTextureWidth,0);
glVertex3f(x,y,z); //2

x := cArenaScale * Vertex1.x;
y := 0;
z := cArenaScale * Vertex1.z;

glTexCoord2d(0,0); glVertex3f(x,y,z); //1
glEnd;

But I am having a dickens of a time trying to make a texture tile across a
triangle strip (quad) if the centre of the strip is at (0,0,0) and I want
the texturing to start from the center of the quad.

Here is some ASCII art to hopefull help :)

(MinX,0,MinZ)

o--------------
| | |
| T | T |
| | |
|------z-------
| | |
| T | T |
| | |
--------------o(MaxX,0,MaxZ)

z = (0,0,0)
T = texture (not stretched) tiled across the quad as much as it can fit

I hope I'm making sense :)

Thanks in advance,
Cheers,
Paul.

"The plastic veneer of civilization is easily melted in the heat of the
moment" - Paul Nicholls.
[email]paul_nicholls (AT) hotmail (DOT) NOSPAM.com[/email]

Remove ".NOSPAM" to reply.




Back to top
Paul Nicholls
Guest





PostPosted: Sun Aug 21, 2005 10:54 pm    Post subject: Re: How to make a texture tile across a GL_TRIANGLE_STRIP (q Reply with quote

"Jeremy Darling" <jdarling (AT) eonclash (DOT) com> wrote

Quote:
Paul,
I'm curious why your not using GLScene for something like this. It
definately makes your life easier when it comes to OpenGL in Delphi and
speeds the development time.

Jeremy

SNIP


I'm not using GLScene partially because I want to learn some of this stuff
myself Smile
Also can one use GLScene in a commercial app?

Cheers,
Paul.



Back to top
Jeremy Darling
Guest





PostPosted: Mon Aug 22, 2005 12:28 pm    Post subject: Re: How to make a texture tile across a GL_TRIANGLE_STRIP (q Reply with quote

Yes you can use GLScene in a commercial application. It falls under the MPL
(Mozilla Public License, http://www.mozilla.org)

Jeremy

"Paul Nicholls" <paul_nicholls (AT) hotmail (DOT) NOSPAM.com> wrote

Quote:
"Jeremy Darling" <jdarling (AT) eonclash (DOT) com> wrote in message
news:4305cdda$1 (AT) newsgroups (DOT) borland.com...
Paul,
I'm curious why your not using GLScene for something like this. It
definately makes your life easier when it comes to OpenGL in Delphi and
speeds the development time.

Jeremy

SNIP

I'm not using GLScene partially because I want to learn some of this stuff
myself Smile
Also can one use GLScene in a commercial app?

Cheers,
Paul.




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
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, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.