Issues texturing a 2d polygon
Blitz3D Forums/Blitz3D Beginners Area/Issues texturing a 2d polygon
| ||
I've got a shape like a line graph that I want to apply a texture (bmp with vertical lines) to. I apply the texture and the lines are horizontal. I rotate the bmp 90 degrees and still the lines are horizontal. I know it's to do with the "u" and "v" values, but it's got me going nuts. Can someone have a look at this code and see if you can help me figure out how to fix the texturing problem. For each point on the x axis of the graph where I have a y value, I put a vertex at 0, and a vertex at y-value. I then move to the next x value. ------------- code section -------------- For GraphLoop = 1 To NumXValues v=AddVertex(Surf,4,0,GraphLoop,0,1,0) ; create vertex on horiz plane v=AddVertex(Surf,4,GraphLoop(GraphValues),tempy,0,0,0) ; create vertex at y-value Next For GraphPolyLoop = 0 To 5 v0 = GraphPolyLoop * 2 v1 = v0 + 1 v2 = v1 + 1 v3 = v2 + 1 AddTriangle (surf,v0,v1,v2) AddTriangle (surf,v2,v1,v3) next -------------------------------- I load a brush and paint it with PaintMesh (GraphMesh,GraphTextureBrush) Any thoughts would be appreciated!!! Cheers! Shane |
| ||
There seems to be something wrong, here you say For GraphLoop = 1 To NumXValues but a few lines later GraphLoop is used as an array: ...GraphLoop(GraphValues)... (where you didn't say what GraphValues is). Not sure if this is the cause (I'm surprised this is running at all), but it surely complicates things in a confusing way. |
| ||
Oops, sorry, I changed my variable names before posting to try to make it more readable. The code should be For GraphLoop = 1 To NumXValues v=AddVertex(Surf,4,0,GraphLoop,0,1,0) ; create vertex on horiz plane v=AddVertex(Surf,4,GraphValues(GraphLoop),tempy,0,0,0) ; create vertex at y-value Next For GraphPolyLoop = 0 To 5 v0 = GraphPolyLoop * 2 v1 = v0 + 1 v2 = v1 + 1 v3 = v2 + 1 AddTriangle (surf,v0,v1,v2) AddTriangle (surf,v2,v1,v3) next Where GraphValues is an array of several integers. --------------- In short, I'm looping across the x values creating 2 verticies for each. I need help with how to set the u and v values with the AddVertex commands above so that I can properly map a texture to it. |
| ||
I have no idea what GraphLoop is for. UV Coordinates work like this: (0,1) ... (1,1) . . . . . . (0,0) ... (1,0) If you set the UV coords for a single quad to those, the texture will be painted unrotated and uncropped to the quad. |
| ||
(0,0) is the top-left corner, Octo. :) Like this:(0,0) ... (1,0) . . . . . . (0,1) ... (1,1) |
| ||
Sorry, been spending too much time with DirectX in C++. |
| ||
hockings - maybe simply try to swap U and V. |
| ||
bram32 on codersworkshop was able to shed some light on the problem. To set the u# and v# of each vertex, you should use VertexTexCoords. v1=AddVertex(Surf,4,0,GraphLoop,0,1,0) ; create vertex on horiz plane v2=AddVertex(Surf,4,GraphValues(GraphLoop),tempy,0,0,0) ; create vertex at y-value vertextexcoords Surf, v1, 0, float(graphloop) / float(numxvalues) vertextexcoords Surf, v2, 1, float(graphloop) / float(numxvalues) A little bit of tweaking and it was working a treat! |
| ||
You don't need to specify the UV coords separately by using the VertexTexCoords command. You can specify the UVs in the AddVertex commands you're using beforehand. |