Texture coordinates on trianglestrips - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: Texture coordinates on trianglestrips (/thread-7072.html) Texture coordinates on trianglestrips - designdb - May 21, 2003 08:57 PM Okay, one more, and then I'm down for the night. I implemented trianglestrips on my terrain generator, and the textures look like junk, and it comes down to the texture coordinates. I don't know how I'm supposed to fix the corners of the texture when I'm not defining all three vertices. I suppose I could fall back to texture teselation, but I'm concerned about the appearance of seams at the edge of each strip. Ideas? Thanks. Dave Ramsey Texture coordinates on trianglestrips - OneSadCookie - May 21, 2003 09:18 PM I'm confused. Are the texture coordinates not solely dependent on the x and z coordinates of the vertex? Texture coordinates on trianglestrips - designdb - May 21, 2003 09:32 PM You can do that? All the examples I could find in the red book used something like [SOURCECODE]glTexCoord2(0.0 , 1.0); glVertex3f(Whatever); glTexCoord2(1.0 , 1.0); glVertex3f(WhateverElse);[/SOURCECODE] If I specify the texture coordinates using the coordinates of the object, I'm still not sure how that gets around the trianglestrip problem. In the strip, I don't explicitly define all of the coordinates (as such). Boy, that was a waffling sentence. I hope you know what I mean by that. Yes, I am defining all of the coordinates, but no longer as discrete triangles, but as triangle, then point, then point (basically). My all triangle version used each pair of triangles which formed a square as one surface for the texture to be mapped upon (in two pieces). If I try to do that in the TriangleStrip, the coordinate which closes one Triangle also opens another. I apologize, for it appears that I lack some of the necessary terminology to describe my problem. Did that help, or do I need to roll out the screenshots? Texture coordinates on trianglestrips - OneSadCookie - May 21, 2003 09:57 PM I still don't understand. You are mapping one texture over the whole terrain, aren't you? You can't use the vertex coordinates as texture coordinates directly without a vertex program. What I meant is that if a your terrain runs from (0, 0, 0) to (128, 0, 128) (diagonally) then the texture coordinates for a vertex (x, y, z) will be (x/128, z/128)... or won't they? Texture coordinates on trianglestrips - designdb - May 21, 2003 11:28 PM Ahh. I see the problem. No, I am not doing one texture over the whole terrain( a la Myth), but rather trying to reproduce a cool system I saw a screenshot of on flipcode one day. The guy had a terrain engine that randomly generated a heightmap and then applied textures and coloration based upon a series of values/characteristics. Right now, since it is still in progress, I am using only one texture, but it needs to repeat across the terrain. Originally, when it was all triangles, I used the texture once per triangle pair: [SOURCECODE] glBegin(GL_TRIANGLES); //POINT 1 glNormal3f((float)[normal getX], (float)[normal getY], (float)[normal getZ]); glTexCoord2f(0.0f, 0.0f); [vertexA draw]; //POINT 2 if(topBottom == TOP_TRIANGLE_OF_SQUARE) {glTexCoord2f(1.0f, 0.0f);} else {glTexCoord2f(1.0f, 1.0f);} [vertexB draw]; //POINT 3 if(topBottom == TOP_TRIANGLE_OF_SQUARE) {glTexCoord2f(1.0f, 1.0f);} else {glTexCoord2f(0.0f, 1.0f);} [vertexC draw]; glEnd(); [/SOURCECODE] Yes, I know I should send the conditional outside the Begin/End, but my intention was to abandon this soon anyway. Unfortunately, a similar approach does not work with TriangleStrips. I think I'm going to have to bind the left and bottom of the texture in the first triangle and then allow it to teselate accross the triangle strip all by itself. The terrain looks nice in all tris, but it's a bit slow (though not noticibly slower than the STRUCT based version I had before). If I can get it all working, I'll have access to an infinite number of readily created playing fields that should be transmittable over a network with a greyscale bitmap, the terrain cuts (at what height grass becomes scrub, scrub becomes rock, where the water table is, etc), and the locations of trees and rocks and such. Should be pretty bandwidth friendly. What I'm working on now is a testbed with a bunch of sliders for testing presets for the random heightmap generators, horizontal scaling, altitude scaling, Terrain cuts, etc. Actually, his changed textures/colors based upon the slope of the ground (i.e. flat ground was grassy, sharply pitched ground was scrub, nearly verticle polys became rock, etc.). I'm not there yet. Does that help? Texture coordinates on trianglestrips - OneSadCookie - May 22, 2003 12:17 AM If you need a texture to tile across the terrain, Code: ```glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);``` Then simply let your texture coordinates range as high as you want. 2.0 = 1.0 = 0.0, 2.5 = 1.5 = 0.5, &c. To turn a texture on or off for particular parts of the terrain, make a grayscale/alpha texture white where you want the texture on, black where you want it off, and multiply the two together using GL_ARB_texture_env_combine. Add multiple different textures with additive blending, just make sure that the sum of the masks is 1 at each point. Or is that over your head Texture coordinates on trianglestrips - designdb - May 22, 2003 08:02 AM Nope, I think I got it. Of course, I won't really have it until I actually do it, but right this second is not the time... The part about additive blending and masks gave me some really cool ideas, though. I'll give it a try later today and let you know how it goes. Texture coordinates on trianglestrips - designdb - May 22, 2003 09:34 AM Perfect, just perfect. It has a significant advantage over what I was trying to do in that when you scale the terrain now, the textures are not scaled. I didn't mind it before, but now that I've seen these, just perfect. Now I just have to figure out the vertex normals. I've got a good vector averaging method that accepts up to 6 vectors, and all of the Tri's have normals. The tough part is figuring out which normals to average. I wish I was back in high school again. I had all this geometry and trig stuff down pat. Don't bother answering the "which normals" question. It's going to be a pain in the butt because of the way I have my Triangle arrays set up, and besides, I want to figure it out for myself (or, at least, give it a shot) OSC, as always, thank you very much for your assistance.