Archived

This topic is now archived and is closed to further replies.

cant map textures to my terrain!

This topic is 5669 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how can i map my texture over all of the triangles instead of each triangle hacing been mapped with the texture? int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(tX,tY,tZ); // Move Left 1.5 Units And Into The Screen 6.0 glPushMatrix(); glTranslatef(0.0,0.0,0.0); //glRotatef(Degree,0.0,0.0,0.0); glBindTexture(GL_TEXTURE_2D, Texture[0].texID); for(int y=1;y<149;y++) { for(int x=1;x<149;x++) { glBegin(GL_TRIANGLE_STRIP); glColor3f(MapCoord[x][y].y/40,MapCoord[x][y].y/40,MapCoord[x][y].y/40); glTexCoord2d(1,1); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right glTexCoord2d(0,1); glVertex3f(MapCoord[x][y+1].x,MapCoord[x][y+1].y,MapCoord[x][y+1].z); // Top Left glTexCoord2d(1,0); glVertex3f(MapCoord[x+1][y].x,MapCoord[x+1][y].y,MapCoord[x+1][y].z); // Bottom Right glTexCoord2d(0,0); glVertex3f(MapCoord[x+1][y+1].x,MapCoord[x+1][y+1].y,MapCoord[x+1][y+1].z); // Bottom Left glEnd(); } } glPopMatrix(); return TRUE; // Keep Going } [edited by - _Titan_ on June 5, 2002 4:24:42 PM]

Share this post


Link to post
Share on other sites
Right now you''re specifying a texture coordinate of 0 or 1 for every vertex, and doing this every iteration in your for loops. Instead, calculate the texture coordinates, so that 0 is first vertex of the initial triangle, and 1 is the final vertex of the last triangle. And then intermediary vertices will have a texture coordinate that is some appropriate value between 0 and 1.

Hope that makes sense.

Share this post


Link to post
Share on other sites
You''ll still specify texcoords for each vertex, but instead of each texcoord being 0 or 1, you''ll have something like this:

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right

So each texcoord is between 0 and 1 for the entire range of vertices...

Does that help?

Share this post


Link to post
Share on other sites
Hmm...did not work, it just mapped as a big green one color map...not what i intended...maybe i did it wrong? I''m sur ei did

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x][y+1].x,MapCoord[x][y+1].y,MapCoord[x][y+1].z); // Top Left

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x+1][y].x,MapCoord[x+1][y].y,MapCoord[x+1][y].z); // Bottom Right

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x+1][y+1].x,MapCoord[x+1][y+1].y,MapCoord[x+1][y+1].z); // Bottom Left

Share this post


Link to post
Share on other sites
That's going to make all 4 texcoords have the same value for each of the 4 vertices per trianglestrip. What I gave you was just to explain the idea, not exactly make it work.

Basically, divide the range of 0 to 1 over each vertex, so that there is an increment over the entire range of your terrain.

With 4 quads,texcoords would look like this:

  
// Quad1

glTexCoord2f(0,0); glVertex3f(0,0,0);
glTexCoord2f(0.5,0); glVertex3f(1,0,0);
glTexCoord2f(0,0.5); glVertex3f(0,1,0);
glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);
//Quad 2

glTexCoord2f(0.5,0); glVertex3f(1,0,0);
glTexCoord2f(1.0,0); glVertex3f(2,0,0);
glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);
glTexCoord2f(1.0,0.5); glVertex3f(2,1,0);
//Quad 3

glTexCoord2f(0,0.5); glVertex3f(0,1,0);
glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);
glTexCoord2f(0.0,1.0); glVertex3f(0,2,0);
glTexCoord2f(0.5,1.0); glVertex3f(1,2,0);
//Quad 4

glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);
glTexCoord2f(1.0,0.5); glVertex3f(2,1,0);
glTexCoord2f(0.5,1.0); glVertex3f(1,2,0);
glTexCoord2f(1.0,1.0); glVertex3f(2,2,0);


See, I have the texcoords stretched over four quads. It's up to you how you implement this.


Edit: Damn source tags aren't holding my formatting...grrrr.

[edited by - yakuza on June 5, 2002 6:10:51 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you''ll need to use glTexCoord2f instead of glTexCoord2d

just my 2 eurocents ...

Share this post


Link to post
Share on other sites
nah, i figured it out, i used a function i found in one of the tutorials. I dont see how it differs from what i had, but it works so who cares.

Share this post


Link to post
Share on other sites
quote:
Original post by _Titan_
nah, i figured it out, i used a function i found in one of the tutorials. I dont see how it differs from what i had, but it works so who cares.


But do you understand why it works? If I were you, I''d be spending a little time analyzing the difference between my code and the "function I found", so that I''d know why it works correctly.

AP: I''m also curious why glTexCoord2f would make a difference from glTexCoord2d?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yakuza :

glTexCoord2d takes as input only integers, whereas glTexCoord2f takes floats ...

SO :
if you do glTexCoord2d(x/150, y/150) it is equivalent to glTexCoord2d(0, 0) if x and y are inferior to 150 and glTexCoord2d(something>=1, something>=1) if x and y are superior to 150

if you do glTexCoord2f(x/150, y/150) x/150 is a number between 0 and 1 if x<=150

that''s all

now re-read previous posts and all will become clear (if you''re smart enough)

Share this post


Link to post
Share on other sites
I did take the time to understand it, and i do understand now. I understood before what i needed to do, but was confused on exact code on doing it...

Anyways, Thanks for the help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
yakuza :

glTexCoord2d takes as input only integers, whereas glTexCoord2f takes floats ...

SO :
if you do glTexCoord2d(x/150, y/150) it is equivalent to glTexCoord2d(0, 0) if x and y are inferior to 150 and glTexCoord2d(something>=1, something>=1) if x and y are superior to 150

if you do glTexCoord2f(x/150, y/150) x/150 is a number between 0 and 1 if x<=150

that''s all

now re-read previous posts and all will become clear (if you''re smart enough)



hmmm... since when is an double an integer?
glTexCoord2d Accepts GLdouble
glTexCoord2f Accepts GLfloat

glTexCoord2i Accepts GLint <-- this would be the one you are babling about....

the difference between double and float is that a double uses double precision (find a programmers guide, or a math guru :D if you want to know what that means)


Oh and I just love the
quote:
(if you''re smart enough)
bit

Share this post


Link to post
Share on other sites
Why blatantly try to confuse people?

Haha, you tricked me into showing I''m a novice programmer. I was confused, because in my mind there shouldn''t be a difference in behavior when using doubles or floats for the texture coords. Then you start "babling" about doubles being integers, and I didn''t take a second thought to it ''cause I''ve seen you post much more advanced topics, so I figured you knew what the hell you were talking about.

In my opinion, misleading newbies isn''t cool, but whatever makes you happy...

---------------------------

I hate have to split some cost of something between three people when you are out to buy something and not being able to do the split correctly due to our inferior base-10 system. -- felonius

Share this post


Link to post
Share on other sites
Thougth Id better register to clear a few things up...

quote:
Original post by yakuza
Why blatantly try to confuse people?



Ehrm... you couldn''t know it but :

Im not the same "anonymous poster" that did the original posts - I just thougt I''d bitch slap him for playing smart and not knowing what he was talking about

quote:

In my opinion, misleading newbies isn''t cool, but whatever makes you happy...


Wich was why thought i''d better corret his misinformation...


/Please excuse my bad spelling - My native language is binary not english

/Take my advice - I don''''t use it...

Share this post


Link to post
Share on other sites